The vocabulary/lexicon generation
Generating code should start from a Go struct with annotations, or from a JSON-LD context document.
The steps should be something like this:
Structure
We need to validate the struct’s compatibility with the Vanilla AP objects:
- the properties must match the position and type of one of the
Object,Actor,IntransitiveActivity,Activity,Link, etc. - the struct must validate against the JSON-LD contexts that the developer chooses for them.
Helper functions
Generate helper functions in the lexicon package:
- Initializer function:
vocab.New<Type>- Perhaps fluent API builders - with generics - would provide a better UX?
lexicon.Builder[lexicon.Object]().Type(lexicon.NoteType)
- Perhaps fluent API builders - with generics - would provide a better UX?
- Generate function type
With<Type>Fnthat’s used as parameters forOn<StructName> - Generate functions:
On<StructName>, andTo<StructName>- Perhaps change
To<StructName>to return*StructName, boolinstead of error
- Perhaps change
- Generate
MarshalJSON/UnmarshalJSON,GobEncode/GobDecode - Add type switch cases to the
IsObject,IsActor,IsActivity,IsIntransitiveActivity,IsLink - Add type switch cases to the
ToObject,ToActor,ToActivity,ToIntransitiveActivity,ToLink - Add type switch cases to the
IsNilfunction.
Types constraints
Accumulate types for generated objects and add their types to the slices for:
ActorTypes: struct has Inbox/Outbox propertiesActivityTypes: struct has Actor/Object propertiesIntransitiveActivityTypes: struct has Actor property but no Object propertyLinkTypes: no ID property, but has a Href property.CollectionTypes: struct hasItems/OrderedItemsandTotalItems(perhapsNext?).ObjectTypes: what’s left? - This is the default when there’s nothing else annotated.
Accumulate types into the interfaces that can be used by generic code (Actors, Objects, etc).