Documentation Wiki

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:

Helper functions

Generate helper functions in the lexicon package:

One thing we need to consider is that the Tombstone object can be used as any of the other object types, because it’s the artefact of a Delete activity. So an object reconstituted after a Delete could be used in places as a specific Actor type, for example.

Types constraints

Accumulate types for generated objects and add their types to the slices for:

Accumulate types into the interfaces that can be used by generic code (Actors, Objects, etc).

Codecs for the data types

As we already mentioned, since we know the structure of the generated data types, the package should include the encoding/decoding functionality for at least two types of representations:

JSON-LD

We have already done some preliminary work for facilitating the generation of Go code from JSON-LD contexts.

It’s uncertain if the contexts are able to provide enough information in order to generate a full type for Go, so the fallback option is to generate from type stubs written as Go code.

Eg:

type Example struct {
    vocab.Object `` // Hint to the generator that we want to extend an object
    NewProperty vocab.Item `` // a New Property
}

Expanded

The data types will need to include annotations for the expanded property names, or some mapping method.

Compacted

The simple method for encoding will most likely need the property name and the corresponding value.

Binary

This should probably not be a gob dependent encoding, as it requires registering data types with it.

Since we control the implementations for all the types that are likely to appear, we can rely on a manual method for binary encoding.