diff --git a/Makefile b/Makefile index 0daf699f..e6abbecf 100644 --- a/Makefile +++ b/Makefile @@ -68,6 +68,10 @@ check: ## Compile everything, checking syntax (does not output binaries) lexgen: ## Run codegen tool for lexicons (lexicon JSON to Go packages) go run ./cmd/lexgen/ --build-file cmd/lexgen/bsky.json $(LEXDIR) +.PHONY: lexgen-ext +lexgen-ext: ## Run codegen tool for lexicons (lexicon JSON to Go packages) + go run ./cmd/lexgen/ --build-file cmd/lexgen/ext.json $(LEXDIR) + .PHONY: cborgen cborgen: ## Run codegen tool for CBOR serialization go run ./gen diff --git a/api-ext/standardsite/graphrecommend.go b/api-ext/standardsite/graphrecommend.go new file mode 100644 index 00000000..5da4ba77 --- /dev/null +++ b/api-ext/standardsite/graphrecommend.go @@ -0,0 +1,20 @@ +// Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT. + +// Lexicon schema: site.standard.graph.recommend + +package standardsite + +import ( + lexutil "github.com/bluesky-social/indigo/lex/util" +) + +func init() { + lexutil.RegisterType("site.standard.graph.recommend", &GraphRecommend{}) +} + +type GraphRecommend struct { + LexiconTypeID string `json:"$type" cborgen:"$type,const=site.standard.graph.recommend"` + CreatedAt string `json:"createdAt" cborgen:"createdAt"` + // document: AT-URI reference to the document record being recommended (ex: at://did:plc:abc123/site.standard.document/xyz789). + Document string `json:"document" cborgen:"document"` +} diff --git a/api-ext/standardsite/graphsubscription.go b/api-ext/standardsite/graphsubscription.go new file mode 100644 index 00000000..2859adeb --- /dev/null +++ b/api-ext/standardsite/graphsubscription.go @@ -0,0 +1,20 @@ +// Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT. + +// Lexicon schema: site.standard.graph.subscription + +package standardsite + +import ( + lexutil "github.com/bluesky-social/indigo/lex/util" +) + +func init() { + lexutil.RegisterType("site.standard.graph.subscription", &GraphSubscription{}) +} + +type GraphSubscription struct { + LexiconTypeID string `json:"$type" cborgen:"$type,const=site.standard.graph.subscription"` + CreatedAt *string `json:"createdAt,omitempty" cborgen:"createdAt,omitempty"` + // publication: AT-URI reference to the publication record being subscribed to (ex: at://did:plc:abc123/site.standard.publication/xyz789). + Publication string `json:"publication" cborgen:"publication"` +} diff --git a/api-ext/standardsite/standarddocument.go b/api-ext/standardsite/standarddocument.go new file mode 100644 index 00000000..d79f0392 --- /dev/null +++ b/api-ext/standardsite/standarddocument.go @@ -0,0 +1,113 @@ +// Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT. + +// Lexicon schema: site.standard.document + +package standardsite + +import ( + "bytes" + "encoding/json" + "fmt" + "io" + + comatproto "github.com/bluesky-social/indigo/api/atproto" + lexutil "github.com/bluesky-social/indigo/lex/util" + cbg "github.com/whyrusleeping/cbor-gen" +) + +func init() { + lexutil.RegisterType("site.standard.document", &Document{}) +} + +type Document struct { + LexiconTypeID string `json:"$type" cborgen:"$type,const=site.standard.document"` + // bskyPostRef: Strong reference to a Bluesky post. Useful to keep track of comments off-platform. + BskyPostRef *comatproto.RepoStrongRef `json:"bskyPostRef,omitempty" cborgen:"bskyPostRef,omitempty"` + // content: Open union used to define the record's content. Each entry must specify a $type and may be extended with other lexicons to support additional content formats. + Content *lexutil.LexiconTypeDecoder `json:"content,omitempty" cborgen:"content,omitempty"` + Contributors []*Document_Contributor `json:"contributors,omitempty" cborgen:"contributors,omitempty"` + // coverImage: Image to used for thumbnail or cover image. Less than 1MB is size. + CoverImage *lexutil.LexBlob `json:"coverImage,omitempty" cborgen:"coverImage,omitempty"` + // description: A brief description or excerpt from the document. + Description *string `json:"description,omitempty" cborgen:"description,omitempty"` + // labels: Self-label values for this post. Effectively content warnings. + Labels *Document_Labels `json:"labels,omitempty" cborgen:"labels,omitempty"` + // links: Array of values describing relationships between this document and external resources + Links *lexutil.LexiconTypeDecoder `json:"links,omitempty" cborgen:"links,omitempty"` + // path: Combine with site or publication url to construct a canonical URL to the document. Prepend with a leading slash. + Path *string `json:"path,omitempty" cborgen:"path,omitempty"` + // publishedAt: Timestamp of the documents publish time. + PublishedAt string `json:"publishedAt" cborgen:"publishedAt"` + // site: Points to a publication record (at://) or a publication url (https://) for loose documents. Avoid trailing slashes. + Site string `json:"site" cborgen:"site"` + // tags: Array of strings used to tag or categorize the document. Avoid prepending tags with hashtags. + Tags []string `json:"tags,omitempty" cborgen:"tags,omitempty"` + // textContent: Plaintext representation of the documents contents. Should not contain markdown or other formatting. + TextContent *string `json:"textContent,omitempty" cborgen:"textContent,omitempty"` + // title: Title of the document. + Title string `json:"title" cborgen:"title"` + // updatedAt: Timestamp of the documents last edit. + UpdatedAt *string `json:"updatedAt,omitempty" cborgen:"updatedAt,omitempty"` +} + +// Document_Contributor is a "contributor" in the site.standard.document schema. +type Document_Contributor struct { + Did string `json:"did" cborgen:"did"` + DisplayName *string `json:"displayName,omitempty" cborgen:"displayName,omitempty"` + Role *string `json:"role,omitempty" cborgen:"role,omitempty"` +} + +// Self-label values for this post. Effectively content warnings. +type Document_Labels struct { + LabelDefs_SelfLabels *comatproto.LabelDefs_SelfLabels +} + +func (t *Document_Labels) MarshalJSON() ([]byte, error) { + if t.LabelDefs_SelfLabels != nil { + t.LabelDefs_SelfLabels.LexiconTypeID = "com.atproto.label.defs#selfLabels" + return json.Marshal(t.LabelDefs_SelfLabels) + } + return nil, fmt.Errorf("can not marshal empty union as JSON") +} + +func (t *Document_Labels) UnmarshalJSON(b []byte) error { + typ, err := lexutil.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "com.atproto.label.defs#selfLabels": + t.LabelDefs_SelfLabels = new(comatproto.LabelDefs_SelfLabels) + return json.Unmarshal(b, t.LabelDefs_SelfLabels) + default: + return nil + } +} + +func (t *Document_Labels) MarshalCBOR(w io.Writer) error { + + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + if t.LabelDefs_SelfLabels != nil { + return t.LabelDefs_SelfLabels.MarshalCBOR(w) + } + return fmt.Errorf("can not marshal empty union as CBOR") +} + +func (t *Document_Labels) UnmarshalCBOR(r io.Reader) error { + typ, b, err := lexutil.CborTypeExtractReader(r) + if err != nil { + return err + } + + switch typ { + case "com.atproto.label.defs#selfLabels": + t.LabelDefs_SelfLabels = new(comatproto.LabelDefs_SelfLabels) + return t.LabelDefs_SelfLabels.UnmarshalCBOR(bytes.NewReader(b)) + default: + return nil + } +} diff --git a/api-ext/standardsite/standardpublication.go b/api-ext/standardsite/standardpublication.go new file mode 100644 index 00000000..7fedbd03 --- /dev/null +++ b/api-ext/standardsite/standardpublication.go @@ -0,0 +1,99 @@ +// Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT. + +// Lexicon schema: site.standard.publication + +package standardsite + +import ( + "bytes" + "encoding/json" + "fmt" + "io" + + comatproto "github.com/bluesky-social/indigo/api/atproto" + lexutil "github.com/bluesky-social/indigo/lex/util" + cbg "github.com/whyrusleeping/cbor-gen" +) + +func init() { + lexutil.RegisterType("site.standard.publication", &Publication{}) +} + +type Publication struct { + LexiconTypeID string `json:"$type" cborgen:"$type,const=site.standard.publication"` + // basicTheme: Simplified publication theme for tools and apps to utilize when displaying content. + BasicTheme *ThemeBasic `json:"basicTheme,omitempty" cborgen:"basicTheme,omitempty"` + // description: Brief description of the publication. + Description *string `json:"description,omitempty" cborgen:"description,omitempty"` + // icon: Square image to identify the publication. Should be at least 256x256. + Icon *lexutil.LexBlob `json:"icon,omitempty" cborgen:"icon,omitempty"` + // labels: Self-label values for this publication. Effectively content warnings. + Labels *Publication_Labels `json:"labels,omitempty" cborgen:"labels,omitempty"` + // name: Name of the publication. + Name string `json:"name" cborgen:"name"` + // preferences: Object containing platform specific preferences (with a few shared properties). + Preferences *Publication_Preferences `json:"preferences,omitempty" cborgen:"preferences,omitempty"` + // url: Base publication url (ex: https://standard.site). The canonical document URL is formed by combining this value with the document path. + Url string `json:"url" cborgen:"url"` +} + +// Self-label values for this publication. Effectively content warnings. +type Publication_Labels struct { + LabelDefs_SelfLabels *comatproto.LabelDefs_SelfLabels +} + +func (t *Publication_Labels) MarshalJSON() ([]byte, error) { + if t.LabelDefs_SelfLabels != nil { + t.LabelDefs_SelfLabels.LexiconTypeID = "com.atproto.label.defs#selfLabels" + return json.Marshal(t.LabelDefs_SelfLabels) + } + return nil, fmt.Errorf("can not marshal empty union as JSON") +} + +func (t *Publication_Labels) UnmarshalJSON(b []byte) error { + typ, err := lexutil.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "com.atproto.label.defs#selfLabels": + t.LabelDefs_SelfLabels = new(comatproto.LabelDefs_SelfLabels) + return json.Unmarshal(b, t.LabelDefs_SelfLabels) + default: + return nil + } +} + +func (t *Publication_Labels) MarshalCBOR(w io.Writer) error { + + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + if t.LabelDefs_SelfLabels != nil { + return t.LabelDefs_SelfLabels.MarshalCBOR(w) + } + return fmt.Errorf("can not marshal empty union as CBOR") +} + +func (t *Publication_Labels) UnmarshalCBOR(r io.Reader) error { + typ, b, err := lexutil.CborTypeExtractReader(r) + if err != nil { + return err + } + + switch typ { + case "com.atproto.label.defs#selfLabels": + t.LabelDefs_SelfLabels = new(comatproto.LabelDefs_SelfLabels) + return t.LabelDefs_SelfLabels.UnmarshalCBOR(bytes.NewReader(b)) + default: + return nil + } +} + +// Publication_Preferences is a "preferences" in the site.standard.publication schema. +type Publication_Preferences struct { + // showInDiscover: Boolean which decides whether the publication should appear in discovery feeds. + ShowInDiscover *bool `json:"showInDiscover,omitempty" cborgen:"showInDiscover,omitempty"` +} diff --git a/api-ext/standardsite/themebasic.go b/api-ext/standardsite/themebasic.go new file mode 100644 index 00000000..33911ddb --- /dev/null +++ b/api-ext/standardsite/themebasic.go @@ -0,0 +1,251 @@ +// Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT. + +// Lexicon schema: site.standard.theme.basic + +package standardsite + +import ( + "bytes" + "encoding/json" + "fmt" + "io" + + lexutil "github.com/bluesky-social/indigo/lex/util" + cbg "github.com/whyrusleeping/cbor-gen" +) + +func init() { + lexutil.RegisterType("site.standard.theme.basic", &ThemeBasic{}) +} + +type ThemeBasic struct { + LexiconTypeID string `json:"$type" cborgen:"$type,const=site.standard.theme.basic"` + // accent: Color used for links and button backgrounds. + Accent *ThemeBasic_Accent `json:"accent" cborgen:"accent"` + // accentForeground: Color used for button text. + AccentForeground *ThemeBasic_AccentForeground `json:"accentForeground" cborgen:"accentForeground"` + // background: Color used for content background. + Background *ThemeBasic_Background `json:"background" cborgen:"background"` + // foreground: Color used for content text. + Foreground *ThemeBasic_Foreground `json:"foreground" cborgen:"foreground"` +} + +// Color used for links and button backgrounds. +type ThemeBasic_Accent struct { + ThemeColor_Rgb *ThemeColor_Rgb +} + +func (t *ThemeBasic_Accent) MarshalJSON() ([]byte, error) { + if t.ThemeColor_Rgb != nil { + t.ThemeColor_Rgb.LexiconTypeID = "site.standard.theme.color#rgb" + return json.Marshal(t.ThemeColor_Rgb) + } + return nil, fmt.Errorf("can not marshal empty union as JSON") +} + +func (t *ThemeBasic_Accent) UnmarshalJSON(b []byte) error { + typ, err := lexutil.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "site.standard.theme.color#rgb": + t.ThemeColor_Rgb = new(ThemeColor_Rgb) + return json.Unmarshal(b, t.ThemeColor_Rgb) + default: + return nil + } +} + +func (t *ThemeBasic_Accent) MarshalCBOR(w io.Writer) error { + + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + if t.ThemeColor_Rgb != nil { + return t.ThemeColor_Rgb.MarshalCBOR(w) + } + return fmt.Errorf("can not marshal empty union as CBOR") +} + +func (t *ThemeBasic_Accent) UnmarshalCBOR(r io.Reader) error { + typ, b, err := lexutil.CborTypeExtractReader(r) + if err != nil { + return err + } + + switch typ { + case "site.standard.theme.color#rgb": + t.ThemeColor_Rgb = new(ThemeColor_Rgb) + return t.ThemeColor_Rgb.UnmarshalCBOR(bytes.NewReader(b)) + default: + return nil + } +} + +// Color used for button text. +type ThemeBasic_AccentForeground struct { + ThemeColor_Rgb *ThemeColor_Rgb +} + +func (t *ThemeBasic_AccentForeground) MarshalJSON() ([]byte, error) { + if t.ThemeColor_Rgb != nil { + t.ThemeColor_Rgb.LexiconTypeID = "site.standard.theme.color#rgb" + return json.Marshal(t.ThemeColor_Rgb) + } + return nil, fmt.Errorf("can not marshal empty union as JSON") +} + +func (t *ThemeBasic_AccentForeground) UnmarshalJSON(b []byte) error { + typ, err := lexutil.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "site.standard.theme.color#rgb": + t.ThemeColor_Rgb = new(ThemeColor_Rgb) + return json.Unmarshal(b, t.ThemeColor_Rgb) + default: + return nil + } +} + +func (t *ThemeBasic_AccentForeground) MarshalCBOR(w io.Writer) error { + + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + if t.ThemeColor_Rgb != nil { + return t.ThemeColor_Rgb.MarshalCBOR(w) + } + return fmt.Errorf("can not marshal empty union as CBOR") +} + +func (t *ThemeBasic_AccentForeground) UnmarshalCBOR(r io.Reader) error { + typ, b, err := lexutil.CborTypeExtractReader(r) + if err != nil { + return err + } + + switch typ { + case "site.standard.theme.color#rgb": + t.ThemeColor_Rgb = new(ThemeColor_Rgb) + return t.ThemeColor_Rgb.UnmarshalCBOR(bytes.NewReader(b)) + default: + return nil + } +} + +// Color used for content background. +type ThemeBasic_Background struct { + ThemeColor_Rgb *ThemeColor_Rgb +} + +func (t *ThemeBasic_Background) MarshalJSON() ([]byte, error) { + if t.ThemeColor_Rgb != nil { + t.ThemeColor_Rgb.LexiconTypeID = "site.standard.theme.color#rgb" + return json.Marshal(t.ThemeColor_Rgb) + } + return nil, fmt.Errorf("can not marshal empty union as JSON") +} + +func (t *ThemeBasic_Background) UnmarshalJSON(b []byte) error { + typ, err := lexutil.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "site.standard.theme.color#rgb": + t.ThemeColor_Rgb = new(ThemeColor_Rgb) + return json.Unmarshal(b, t.ThemeColor_Rgb) + default: + return nil + } +} + +func (t *ThemeBasic_Background) MarshalCBOR(w io.Writer) error { + + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + if t.ThemeColor_Rgb != nil { + return t.ThemeColor_Rgb.MarshalCBOR(w) + } + return fmt.Errorf("can not marshal empty union as CBOR") +} + +func (t *ThemeBasic_Background) UnmarshalCBOR(r io.Reader) error { + typ, b, err := lexutil.CborTypeExtractReader(r) + if err != nil { + return err + } + + switch typ { + case "site.standard.theme.color#rgb": + t.ThemeColor_Rgb = new(ThemeColor_Rgb) + return t.ThemeColor_Rgb.UnmarshalCBOR(bytes.NewReader(b)) + default: + return nil + } +} + +// Color used for content text. +type ThemeBasic_Foreground struct { + ThemeColor_Rgb *ThemeColor_Rgb +} + +func (t *ThemeBasic_Foreground) MarshalJSON() ([]byte, error) { + if t.ThemeColor_Rgb != nil { + t.ThemeColor_Rgb.LexiconTypeID = "site.standard.theme.color#rgb" + return json.Marshal(t.ThemeColor_Rgb) + } + return nil, fmt.Errorf("can not marshal empty union as JSON") +} + +func (t *ThemeBasic_Foreground) UnmarshalJSON(b []byte) error { + typ, err := lexutil.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "site.standard.theme.color#rgb": + t.ThemeColor_Rgb = new(ThemeColor_Rgb) + return json.Unmarshal(b, t.ThemeColor_Rgb) + default: + return nil + } +} + +func (t *ThemeBasic_Foreground) MarshalCBOR(w io.Writer) error { + + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + if t.ThemeColor_Rgb != nil { + return t.ThemeColor_Rgb.MarshalCBOR(w) + } + return fmt.Errorf("can not marshal empty union as CBOR") +} + +func (t *ThemeBasic_Foreground) UnmarshalCBOR(r io.Reader) error { + typ, b, err := lexutil.CborTypeExtractReader(r) + if err != nil { + return err + } + + switch typ { + case "site.standard.theme.color#rgb": + t.ThemeColor_Rgb = new(ThemeColor_Rgb) + return t.ThemeColor_Rgb.UnmarshalCBOR(bytes.NewReader(b)) + default: + return nil + } +} diff --git a/api-ext/standardsite/themecolor.go b/api-ext/standardsite/themecolor.go new file mode 100644 index 00000000..207b9ca2 --- /dev/null +++ b/api-ext/standardsite/themecolor.go @@ -0,0 +1,21 @@ +// Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT. + +// Lexicon schema: site.standard.theme.color + +package standardsite + +// ThemeColor_Rgb is a "rgb" in the site.standard.theme.color schema. +type ThemeColor_Rgb struct { + LexiconTypeID string `json:"$type" cborgen:"$type,const=site.standard.theme.color#rgb"` + B int64 `json:"b" cborgen:"b"` + G int64 `json:"g" cborgen:"g"` + R int64 `json:"r" cborgen:"r"` +} + +// ThemeColor_Rgba is a "rgba" in the site.standard.theme.color schema. +type ThemeColor_Rgba struct { + A int64 `json:"a" cborgen:"a"` + B int64 `json:"b" cborgen:"b"` + G int64 `json:"g" cborgen:"g"` + R int64 `json:"r" cborgen:"r"` +} diff --git a/cmd/lexgen/ext.json b/cmd/lexgen/ext.json new file mode 100644 index 00000000..b786b3a1 --- /dev/null +++ b/cmd/lexgen/ext.json @@ -0,0 +1,14 @@ +[ + { + "package": "atproto", + "prefix": "com.atproto", + "outdir": "api/atproto", + "import": "github.com/bluesky-social/indigo/api/atproto" + }, + { + "package": "standardsite", + "prefix": "site.standard", + "outdir": "api-ext/standardsite", + "import": "github.com/bluesky-social/indigo/api-ext/standardsite" + } +] diff --git a/lexicons/site/standard/document.json b/lexicons/site/standard/document.json new file mode 100644 index 00000000..5d7d9d8f --- /dev/null +++ b/lexicons/site/standard/document.json @@ -0,0 +1,125 @@ +{ + "defs": { + "contributor": { + "properties": { + "did": { + "format": "did", + "type": "string" + }, + "displayName": { + "maxGraphemes": 100, + "maxLength": 1000, + "type": "string" + }, + "role": { + "maxGraphemes": 100, + "maxLength": 1000, + "type": "string" + } + }, + "required": [ + "did" + ], + "type": "object" + }, + "main": { + "description": "A document record representing a published article, blog post, or other content. Documents can belong to a publication or exist independently.", + "key": "tid", + "record": { + "properties": { + "bskyPostRef": { + "description": "Strong reference to a Bluesky post. Useful to keep track of comments off-platform.", + "ref": "com.atproto.repo.strongRef", + "type": "ref" + }, + "content": { + "closed": false, + "description": "Open union used to define the record's content. Each entry must specify a $type and may be extended with other lexicons to support additional content formats.", + "refs": [], + "type": "union" + }, + "contributors": { + "items": { + "ref": "#contributor", + "type": "ref" + }, + "type": "array" + }, + "coverImage": { + "accept": [ + "image/*" + ], + "description": "Image to used for thumbnail or cover image. Less than 1MB is size.", + "maxSize": 1000000, + "type": "blob" + }, + "description": { + "description": "A brief description or excerpt from the document.", + "maxGraphemes": 3000, + "maxLength": 30000, + "type": "string" + }, + "labels": { + "description": "Self-label values for this post. Effectively content warnings.", + "refs": [ + "com.atproto.label.defs#selfLabels" + ], + "type": "union" + }, + "links": { + "description": "Array of values describing relationships between this document and external resources", + "refs": [], + "type": "union" + }, + "path": { + "description": "Combine with site or publication url to construct a canonical URL to the document. Prepend with a leading slash.", + "type": "string" + }, + "publishedAt": { + "description": "Timestamp of the documents publish time.", + "format": "datetime", + "type": "string" + }, + "site": { + "description": "Points to a publication record (at://) or a publication url (https://) for loose documents. Avoid trailing slashes.", + "format": "uri", + "type": "string" + }, + "tags": { + "description": "Array of strings used to tag or categorize the document. Avoid prepending tags with hashtags.", + "items": { + "maxGraphemes": 128, + "maxLength": 1280, + "type": "string" + }, + "type": "array" + }, + "textContent": { + "description": "Plaintext representation of the documents contents. Should not contain markdown or other formatting.", + "type": "string" + }, + "title": { + "description": "Title of the document.", + "maxGraphemes": 500, + "maxLength": 5000, + "type": "string" + }, + "updatedAt": { + "description": "Timestamp of the documents last edit.", + "format": "datetime", + "type": "string" + } + }, + "required": [ + "site", + "title", + "publishedAt" + ], + "type": "object" + }, + "type": "record" + } + }, + "id": "site.standard.document", + "lexicon": 1 +} diff --git a/lexicons/site/standard/graph/recommend.json b/lexicons/site/standard/graph/recommend.json new file mode 100644 index 00000000..27625ddf --- /dev/null +++ b/lexicons/site/standard/graph/recommend.json @@ -0,0 +1,29 @@ +{ + "defs": { + "main": { + "description": "Record declaring a recommendation of a document.", + "key": "tid", + "record": { + "properties": { + "createdAt": { + "format": "datetime", + "type": "string" + }, + "document": { + "description": "AT-URI reference to the document record being recommended (ex: at://did:plc:abc123/site.standard.document/xyz789).", + "format": "at-uri", + "type": "string" + } + }, + "required": [ + "document", + "createdAt" + ], + "type": "object" + }, + "type": "record" + } + }, + "id": "site.standard.graph.recommend", + "lexicon": 1 +} diff --git a/lexicons/site/standard/graph/subscription.json b/lexicons/site/standard/graph/subscription.json new file mode 100644 index 00000000..f0da5f7a --- /dev/null +++ b/lexicons/site/standard/graph/subscription.json @@ -0,0 +1,28 @@ +{ + "defs": { + "main": { + "description": "Record declaring a subscription to a publication.", + "key": "tid", + "record": { + "properties": { + "createdAt": { + "format": "datetime", + "type": "string" + }, + "publication": { + "description": "AT-URI reference to the publication record being subscribed to (ex: at://did:plc:abc123/site.standard.publication/xyz789).", + "format": "at-uri", + "type": "string" + } + }, + "required": [ + "publication" + ], + "type": "object" + }, + "type": "record" + } + }, + "id": "site.standard.graph.subscription", + "lexicon": 1 +} diff --git a/lexicons/site/standard/publication.json b/lexicons/site/standard/publication.json new file mode 100644 index 00000000..a93f818d --- /dev/null +++ b/lexicons/site/standard/publication.json @@ -0,0 +1,72 @@ +{ + "defs": { + "main": { + "description": "A publication record representing a blog, website, or content platform. Publications serve as containers for documents and define the overall branding and settings.", + "key": "tid", + "record": { + "properties": { + "basicTheme": { + "description": "Simplified publication theme for tools and apps to utilize when displaying content.", + "ref": "site.standard.theme.basic", + "type": "ref" + }, + "description": { + "description": "Brief description of the publication.", + "maxGraphemes": 3000, + "maxLength": 30000, + "type": "string" + }, + "icon": { + "accept": [ + "image/*" + ], + "description": "Square image to identify the publication. Should be at least 256x256.", + "maxSize": 1000000, + "type": "blob" + }, + "labels": { + "description": "Self-label values for this publication. Effectively content warnings.", + "refs": [ + "com.atproto.label.defs#selfLabels" + ], + "type": "union" + }, + "name": { + "description": "Name of the publication.", + "maxGraphemes": 500, + "maxLength": 5000, + "type": "string" + }, + "preferences": { + "description": "Object containing platform specific preferences (with a few shared properties).", + "ref": "#preferences", + "type": "ref" + }, + "url": { + "description": "Base publication url (ex: https://standard.site). The canonical document URL is formed by combining this value with the document path.", + "format": "uri", + "type": "string" + } + }, + "required": [ + "url", + "name" + ], + "type": "object" + }, + "type": "record" + }, + "preferences": { + "properties": { + "showInDiscover": { + "default": true, + "description": "Boolean which decides whether the publication should appear in discovery feeds.", + "type": "boolean" + } + }, + "type": "object" + } + }, + "id": "site.standard.publication", + "lexicon": 1 +} diff --git a/lexicons/site/standard/theme/basic.json b/lexicons/site/standard/theme/basic.json new file mode 100644 index 00000000..86969ff6 --- /dev/null +++ b/lexicons/site/standard/theme/basic.json @@ -0,0 +1,50 @@ +{ + "defs": { + "main": { + "description": "A simplified theme definition for publications, providing basic color customization for content display across different platforms and applications.", + "key": "tid", + "record": { + "properties": { + "accent": { + "description": "Color used for links and button backgrounds.", + "refs": [ + "site.standard.theme.color#rgb" + ], + "type": "union" + }, + "accentForeground": { + "description": "Color used for button text.", + "refs": [ + "site.standard.theme.color#rgb" + ], + "type": "union" + }, + "background": { + "description": "Color used for content background.", + "refs": [ + "site.standard.theme.color#rgb" + ], + "type": "union" + }, + "foreground": { + "description": "Color used for content text.", + "refs": [ + "site.standard.theme.color#rgb" + ], + "type": "union" + } + }, + "required": [ + "background", + "foreground", + "accent", + "accentForeground" + ], + "type": "object" + }, + "type": "record" + } + }, + "id": "site.standard.theme.basic", + "lexicon": 1 +} diff --git a/lexicons/site/standard/theme/color.json b/lexicons/site/standard/theme/color.json new file mode 100644 index 00000000..5b6282da --- /dev/null +++ b/lexicons/site/standard/theme/color.json @@ -0,0 +1,62 @@ +{ + "defs": { + "rgb": { + "properties": { + "b": { + "maximum": 255, + "minimum": 0, + "type": "integer" + }, + "g": { + "maximum": 255, + "minimum": 0, + "type": "integer" + }, + "r": { + "maximum": 255, + "minimum": 0, + "type": "integer" + } + }, + "required": [ + "r", + "g", + "b" + ], + "type": "object" + }, + "rgba": { + "properties": { + "a": { + "maximum": 100, + "minimum": 0, + "type": "integer" + }, + "b": { + "maximum": 255, + "minimum": 0, + "type": "integer" + }, + "g": { + "maximum": 255, + "minimum": 0, + "type": "integer" + }, + "r": { + "maximum": 255, + "minimum": 0, + "type": "integer" + } + }, + "required": [ + "r", + "g", + "b", + "a" + ], + "type": "object" + } + }, + "id": "site.standard.theme.color", + "lexicon": 1 +} -- 2.51.2 From 354dc7a7a2e8984b7a31a9a4bc5c012663d3b438 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Sun, 17 May 2026 12:26:29 -0500 Subject: [PATCH 2/2] Add placeholder def to work around lexgen bug, cbor-gen --- api-ext/standardsite/cbor_gen.go | 2751 ++++++++++++++++++++++ api-ext/standardsite/standarddocument.go | 123 +- gen/main.go | 16 + lexicons/site/standard/document.json | 13 +- 4 files changed, 2898 insertions(+), 5 deletions(-) create mode 100644 api-ext/standardsite/cbor_gen.go diff --git a/api-ext/standardsite/cbor_gen.go b/api-ext/standardsite/cbor_gen.go new file mode 100644 index 00000000..9fa895e4 --- /dev/null +++ b/api-ext/standardsite/cbor_gen.go @@ -0,0 +1,2751 @@ +// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT. + +package standardsite + +import ( + "fmt" + "io" + "math" + "sort" + + atproto "github.com/bluesky-social/indigo/api/atproto" + util "github.com/bluesky-social/indigo/lex/util" + cid "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" + xerrors "golang.org/x/xerrors" +) + +var _ = xerrors.Errorf +var _ = cid.Undef +var _ = math.E +var _ = sort.Sort + +func (t *Document) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + fieldCount := 15 + + if t.BskyPostRef == nil { + fieldCount-- + } + + if t.Content == nil { + fieldCount-- + } + + if t.Contributors == nil { + fieldCount-- + } + + if t.CoverImage == nil { + fieldCount-- + } + + if t.Description == nil { + fieldCount-- + } + + if t.Labels == nil { + fieldCount-- + } + + if t.Links == nil { + fieldCount-- + } + + if t.Path == nil { + fieldCount-- + } + + if t.Tags == nil { + fieldCount-- + } + + if t.TextContent == nil { + fieldCount-- + } + + if t.UpdatedAt == nil { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { + return err + } + + // t.Path (string) (string) + if t.Path != nil { + + if len("path") > 1000000 { + return xerrors.Errorf("Value in field \"path\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("path"))); err != nil { + return err + } + if _, err := cw.WriteString(string("path")); err != nil { + return err + } + + if t.Path == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.Path) > 1000000 { + return xerrors.Errorf("Value in field t.Path was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Path))); err != nil { + return err + } + if _, err := cw.WriteString(string(*t.Path)); err != nil { + return err + } + } + } + + // t.Site (string) (string) + if len("site") > 1000000 { + return xerrors.Errorf("Value in field \"site\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("site"))); err != nil { + return err + } + if _, err := cw.WriteString(string("site")); err != nil { + return err + } + + if len(t.Site) > 1000000 { + return xerrors.Errorf("Value in field t.Site was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Site))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.Site)); err != nil { + return err + } + + // t.Tags ([]string) (slice) + if t.Tags != nil { + + if len("tags") > 1000000 { + return xerrors.Errorf("Value in field \"tags\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("tags"))); err != nil { + return err + } + if _, err := cw.WriteString(string("tags")); err != nil { + return err + } + + if len(t.Tags) > 8192 { + return xerrors.Errorf("Slice value in field t.Tags was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Tags))); err != nil { + return err + } + for _, v := range t.Tags { + if len(v) > 1000000 { + return xerrors.Errorf("Value in field v was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(v))); err != nil { + return err + } + if _, err := cw.WriteString(string(v)); err != nil { + return err + } + + } + } + + // t.LexiconTypeID (string) (string) + if len("$type") > 1000000 { + return xerrors.Errorf("Value in field \"$type\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { + return err + } + if _, err := cw.WriteString(string("$type")); err != nil { + return err + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("site.standard.document"))); err != nil { + return err + } + if _, err := cw.WriteString(string("site.standard.document")); err != nil { + return err + } + + // t.Links (standardsite.Document_Links) (struct) + if t.Links != nil { + + if len("links") > 1000000 { + return xerrors.Errorf("Value in field \"links\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("links"))); err != nil { + return err + } + if _, err := cw.WriteString(string("links")); err != nil { + return err + } + + if err := t.Links.MarshalCBOR(cw); err != nil { + return err + } + } + + // t.Title (string) (string) + if len("title") > 1000000 { + return xerrors.Errorf("Value in field \"title\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("title"))); err != nil { + return err + } + if _, err := cw.WriteString(string("title")); err != nil { + return err + } + + if len(t.Title) > 1000000 { + return xerrors.Errorf("Value in field t.Title was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Title))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.Title)); err != nil { + return err + } + + // t.Labels (standardsite.Document_Labels) (struct) + if t.Labels != nil { + + if len("labels") > 1000000 { + return xerrors.Errorf("Value in field \"labels\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("labels"))); err != nil { + return err + } + if _, err := cw.WriteString(string("labels")); err != nil { + return err + } + + if err := t.Labels.MarshalCBOR(cw); err != nil { + return err + } + } + + // t.Content (standardsite.Document_Content) (struct) + if t.Content != nil { + + if len("content") > 1000000 { + return xerrors.Errorf("Value in field \"content\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("content"))); err != nil { + return err + } + if _, err := cw.WriteString(string("content")); err != nil { + return err + } + + if err := t.Content.MarshalCBOR(cw); err != nil { + return err + } + } + + // t.UpdatedAt (string) (string) + if t.UpdatedAt != nil { + + if len("updatedAt") > 1000000 { + return xerrors.Errorf("Value in field \"updatedAt\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("updatedAt"))); err != nil { + return err + } + if _, err := cw.WriteString(string("updatedAt")); err != nil { + return err + } + + if t.UpdatedAt == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.UpdatedAt) > 1000000 { + return xerrors.Errorf("Value in field t.UpdatedAt was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.UpdatedAt))); err != nil { + return err + } + if _, err := cw.WriteString(string(*t.UpdatedAt)); err != nil { + return err + } + } + } + + // t.CoverImage (util.LexBlob) (struct) + if t.CoverImage != nil { + + if len("coverImage") > 1000000 { + return xerrors.Errorf("Value in field \"coverImage\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("coverImage"))); err != nil { + return err + } + if _, err := cw.WriteString(string("coverImage")); err != nil { + return err + } + + if err := t.CoverImage.MarshalCBOR(cw); err != nil { + return err + } + } + + // t.BskyPostRef (atproto.RepoStrongRef) (struct) + if t.BskyPostRef != nil { + + if len("bskyPostRef") > 1000000 { + return xerrors.Errorf("Value in field \"bskyPostRef\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("bskyPostRef"))); err != nil { + return err + } + if _, err := cw.WriteString(string("bskyPostRef")); err != nil { + return err + } + + if err := t.BskyPostRef.MarshalCBOR(cw); err != nil { + return err + } + } + + // t.Description (string) (string) + if t.Description != nil { + + if len("description") > 1000000 { + return xerrors.Errorf("Value in field \"description\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("description"))); err != nil { + return err + } + if _, err := cw.WriteString(string("description")); err != nil { + return err + } + + if t.Description == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.Description) > 1000000 { + return xerrors.Errorf("Value in field t.Description was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Description))); err != nil { + return err + } + if _, err := cw.WriteString(string(*t.Description)); err != nil { + return err + } + } + } + + // t.PublishedAt (string) (string) + if len("publishedAt") > 1000000 { + return xerrors.Errorf("Value in field \"publishedAt\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("publishedAt"))); err != nil { + return err + } + if _, err := cw.WriteString(string("publishedAt")); err != nil { + return err + } + + if len(t.PublishedAt) > 1000000 { + return xerrors.Errorf("Value in field t.PublishedAt was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.PublishedAt))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.PublishedAt)); err != nil { + return err + } + + // t.TextContent (string) (string) + if t.TextContent != nil { + + if len("textContent") > 1000000 { + return xerrors.Errorf("Value in field \"textContent\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("textContent"))); err != nil { + return err + } + if _, err := cw.WriteString(string("textContent")); err != nil { + return err + } + + if t.TextContent == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.TextContent) > 1000000 { + return xerrors.Errorf("Value in field t.TextContent was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.TextContent))); err != nil { + return err + } + if _, err := cw.WriteString(string(*t.TextContent)); err != nil { + return err + } + } + } + + // t.Contributors ([]*standardsite.Document_Contributor) (slice) + if t.Contributors != nil { + + if len("contributors") > 1000000 { + return xerrors.Errorf("Value in field \"contributors\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("contributors"))); err != nil { + return err + } + if _, err := cw.WriteString(string("contributors")); err != nil { + return err + } + + if len(t.Contributors) > 8192 { + return xerrors.Errorf("Slice value in field t.Contributors was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Contributors))); err != nil { + return err + } + for _, v := range t.Contributors { + if err := v.MarshalCBOR(cw); err != nil { + return err + } + + } + } + return nil +} + +func (t *Document) UnmarshalCBOR(r io.Reader) (err error) { + *t = Document{} + + cr := cbg.NewCborReader(r) + + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") + } + + if extra > cbg.MaxLength { + return fmt.Errorf("Document: map struct too large (%d)", extra) + } + + n := extra + + nameBuf := make([]byte, 12) + for i := uint64(0); i < n; i++ { + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 1000000) + if err != nil { + return err + } + + if !ok { + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { + return err + } + continue + } + + switch string(nameBuf[:nameLen]) { + // t.Path (string) (string) + case "path": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.Path = (*string)(&sval) + } + } + // t.Site (string) (string) + case "site": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.Site = string(sval) + } + // t.Tags ([]string) (slice) + case "tags": + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + + if extra > 8192 { + return fmt.Errorf("t.Tags: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.Tags = make([]string, extra) + } + + for i := 0; i < int(extra); i++ { + { + var maj byte + var extra uint64 + var err error + _ = maj + _ = extra + _ = err + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.Tags[i] = string(sval) + } + + } + } + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.Links (standardsite.Document_Links) (struct) + case "links": + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.Links = new(Document_Links) + if err := t.Links.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Links pointer: %w", err) + } + } + + } + // t.Title (string) (string) + case "title": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.Title = string(sval) + } + // t.Labels (standardsite.Document_Labels) (struct) + case "labels": + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.Labels = new(Document_Labels) + if err := t.Labels.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Labels pointer: %w", err) + } + } + + } + // t.Content (standardsite.Document_Content) (struct) + case "content": + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.Content = new(Document_Content) + if err := t.Content.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Content pointer: %w", err) + } + } + + } + // t.UpdatedAt (string) (string) + case "updatedAt": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.UpdatedAt = (*string)(&sval) + } + } + // t.CoverImage (util.LexBlob) (struct) + case "coverImage": + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.CoverImage = new(util.LexBlob) + if err := t.CoverImage.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.CoverImage pointer: %w", err) + } + } + + } + // t.BskyPostRef (atproto.RepoStrongRef) (struct) + case "bskyPostRef": + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.BskyPostRef = new(atproto.RepoStrongRef) + if err := t.BskyPostRef.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.BskyPostRef pointer: %w", err) + } + } + + } + // t.Description (string) (string) + case "description": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.Description = (*string)(&sval) + } + } + // t.PublishedAt (string) (string) + case "publishedAt": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.PublishedAt = string(sval) + } + // t.TextContent (string) (string) + case "textContent": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.TextContent = (*string)(&sval) + } + } + // t.Contributors ([]*standardsite.Document_Contributor) (slice) + case "contributors": + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + + if extra > 8192 { + return fmt.Errorf("t.Contributors: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.Contributors = make([]*Document_Contributor, extra) + } + + for i := 0; i < int(extra); i++ { + { + var maj byte + var extra uint64 + var err error + _ = maj + _ = extra + _ = err + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.Contributors[i] = new(Document_Contributor) + if err := t.Contributors[i].UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Contributors[i] pointer: %w", err) + } + } + + } + + } + } + + default: + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { + return err + } + } + } + + return nil +} +func (t *Document_Contributor) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + fieldCount := 3 + + if t.DisplayName == nil { + fieldCount-- + } + + if t.Role == nil { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { + return err + } + + // t.Did (string) (string) + if len("did") > 1000000 { + return xerrors.Errorf("Value in field \"did\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("did"))); err != nil { + return err + } + if _, err := cw.WriteString(string("did")); err != nil { + return err + } + + if len(t.Did) > 1000000 { + return xerrors.Errorf("Value in field t.Did was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Did))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.Did)); err != nil { + return err + } + + // t.Role (string) (string) + if t.Role != nil { + + if len("role") > 1000000 { + return xerrors.Errorf("Value in field \"role\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("role"))); err != nil { + return err + } + if _, err := cw.WriteString(string("role")); err != nil { + return err + } + + if t.Role == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.Role) > 1000000 { + return xerrors.Errorf("Value in field t.Role was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Role))); err != nil { + return err + } + if _, err := cw.WriteString(string(*t.Role)); err != nil { + return err + } + } + } + + // t.DisplayName (string) (string) + if t.DisplayName != nil { + + if len("displayName") > 1000000 { + return xerrors.Errorf("Value in field \"displayName\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("displayName"))); err != nil { + return err + } + if _, err := cw.WriteString(string("displayName")); err != nil { + return err + } + + if t.DisplayName == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.DisplayName) > 1000000 { + return xerrors.Errorf("Value in field t.DisplayName was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.DisplayName))); err != nil { + return err + } + if _, err := cw.WriteString(string(*t.DisplayName)); err != nil { + return err + } + } + } + return nil +} + +func (t *Document_Contributor) UnmarshalCBOR(r io.Reader) (err error) { + *t = Document_Contributor{} + + cr := cbg.NewCborReader(r) + + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") + } + + if extra > cbg.MaxLength { + return fmt.Errorf("Document_Contributor: map struct too large (%d)", extra) + } + + n := extra + + nameBuf := make([]byte, 11) + for i := uint64(0); i < n; i++ { + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 1000000) + if err != nil { + return err + } + + if !ok { + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { + return err + } + continue + } + + switch string(nameBuf[:nameLen]) { + // t.Did (string) (string) + case "did": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.Did = string(sval) + } + // t.Role (string) (string) + case "role": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.Role = (*string)(&sval) + } + } + // t.DisplayName (string) (string) + case "displayName": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.DisplayName = (*string)(&sval) + } + } + + default: + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { + return err + } + } + } + + return nil +} +func (t *Document_Placeholder) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{161}); err != nil { + return err + } + + // t.LexiconTypeID (string) (string) + if len("$type") > 1000000 { + return xerrors.Errorf("Value in field \"$type\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { + return err + } + if _, err := cw.WriteString(string("$type")); err != nil { + return err + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("site.standard.document#placeholder"))); err != nil { + return err + } + if _, err := cw.WriteString(string("site.standard.document#placeholder")); err != nil { + return err + } + return nil +} + +func (t *Document_Placeholder) UnmarshalCBOR(r io.Reader) (err error) { + *t = Document_Placeholder{} + + cr := cbg.NewCborReader(r) + + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") + } + + if extra > cbg.MaxLength { + return fmt.Errorf("Document_Placeholder: map struct too large (%d)", extra) + } + + n := extra + + nameBuf := make([]byte, 5) + for i := uint64(0); i < n; i++ { + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 1000000) + if err != nil { + return err + } + + if !ok { + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { + return err + } + continue + } + + switch string(nameBuf[:nameLen]) { + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + + default: + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { + return err + } + } + } + + return nil +} +func (t *Publication) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + fieldCount := 8 + + if t.BasicTheme == nil { + fieldCount-- + } + + if t.Description == nil { + fieldCount-- + } + + if t.Icon == nil { + fieldCount-- + } + + if t.Labels == nil { + fieldCount-- + } + + if t.Preferences == nil { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { + return err + } + + // t.Url (string) (string) + if len("url") > 1000000 { + return xerrors.Errorf("Value in field \"url\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("url"))); err != nil { + return err + } + if _, err := cw.WriteString(string("url")); err != nil { + return err + } + + if len(t.Url) > 1000000 { + return xerrors.Errorf("Value in field t.Url was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Url))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.Url)); err != nil { + return err + } + + // t.Icon (util.LexBlob) (struct) + if t.Icon != nil { + + if len("icon") > 1000000 { + return xerrors.Errorf("Value in field \"icon\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("icon"))); err != nil { + return err + } + if _, err := cw.WriteString(string("icon")); err != nil { + return err + } + + if err := t.Icon.MarshalCBOR(cw); err != nil { + return err + } + } + + // t.Name (string) (string) + if len("name") > 1000000 { + return xerrors.Errorf("Value in field \"name\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("name"))); err != nil { + return err + } + if _, err := cw.WriteString(string("name")); err != nil { + return err + } + + if len(t.Name) > 1000000 { + return xerrors.Errorf("Value in field t.Name was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Name))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.Name)); err != nil { + return err + } + + // t.LexiconTypeID (string) (string) + if len("$type") > 1000000 { + return xerrors.Errorf("Value in field \"$type\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { + return err + } + if _, err := cw.WriteString(string("$type")); err != nil { + return err + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("site.standard.publication"))); err != nil { + return err + } + if _, err := cw.WriteString(string("site.standard.publication")); err != nil { + return err + } + + // t.Labels (standardsite.Publication_Labels) (struct) + if t.Labels != nil { + + if len("labels") > 1000000 { + return xerrors.Errorf("Value in field \"labels\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("labels"))); err != nil { + return err + } + if _, err := cw.WriteString(string("labels")); err != nil { + return err + } + + if err := t.Labels.MarshalCBOR(cw); err != nil { + return err + } + } + + // t.BasicTheme (standardsite.ThemeBasic) (struct) + if t.BasicTheme != nil { + + if len("basicTheme") > 1000000 { + return xerrors.Errorf("Value in field \"basicTheme\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("basicTheme"))); err != nil { + return err + } + if _, err := cw.WriteString(string("basicTheme")); err != nil { + return err + } + + if err := t.BasicTheme.MarshalCBOR(cw); err != nil { + return err + } + } + + // t.Description (string) (string) + if t.Description != nil { + + if len("description") > 1000000 { + return xerrors.Errorf("Value in field \"description\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("description"))); err != nil { + return err + } + if _, err := cw.WriteString(string("description")); err != nil { + return err + } + + if t.Description == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.Description) > 1000000 { + return xerrors.Errorf("Value in field t.Description was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Description))); err != nil { + return err + } + if _, err := cw.WriteString(string(*t.Description)); err != nil { + return err + } + } + } + + // t.Preferences (standardsite.Publication_Preferences) (struct) + if t.Preferences != nil { + + if len("preferences") > 1000000 { + return xerrors.Errorf("Value in field \"preferences\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("preferences"))); err != nil { + return err + } + if _, err := cw.WriteString(string("preferences")); err != nil { + return err + } + + if err := t.Preferences.MarshalCBOR(cw); err != nil { + return err + } + } + return nil +} + +func (t *Publication) UnmarshalCBOR(r io.Reader) (err error) { + *t = Publication{} + + cr := cbg.NewCborReader(r) + + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") + } + + if extra > cbg.MaxLength { + return fmt.Errorf("Publication: map struct too large (%d)", extra) + } + + n := extra + + nameBuf := make([]byte, 11) + for i := uint64(0); i < n; i++ { + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 1000000) + if err != nil { + return err + } + + if !ok { + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { + return err + } + continue + } + + switch string(nameBuf[:nameLen]) { + // t.Url (string) (string) + case "url": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.Url = string(sval) + } + // t.Icon (util.LexBlob) (struct) + case "icon": + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.Icon = new(util.LexBlob) + if err := t.Icon.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Icon pointer: %w", err) + } + } + + } + // t.Name (string) (string) + case "name": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.Name = string(sval) + } + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.Labels (standardsite.Publication_Labels) (struct) + case "labels": + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.Labels = new(Publication_Labels) + if err := t.Labels.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Labels pointer: %w", err) + } + } + + } + // t.BasicTheme (standardsite.ThemeBasic) (struct) + case "basicTheme": + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.BasicTheme = new(ThemeBasic) + if err := t.BasicTheme.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.BasicTheme pointer: %w", err) + } + } + + } + // t.Description (string) (string) + case "description": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.Description = (*string)(&sval) + } + } + // t.Preferences (standardsite.Publication_Preferences) (struct) + case "preferences": + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.Preferences = new(Publication_Preferences) + if err := t.Preferences.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Preferences pointer: %w", err) + } + } + + } + + default: + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { + return err + } + } + } + + return nil +} +func (t *Publication_Preferences) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + fieldCount := 1 + + if t.ShowInDiscover == nil { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { + return err + } + + // t.ShowInDiscover (bool) (bool) + if t.ShowInDiscover != nil { + + if len("showInDiscover") > 1000000 { + return xerrors.Errorf("Value in field \"showInDiscover\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("showInDiscover"))); err != nil { + return err + } + if _, err := cw.WriteString(string("showInDiscover")); err != nil { + return err + } + + if t.ShowInDiscover == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if err := cbg.WriteBool(w, *t.ShowInDiscover); err != nil { + return err + } + } + } + return nil +} + +func (t *Publication_Preferences) UnmarshalCBOR(r io.Reader) (err error) { + *t = Publication_Preferences{} + + cr := cbg.NewCborReader(r) + + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") + } + + if extra > cbg.MaxLength { + return fmt.Errorf("Publication_Preferences: map struct too large (%d)", extra) + } + + n := extra + + nameBuf := make([]byte, 14) + for i := uint64(0); i < n; i++ { + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 1000000) + if err != nil { + return err + } + + if !ok { + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { + return err + } + continue + } + + switch string(nameBuf[:nameLen]) { + // t.ShowInDiscover (bool) (bool) + case "showInDiscover": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + if maj != cbg.MajOther { + return fmt.Errorf("booleans must be major type 7") + } + + var val bool + switch extra { + case 20: + val = false + case 21: + val = true + default: + return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra) + } + t.ShowInDiscover = &val + } + } + + default: + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { + return err + } + } + } + + return nil +} +func (t *GraphRecommend) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{163}); err != nil { + return err + } + + // t.LexiconTypeID (string) (string) + if len("$type") > 1000000 { + return xerrors.Errorf("Value in field \"$type\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { + return err + } + if _, err := cw.WriteString(string("$type")); err != nil { + return err + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("site.standard.graph.recommend"))); err != nil { + return err + } + if _, err := cw.WriteString(string("site.standard.graph.recommend")); err != nil { + return err + } + + // t.Document (string) (string) + if len("document") > 1000000 { + return xerrors.Errorf("Value in field \"document\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("document"))); err != nil { + return err + } + if _, err := cw.WriteString(string("document")); err != nil { + return err + } + + if len(t.Document) > 1000000 { + return xerrors.Errorf("Value in field t.Document was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Document))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.Document)); err != nil { + return err + } + + // t.CreatedAt (string) (string) + if len("createdAt") > 1000000 { + return xerrors.Errorf("Value in field \"createdAt\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("createdAt"))); err != nil { + return err + } + if _, err := cw.WriteString(string("createdAt")); err != nil { + return err + } + + if len(t.CreatedAt) > 1000000 { + return xerrors.Errorf("Value in field t.CreatedAt was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.CreatedAt))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.CreatedAt)); err != nil { + return err + } + return nil +} + +func (t *GraphRecommend) UnmarshalCBOR(r io.Reader) (err error) { + *t = GraphRecommend{} + + cr := cbg.NewCborReader(r) + + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") + } + + if extra > cbg.MaxLength { + return fmt.Errorf("GraphRecommend: map struct too large (%d)", extra) + } + + n := extra + + nameBuf := make([]byte, 9) + for i := uint64(0); i < n; i++ { + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 1000000) + if err != nil { + return err + } + + if !ok { + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { + return err + } + continue + } + + switch string(nameBuf[:nameLen]) { + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.Document (string) (string) + case "document": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.Document = string(sval) + } + // t.CreatedAt (string) (string) + case "createdAt": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.CreatedAt = string(sval) + } + + default: + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { + return err + } + } + } + + return nil +} +func (t *GraphSubscription) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + fieldCount := 3 + + if t.CreatedAt == nil { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { + return err + } + + // t.LexiconTypeID (string) (string) + if len("$type") > 1000000 { + return xerrors.Errorf("Value in field \"$type\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { + return err + } + if _, err := cw.WriteString(string("$type")); err != nil { + return err + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("site.standard.graph.subscription"))); err != nil { + return err + } + if _, err := cw.WriteString(string("site.standard.graph.subscription")); err != nil { + return err + } + + // t.CreatedAt (string) (string) + if t.CreatedAt != nil { + + if len("createdAt") > 1000000 { + return xerrors.Errorf("Value in field \"createdAt\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("createdAt"))); err != nil { + return err + } + if _, err := cw.WriteString(string("createdAt")); err != nil { + return err + } + + if t.CreatedAt == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.CreatedAt) > 1000000 { + return xerrors.Errorf("Value in field t.CreatedAt was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.CreatedAt))); err != nil { + return err + } + if _, err := cw.WriteString(string(*t.CreatedAt)); err != nil { + return err + } + } + } + + // t.Publication (string) (string) + if len("publication") > 1000000 { + return xerrors.Errorf("Value in field \"publication\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("publication"))); err != nil { + return err + } + if _, err := cw.WriteString(string("publication")); err != nil { + return err + } + + if len(t.Publication) > 1000000 { + return xerrors.Errorf("Value in field t.Publication was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Publication))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.Publication)); err != nil { + return err + } + return nil +} + +func (t *GraphSubscription) UnmarshalCBOR(r io.Reader) (err error) { + *t = GraphSubscription{} + + cr := cbg.NewCborReader(r) + + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") + } + + if extra > cbg.MaxLength { + return fmt.Errorf("GraphSubscription: map struct too large (%d)", extra) + } + + n := extra + + nameBuf := make([]byte, 11) + for i := uint64(0); i < n; i++ { + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 1000000) + if err != nil { + return err + } + + if !ok { + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { + return err + } + continue + } + + switch string(nameBuf[:nameLen]) { + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.CreatedAt (string) (string) + case "createdAt": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.CreatedAt = (*string)(&sval) + } + } + // t.Publication (string) (string) + case "publication": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.Publication = string(sval) + } + + default: + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { + return err + } + } + } + + return nil +} +func (t *ThemeBasic) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{165}); err != nil { + return err + } + + // t.LexiconTypeID (string) (string) + if len("$type") > 1000000 { + return xerrors.Errorf("Value in field \"$type\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { + return err + } + if _, err := cw.WriteString(string("$type")); err != nil { + return err + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("site.standard.theme.basic"))); err != nil { + return err + } + if _, err := cw.WriteString(string("site.standard.theme.basic")); err != nil { + return err + } + + // t.Accent (standardsite.ThemeBasic_Accent) (struct) + if len("accent") > 1000000 { + return xerrors.Errorf("Value in field \"accent\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("accent"))); err != nil { + return err + } + if _, err := cw.WriteString(string("accent")); err != nil { + return err + } + + if err := t.Accent.MarshalCBOR(cw); err != nil { + return err + } + + // t.Background (standardsite.ThemeBasic_Background) (struct) + if len("background") > 1000000 { + return xerrors.Errorf("Value in field \"background\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("background"))); err != nil { + return err + } + if _, err := cw.WriteString(string("background")); err != nil { + return err + } + + if err := t.Background.MarshalCBOR(cw); err != nil { + return err + } + + // t.Foreground (standardsite.ThemeBasic_Foreground) (struct) + if len("foreground") > 1000000 { + return xerrors.Errorf("Value in field \"foreground\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("foreground"))); err != nil { + return err + } + if _, err := cw.WriteString(string("foreground")); err != nil { + return err + } + + if err := t.Foreground.MarshalCBOR(cw); err != nil { + return err + } + + // t.AccentForeground (standardsite.ThemeBasic_AccentForeground) (struct) + if len("accentForeground") > 1000000 { + return xerrors.Errorf("Value in field \"accentForeground\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("accentForeground"))); err != nil { + return err + } + if _, err := cw.WriteString(string("accentForeground")); err != nil { + return err + } + + if err := t.AccentForeground.MarshalCBOR(cw); err != nil { + return err + } + return nil +} + +func (t *ThemeBasic) UnmarshalCBOR(r io.Reader) (err error) { + *t = ThemeBasic{} + + cr := cbg.NewCborReader(r) + + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") + } + + if extra > cbg.MaxLength { + return fmt.Errorf("ThemeBasic: map struct too large (%d)", extra) + } + + n := extra + + nameBuf := make([]byte, 16) + for i := uint64(0); i < n; i++ { + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 1000000) + if err != nil { + return err + } + + if !ok { + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { + return err + } + continue + } + + switch string(nameBuf[:nameLen]) { + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.Accent (standardsite.ThemeBasic_Accent) (struct) + case "accent": + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.Accent = new(ThemeBasic_Accent) + if err := t.Accent.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Accent pointer: %w", err) + } + } + + } + // t.Background (standardsite.ThemeBasic_Background) (struct) + case "background": + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.Background = new(ThemeBasic_Background) + if err := t.Background.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Background pointer: %w", err) + } + } + + } + // t.Foreground (standardsite.ThemeBasic_Foreground) (struct) + case "foreground": + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.Foreground = new(ThemeBasic_Foreground) + if err := t.Foreground.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Foreground pointer: %w", err) + } + } + + } + // t.AccentForeground (standardsite.ThemeBasic_AccentForeground) (struct) + case "accentForeground": + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.AccentForeground = new(ThemeBasic_AccentForeground) + if err := t.AccentForeground.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.AccentForeground pointer: %w", err) + } + } + + } + + default: + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { + return err + } + } + } + + return nil +} +func (t *ThemeColor_Rgb) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{164}); err != nil { + return err + } + + // t.B (int64) (int64) + if len("b") > 1000000 { + return xerrors.Errorf("Value in field \"b\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("b"))); err != nil { + return err + } + if _, err := cw.WriteString(string("b")); err != nil { + return err + } + + if t.B >= 0 { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.B)); err != nil { + return err + } + } else { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.B-1)); err != nil { + return err + } + } + + // t.G (int64) (int64) + if len("g") > 1000000 { + return xerrors.Errorf("Value in field \"g\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("g"))); err != nil { + return err + } + if _, err := cw.WriteString(string("g")); err != nil { + return err + } + + if t.G >= 0 { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.G)); err != nil { + return err + } + } else { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.G-1)); err != nil { + return err + } + } + + // t.R (int64) (int64) + if len("r") > 1000000 { + return xerrors.Errorf("Value in field \"r\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("r"))); err != nil { + return err + } + if _, err := cw.WriteString(string("r")); err != nil { + return err + } + + if t.R >= 0 { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.R)); err != nil { + return err + } + } else { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.R-1)); err != nil { + return err + } + } + + // t.LexiconTypeID (string) (string) + if len("$type") > 1000000 { + return xerrors.Errorf("Value in field \"$type\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { + return err + } + if _, err := cw.WriteString(string("$type")); err != nil { + return err + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("site.standard.theme.color#rgb"))); err != nil { + return err + } + if _, err := cw.WriteString(string("site.standard.theme.color#rgb")); err != nil { + return err + } + return nil +} + +func (t *ThemeColor_Rgb) UnmarshalCBOR(r io.Reader) (err error) { + *t = ThemeColor_Rgb{} + + cr := cbg.NewCborReader(r) + + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") + } + + if extra > cbg.MaxLength { + return fmt.Errorf("ThemeColor_Rgb: map struct too large (%d)", extra) + } + + n := extra + + nameBuf := make([]byte, 5) + for i := uint64(0); i < n; i++ { + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 1000000) + if err != nil { + return err + } + + if !ok { + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { + return err + } + continue + } + + switch string(nameBuf[:nameLen]) { + // t.B (int64) (int64) + case "b": + { + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + var extraI int64 + switch maj { + case cbg.MajUnsignedInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 positive overflow") + } + case cbg.MajNegativeInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 negative overflow") + } + extraI = -1 - extraI + default: + return fmt.Errorf("wrong type for int64 field: %d", maj) + } + + t.B = int64(extraI) + } + // t.G (int64) (int64) + case "g": + { + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + var extraI int64 + switch maj { + case cbg.MajUnsignedInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 positive overflow") + } + case cbg.MajNegativeInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 negative overflow") + } + extraI = -1 - extraI + default: + return fmt.Errorf("wrong type for int64 field: %d", maj) + } + + t.G = int64(extraI) + } + // t.R (int64) (int64) + case "r": + { + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + var extraI int64 + switch maj { + case cbg.MajUnsignedInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 positive overflow") + } + case cbg.MajNegativeInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 negative overflow") + } + extraI = -1 - extraI + default: + return fmt.Errorf("wrong type for int64 field: %d", maj) + } + + t.R = int64(extraI) + } + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + + default: + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { + return err + } + } + } + + return nil +} +func (t *ThemeColor_Rgba) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{164}); err != nil { + return err + } + + // t.A (int64) (int64) + if len("a") > 1000000 { + return xerrors.Errorf("Value in field \"a\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("a"))); err != nil { + return err + } + if _, err := cw.WriteString(string("a")); err != nil { + return err + } + + if t.A >= 0 { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.A)); err != nil { + return err + } + } else { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.A-1)); err != nil { + return err + } + } + + // t.B (int64) (int64) + if len("b") > 1000000 { + return xerrors.Errorf("Value in field \"b\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("b"))); err != nil { + return err + } + if _, err := cw.WriteString(string("b")); err != nil { + return err + } + + if t.B >= 0 { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.B)); err != nil { + return err + } + } else { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.B-1)); err != nil { + return err + } + } + + // t.G (int64) (int64) + if len("g") > 1000000 { + return xerrors.Errorf("Value in field \"g\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("g"))); err != nil { + return err + } + if _, err := cw.WriteString(string("g")); err != nil { + return err + } + + if t.G >= 0 { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.G)); err != nil { + return err + } + } else { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.G-1)); err != nil { + return err + } + } + + // t.R (int64) (int64) + if len("r") > 1000000 { + return xerrors.Errorf("Value in field \"r\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("r"))); err != nil { + return err + } + if _, err := cw.WriteString(string("r")); err != nil { + return err + } + + if t.R >= 0 { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.R)); err != nil { + return err + } + } else { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.R-1)); err != nil { + return err + } + } + + return nil +} + +func (t *ThemeColor_Rgba) UnmarshalCBOR(r io.Reader) (err error) { + *t = ThemeColor_Rgba{} + + cr := cbg.NewCborReader(r) + + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") + } + + if extra > cbg.MaxLength { + return fmt.Errorf("ThemeColor_Rgba: map struct too large (%d)", extra) + } + + n := extra + + nameBuf := make([]byte, 1) + for i := uint64(0); i < n; i++ { + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 1000000) + if err != nil { + return err + } + + if !ok { + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { + return err + } + continue + } + + switch string(nameBuf[:nameLen]) { + // t.A (int64) (int64) + case "a": + { + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + var extraI int64 + switch maj { + case cbg.MajUnsignedInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 positive overflow") + } + case cbg.MajNegativeInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 negative overflow") + } + extraI = -1 - extraI + default: + return fmt.Errorf("wrong type for int64 field: %d", maj) + } + + t.A = int64(extraI) + } + // t.B (int64) (int64) + case "b": + { + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + var extraI int64 + switch maj { + case cbg.MajUnsignedInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 positive overflow") + } + case cbg.MajNegativeInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 negative overflow") + } + extraI = -1 - extraI + default: + return fmt.Errorf("wrong type for int64 field: %d", maj) + } + + t.B = int64(extraI) + } + // t.G (int64) (int64) + case "g": + { + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + var extraI int64 + switch maj { + case cbg.MajUnsignedInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 positive overflow") + } + case cbg.MajNegativeInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 negative overflow") + } + extraI = -1 - extraI + default: + return fmt.Errorf("wrong type for int64 field: %d", maj) + } + + t.G = int64(extraI) + } + // t.R (int64) (int64) + case "r": + { + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + var extraI int64 + switch maj { + case cbg.MajUnsignedInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 positive overflow") + } + case cbg.MajNegativeInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 negative overflow") + } + extraI = -1 - extraI + default: + return fmt.Errorf("wrong type for int64 field: %d", maj) + } + + t.R = int64(extraI) + } + + default: + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { + return err + } + } + } + + return nil +} diff --git a/api-ext/standardsite/standarddocument.go b/api-ext/standardsite/standarddocument.go index d79f0392..a4f8d531 100644 --- a/api-ext/standardsite/standarddocument.go +++ b/api-ext/standardsite/standarddocument.go @@ -24,8 +24,8 @@ type Document struct { // bskyPostRef: Strong reference to a Bluesky post. Useful to keep track of comments off-platform. BskyPostRef *comatproto.RepoStrongRef `json:"bskyPostRef,omitempty" cborgen:"bskyPostRef,omitempty"` // content: Open union used to define the record's content. Each entry must specify a $type and may be extended with other lexicons to support additional content formats. - Content *lexutil.LexiconTypeDecoder `json:"content,omitempty" cborgen:"content,omitempty"` - Contributors []*Document_Contributor `json:"contributors,omitempty" cborgen:"contributors,omitempty"` + Content *Document_Content `json:"content,omitempty" cborgen:"content,omitempty"` + Contributors []*Document_Contributor `json:"contributors,omitempty" cborgen:"contributors,omitempty"` // coverImage: Image to used for thumbnail or cover image. Less than 1MB is size. CoverImage *lexutil.LexBlob `json:"coverImage,omitempty" cborgen:"coverImage,omitempty"` // description: A brief description or excerpt from the document. @@ -33,7 +33,7 @@ type Document struct { // labels: Self-label values for this post. Effectively content warnings. Labels *Document_Labels `json:"labels,omitempty" cborgen:"labels,omitempty"` // links: Array of values describing relationships between this document and external resources - Links *lexutil.LexiconTypeDecoder `json:"links,omitempty" cborgen:"links,omitempty"` + Links *Document_Links `json:"links,omitempty" cborgen:"links,omitempty"` // path: Combine with site or publication url to construct a canonical URL to the document. Prepend with a leading slash. Path *string `json:"path,omitempty" cborgen:"path,omitempty"` // publishedAt: Timestamp of the documents publish time. @@ -50,6 +50,61 @@ type Document struct { UpdatedAt *string `json:"updatedAt,omitempty" cborgen:"updatedAt,omitempty"` } +// Open union used to define the record's content. Each entry must specify a $type and may be extended with other lexicons to support additional content formats. +type Document_Content struct { + Document_Placeholder *Document_Placeholder +} + +func (t *Document_Content) MarshalJSON() ([]byte, error) { + if t.Document_Placeholder != nil { + t.Document_Placeholder.LexiconTypeID = "site.standard.document#placeholder" + return json.Marshal(t.Document_Placeholder) + } + return nil, fmt.Errorf("can not marshal empty union as JSON") +} + +func (t *Document_Content) UnmarshalJSON(b []byte) error { + typ, err := lexutil.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "site.standard.document#placeholder": + t.Document_Placeholder = new(Document_Placeholder) + return json.Unmarshal(b, t.Document_Placeholder) + default: + return nil + } +} + +func (t *Document_Content) MarshalCBOR(w io.Writer) error { + + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + if t.Document_Placeholder != nil { + return t.Document_Placeholder.MarshalCBOR(w) + } + return fmt.Errorf("can not marshal empty union as CBOR") +} + +func (t *Document_Content) UnmarshalCBOR(r io.Reader) error { + typ, b, err := lexutil.CborTypeExtractReader(r) + if err != nil { + return err + } + + switch typ { + case "site.standard.document#placeholder": + t.Document_Placeholder = new(Document_Placeholder) + return t.Document_Placeholder.UnmarshalCBOR(bytes.NewReader(b)) + default: + return nil + } +} + // Document_Contributor is a "contributor" in the site.standard.document schema. type Document_Contributor struct { Did string `json:"did" cborgen:"did"` @@ -111,3 +166,65 @@ func (t *Document_Labels) UnmarshalCBOR(r io.Reader) error { return nil } } + +// Array of values describing relationships between this document and external resources +type Document_Links struct { + Document_Placeholder *Document_Placeholder +} + +func (t *Document_Links) MarshalJSON() ([]byte, error) { + if t.Document_Placeholder != nil { + t.Document_Placeholder.LexiconTypeID = "site.standard.document#placeholder" + return json.Marshal(t.Document_Placeholder) + } + return nil, fmt.Errorf("can not marshal empty union as JSON") +} + +func (t *Document_Links) UnmarshalJSON(b []byte) error { + typ, err := lexutil.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "site.standard.document#placeholder": + t.Document_Placeholder = new(Document_Placeholder) + return json.Unmarshal(b, t.Document_Placeholder) + default: + return nil + } +} + +func (t *Document_Links) MarshalCBOR(w io.Writer) error { + + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + if t.Document_Placeholder != nil { + return t.Document_Placeholder.MarshalCBOR(w) + } + return fmt.Errorf("can not marshal empty union as CBOR") +} + +func (t *Document_Links) UnmarshalCBOR(r io.Reader) error { + typ, b, err := lexutil.CborTypeExtractReader(r) + if err != nil { + return err + } + + switch typ { + case "site.standard.document#placeholder": + t.Document_Placeholder = new(Document_Placeholder) + return t.Document_Placeholder.UnmarshalCBOR(bytes.NewReader(b)) + default: + return nil + } +} + +// Document_Placeholder is a "placeholder" in the site.standard.document schema. +// +// Placeholder type used to seed open unions until concrete content/link lexicons are defined. Should not be used in real records. +type Document_Placeholder struct { + LexiconTypeID string `json:"$type" cborgen:"$type,const=site.standard.document#placeholder"` +} diff --git a/gen/main.go b/gen/main.go index 03c4a084..9d7e24c6 100644 --- a/gen/main.go +++ b/gen/main.go @@ -6,6 +6,7 @@ import ( atproto "github.com/bluesky-social/indigo/api/atproto" bsky "github.com/bluesky-social/indigo/api/bsky" chat "github.com/bluesky-social/indigo/api/chat" + standardsite "github.com/bluesky-social/indigo/api-ext/standardsite" "github.com/bluesky-social/indigo/atproto/atdata" "github.com/bluesky-social/indigo/atproto/labeling" atrepo "github.com/bluesky-social/indigo/atproto/repo" @@ -89,6 +90,21 @@ func main() { panic(err) } + if err := genCfg.WriteMapEncodersToFile("api-ext/standardsite/cbor_gen.go", "standardsite", + standardsite.Document{}, + standardsite.Document_Contributor{}, + standardsite.Document_Placeholder{}, + standardsite.Publication{}, + standardsite.Publication_Preferences{}, + standardsite.GraphRecommend{}, + standardsite.GraphSubscription{}, + standardsite.ThemeBasic{}, + standardsite.ThemeColor_Rgb{}, + standardsite.ThemeColor_Rgba{}, + ); err != nil { + panic(err) + } + if err := genCfg.WriteMapEncodersToFile("api/atproto/cbor_gen.go", "atproto", atproto.LexiconSchema{}, atproto.RepoStrongRef{}, diff --git a/lexicons/site/standard/document.json b/lexicons/site/standard/document.json index 5d7d9d8f..07f13021 100644 --- a/lexicons/site/standard/document.json +++ b/lexicons/site/standard/document.json @@ -1,5 +1,10 @@ { "defs": { + "placeholder": { + "description": "Placeholder type used to seed open unions until concrete content/link lexicons are defined. Should not be used in real records.", + "properties": {}, + "type": "object" + }, "contributor": { "properties": { "did": { @@ -35,7 +40,9 @@ "content": { "closed": false, "description": "Open union used to define the record's content. Each entry must specify a $type and may be extended with other lexicons to support additional content formats.", - "refs": [], + "refs": [ + "#placeholder" + ], "type": "union" }, "contributors": { @@ -68,7 +75,9 @@ }, "links": { "description": "Array of values describing relationships between this document and external resources", - "refs": [], + "refs": [ + "#placeholder" + ], "type": "union" }, "path": {