schema

package
v0.5.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 7, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

README

#+TITLE: Schema

* Overview

* Motivation and Rationale
  
* Transaction Messages and Types
  
** Supported Property Types
#+BEGIN_SRC go :tangle types.go
  type PropertyType int

  const (
    OBJECT PropertyType = 0
	  ENUM
    STRING
    INTEGER
    DECIMAL
    BOOL
    DOUBLE
    DATETIME
    DATE
    TIME
    DURATION
    BASE64
    ANYURI
    WKT
  )
#+END_SRC

** Class, Property and Label Integer ID's
   Classes, properties and labels receive an auto-incremented integer ID. This ID is used in references in class and property definitions and can also used for saving storage space in a binary RDF serialization format.

#+BEGIN_SRC go :tangle types.go
  type PropertyID uint64

  type ClassID uint64

  type LabelID uint64
#+END_SRC

** Define Property
   
#+BEGIN_SRC go :tangle types.go
  type ActionDefineProperty struct {
    Agent agent.AgentID `json:"agent"`
    Name string `json:"name"`
    Many bool `json:"many,omitempty"`
    Type PropertyType `json:"type,omitempty"`
    Class ClassID `json:"class,omitempty"`
    SuperProperties []PropertyID `json:"super_properties,omitempty"`
    SubProperties []PropertyID `json:"sub,omitempty"`
	  EnumLabels []LabelID `json:"enum_labels,omitempty"`
    IntegerMin *big.Int `json:"integer_min,omitempty"`
    IntegerMax *big.Int `json:"integer_max,omitempty"`
    DoubleMin *double `json:"double_min,omitempty"`
    DoubleMax *double `json:"double_max,omitempty"`
    Label []LangString `json:"label,omitempty"`
    Comment []LangString `json:"label,omitempty"`
  }

#+END_SRC

** Define Class
   
#+BEGIN_SRC go :tangle types.go
   
  type ActionDefineClass struct {
    Agent agent.AgentID `json:"agent"`
    Name string `json:"name"`
    Properties []PropertyRef `json:"properties,omitempty"`
	  SuperClasses []ClassID `json:"super_classes,omitempty"`
	  SubClasses []ClassID `json:"sub_classes,omitempty"`
    Label []LangString `json:"label,omitempty"`
    Comment []LangString `json:"label,omitempty"`
  }

  type PropertyRef struct {
    Property PropertyID `json:"property"`
    Required bool `json:"required,omitempty"`
  }

#+END_SRC

** Define Label
   Labels are IRI's whose sole purpose is to serve as an enum value.
   
#+BEGIN_SRC go :tangle types.go
   
  type ActionDefineLabel struct {
    Agent agent.AgentID `json:"agent"`
    Name string `json:"name"`
    Label []LangString `json:"label,omitempty"`
    Comment []LangString `json:"label,omitempty"`
  }

#+END_SRC
** Human-readable labels and descriptions

   Human-readable and localized labels and descriptions can be defined using the ~Label~ and ~Comment~ fields of property and class definitions which map to ~rdfs:label~ and ~rdfs:comment~ properties respectively. Their values like in RDF Schema are an array of ~LangString~'s to support localization.

#+BEGIN_SRC go :tangle types.go
  type LangString struct {
    Text String `json:"text,omitempty"`
    Language String `json:"lang,omitempty"`
  }
#+END_SRC
** TODO bulk insertions
** TODO updates to classes (adding optional properties), human-readable text?

* Identifiers
  Properties and classes are identified by the URI formed by taking the agent URI and appending ~s/<name>~.

Documentation

Overview

Package schema defines a module for defining on-chain schema definitions. The rationale for on-chain schema definitions is that a blockchain can enforce schema definition rules that force backwards compatibility. Specifically if a schema property or class is defined to have one meaning at one point, that same identifier can't be redefined with an incompatible meaning in the future. Having consensus around the meaning of schema identifiers provides a basis for which applications developers can safely write interoperable apps that don't break arbitrarily. In addition to providing this basis for consistency, the schema module also aims to provide clear pathways for upgrading schemas and defining schemas which mix and match different parts of other schemas in order to facilitate a new generation of interoperable apps and data, most importantly within the ecological domain.

Index

Constants

View Source
const PropertyNameRegex = "^[a-z][a-zA-Z0-9_]*$"

PropertyNameRegex defines the valid characters for property names. Only lowercase ascii letters are allowed, property names must start with a letter and can otherwise also contain numbers and underscores. Snake case is preferred as a number of sources point suggest it has enhanced readability as opposed to camel case

Variables

View Source
var (
	LastPropertyIDKey = []byte("_/next-property-id")
)

Functions

func NewHandler

func NewHandler(keeper Keeper) sdk.Handler

NewHandler returns a handler for "schema" type messages.

func NewOnChainSchemaResolver

func NewOnChainSchemaResolver(keeper Keeper, ctx sdk.Context) graph.SchemaResolver

func NewProperty

func NewProperty(propertyDefinition PropertyDefinition, uri *url.URL) graph.Property

NewProperty wraps a PropertyDefinition as a Property TODO move this to the schema module

func PropertyKey

func PropertyKey(id graph.PropertyID) []byte

PropertyKey returns the store key for the given graph.PropertyID that points to its PropertyDefinition

func PropertyURLKey

func PropertyURLKey(url string) []byte

PropertyURLKey returns the store key for the given property URL that points to its graph.PropertyID

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

RegisterCodec registers concrete types on the Amino codec

Types

type Keeper

type Keeper struct {
	// contains filtered or unexported fields
}

Keeper is the schema module keeper

func NewKeeper

func NewKeeper(storeKey sdk.StoreKey, cdc *codec.Codec) Keeper

NewKeeper creates a new Keeper

func (Keeper) DefineProperty

func (keeper Keeper) DefineProperty(ctx sdk.Context, def PropertyDefinition) (id graph.PropertyID, uri *url.URL, err sdk.Error)

DefineProperty defines a property within the state store return the property's id and URL if it was defined successfully or else an error

func (Keeper) GetLastPropertyID

func (keeper Keeper) GetLastPropertyID(ctx sdk.Context) graph.PropertyID

func (Keeper) GetPropertyDefinition

func (keeper Keeper) GetPropertyDefinition(ctx sdk.Context, id graph.PropertyID) (prop PropertyDefinition, found bool)

GetProperty returns a PropertyDefinition given a graph.PropertyID if one exists

func (Keeper) GetPropertyID

func (keeper Keeper) GetPropertyID(ctx sdk.Context, propertyURL string) graph.PropertyID

GetPropertyID returns the ID for a property URL if one exists, the graph.PropertyID 0 indicates no property with this URL is defined

type PropertyDefinition

type PropertyDefinition struct {
	// Creator is the entity that defined this property
	Creator sdk.AccAddress `json:"creator"`
	// Name is the human-readable name of the property within the creator's namespace of properties
	Name string `json:"name"`
	// Many indicates whether or not this property can be assigned more than once to a given node/object. If it is
	// false, then the property can only be assigned once for a given node/object
	Arity graph.Arity `json:"arity:omitempty"`
	// PropertyType indicates the data type of the property
	PropertyType graph.PropertyType `json:"type,omitempty"`
}

PropertyDefinition defines the schema for a property

func (PropertyDefinition) GetSignBytes

func (prop PropertyDefinition) GetSignBytes() []byte

GetSignBytes returns the bytes over which to sign

func (PropertyDefinition) GetSigners

func (prop PropertyDefinition) GetSigners() []sdk.AccAddress

GetSigners returns the addresses which must sign the message

func (PropertyDefinition) Route

func (PropertyDefinition) Route() string

Route returns the route of the message

func (PropertyDefinition) String

func (prop PropertyDefinition) String() string

func (PropertyDefinition) Type

func (PropertyDefinition) Type() string

Type returns the type of the message

func (PropertyDefinition) URI

func (prop PropertyDefinition) URI() *url.URL

URL returns the URL of the property

func (PropertyDefinition) ValidateBasic

func (prop PropertyDefinition) ValidateBasic() sdk.Error

ValidateBasic ensures that Creator and Name are non-empty and the PropertyType is valid

Directories

Path Synopsis
cli

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL