document

package
v0.0.0-...-865bf36 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2015 License: LGPL-2.1 Imports: 5 Imported by: 12

Documentation

Overview

DEJE Documents and events.

Document contents are reconstructed through *history*, and history is a graph of Events. For more information about how events are applied to reconstruct the contents of a document, see the go-deje/state package.

The history model works as follows:

Events act like commits, expressing a change/delta from a parent state. They can be simple primitives, or complex custom events, but even complex events end up being boiled down into primitives internally when you apply them.

Timestamps are polled via some external registry, like the Bitcoin network. They tie Events specific times, or rather, a chronological order. Earlier timestamps take precedence over later ones, so that a set of former Acceptors can't rewrite history.

For more info, see the timestamps module.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Document

type Document struct {
	State *state.DocumentState `json:"-"`

	// Do not modify the contents of the following fields!
	// They're there for you to have convenient and uninhibited
	// READ-ONLY access. If you try to add or remove things manually,
	// you run the risk of doing so inconsistently.
	//
	// Please just use the Thing.Register() and Thing.Unregister()
	// methods, and when it comes to these fields, LOOK BUT DON'T TOUCH.
	Events         EventSet            `json:"events"`
	EventsByParent map[string]EventSet `json:"-"`
	Timestamps     []string            `json:"timestamps"`
}

A document is a single managed DEJE object, associated with a single immutable topic string, and self-describing its actions and permissions as part of the content.

The content of a Document is the result of applying the "official" chain of history, in much the same way that the Bitcoin ledger is the result of playing through the transactions in every block of the longest valid blockchain.

func NewDocument

func NewDocument() Document

Create a new, blank Document, with fields initialized.

func (*Document) Deserialize

func (doc *Document) Deserialize(r io.Reader) error

Deserialize JSON data from an io.Reader.

func (*Document) NewEvent

func (doc *Document) NewEvent(handler_name string) Event

func (*Document) Serialize

func (doc *Document) Serialize(w io.Writer) error

Serialize JSON data to an io.Writer.

type Event

type Event struct {
	Doc         *Document              `json:"-"`
	ParentHash  string                 `json:"parent"`
	HandlerName string                 `json:"handler"`
	Arguments   map[string]interface{} `json:"args"`
}

An Event is an action that can be applied to a DEJE doc, including a set of parameters. In practice, custom Event types may be defined for a document, as well as permissions for which users are allowed to perform which types of Events.

func NewEvent

func NewEvent(hname string) Event

func (Event) Apply

func (e Event) Apply() error

Attempt to apply this event to the current document state.

Does not check that the document is at the Event's parent before attempting to apply primitives.

func (*Event) CompatibleWith

func (A *Event) CompatibleWith(B *Event) (bool, error)

Returns whether two events are on compatible forks.

This means that they are on the same fork. This means one is the parent of the other (or the events are equal).

func (Event) Eq

func (e Event) Eq(other Event) bool

func (Event) GetChildren

func (e Event) GetChildren() EventSet

Get a list of the children of an Event.

func (*Event) GetCommonAncestor

func (A *Event) GetCommonAncestor(B *Event) (*Event, error)

Given a set of Events, and two specific ones to trace, find the most recent common parent between the two chains.

If A is the common ancestor, it is a parent of B. And vice versa - if B is the common ancestor, it is a parent of A. There is also the corner case where you compare an Event against itself, and get that same Event. However, if the common ancestor is neither A nor B, than the two Events are not in the same chain of history, and must be considered incompatible branches of the Event chain.

There may not be a common ancestor. In this event, we return an error.

func (Event) GetGroupKey

func (e Event) GetGroupKey() string

func (*Event) GetHistory

func (e *Event) GetHistory() ([]*Event, bool)

Get a linear history of the Events leading up to the given Event.

If we fail to find a parent at any point, we return (nil, false).

func (Event) GetKey

func (e Event) GetKey() string

func (*Event) GetParent

func (e *Event) GetParent() (*Event, bool)

Convenience function. Panics if e.Doc is nil.

func (*Event) GetRoot

func (tip *Event) GetRoot() (event *Event, ok bool)

Traverse up the chain of parents until there's no more to traverse.

func (Event) Goto

func (e Event) Goto() error

Attempt to navigate the DocumentState to this Event.

Somewhat analogous to git checkout.

func (Event) Hash

func (e Event) Hash() string

Get the hash of the Event object.

func (*Event) Register

func (e *Event) Register()

Register with the Doc. This stores it in a hash-based location, so do not make changes to an Event after it has been registered.

func (*Event) SetParent

func (e *Event) SetParent(p Event)

func (*Event) Unregister

func (e *Event) Unregister()

Unregister from the Doc. This also cleans up empty groups.

type EventSet

type EventSet map[string]*Event

func (EventSet) Contains

func (es EventSet) Contains(ev Event) bool

Jump to

Keyboard shortcuts

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