entity

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2022 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const UnsetId = Id("unset")

Variables

This section is empty.

Functions

func IsErrMultipleMatch

func IsErrMultipleMatch(err error) bool

func SeparateIds

func SeparateIds(prefix string) (primaryPrefix string, secondaryPrefix string)

SeparateIds extract primary and secondary prefix from an arbitrary length prefix of an Id created with CombineIds.

Types

type Alphabetical

type Alphabetical []Id

func (Alphabetical) Len

func (a Alphabetical) Len() int

func (Alphabetical) Less

func (a Alphabetical) Less(i, j int) bool

func (Alphabetical) Swap

func (a Alphabetical) Swap(i, j int)

type ErrInvalidFormat

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

func NewErrInvalidFormat

func NewErrInvalidFormat(version uint, expected uint) *ErrInvalidFormat

func NewErrUnknownFormat

func NewErrUnknownFormat(expected uint) *ErrInvalidFormat

func (ErrInvalidFormat) Error

func (e ErrInvalidFormat) Error() string

type ErrMultipleMatch

type ErrMultipleMatch struct {
	Matching []Id
	// contains filtered or unexported fields
}

func NewErrMultipleMatch

func NewErrMultipleMatch(entityType string, matching []Id) *ErrMultipleMatch

func (ErrMultipleMatch) Error

func (e ErrMultipleMatch) Error() string

type Id

type Id string

Id is an identifier for an entity or part of an entity

func CombineIds

func CombineIds(primary Id, secondary Id) Id

CombineIds compute a merged Id holding information from both the primary Id and the secondary Id.

This allow to later find efficiently a secondary element because we can access the primary one directly instead of searching for a primary that has a secondary matching the Id.

An example usage is Comment in a Bug. The interleaved Id will hold part of the Bug Id and part of the Comment Id.

To allow the use of an arbitrary length prefix of this Id, Ids from primary and secondary are interleaved with this irregular pattern to give the best chance to find the secondary even with a 7 character prefix.

Format is: PSPSPSPPPSPPPPSPPPPSPPPPSPPPPSPPPPSPPPPSPPPPSPPPPSPPPPSPPPPSPPPP

A complete interleaved Id hold 50 characters for the primary and 14 for the secondary, which give a key space of 36^50 for the primary (~6 * 10^77) and 36^14 for the secondary (~6 * 10^21). This asymmetry assume a reasonable number of secondary within a primary Entity, while still allowing for a vast key space for the primary (that is, a globally merged database) with a low risk of collision.

Here is the breakdown of several common prefix length:

5: 3P, 2S 7: 4P, 3S 10: 6P, 4S 16: 11P, 5S

func DeriveId

func DeriveId(data []byte) Id

DeriveId generate an Id from the serialization of the object or part of the object.

func RefToId

func RefToId(ref string) Id

RefsToIds parse a git reference and return the corresponding Entity's Id.

func RefsToIds

func RefsToIds(refs []string) []Id

RefsToIds parse a slice of git references and return the corresponding Entity's Id.

func (Id) HasPrefix

func (i Id) HasPrefix(prefix string) bool

func (Id) Human

func (i Id) Human() string

Human return the identifier, shortened for human consumption

func (Id) MarshalGQL

func (i Id) MarshalGQL(w io.Writer)

MarshalGQL implement the Marshaler interface for gqlgen

func (Id) String

func (i Id) String() string

String return the identifier as a string

func (*Id) UnmarshalGQL

func (i *Id) UnmarshalGQL(v interface{}) error

UnmarshalGQL implement the Unmarshaler interface for gqlgen

func (Id) Validate

func (i Id) Validate() error

IsValid tell if the Id is valid

type Interface

type Interface interface {
	// Id return the Entity identifier
	//
	// This Id need to be immutable without having to store the entity somewhere (ie, an entity only in memory
	// should have a valid Id, and it should not change if further edit are done on this entity).
	// How to achieve that is up to the entity itself. A common way would be to take a hash of an immutable data at
	// the root of the entity.
	// It is acceptable to use such a hash and keep mutating that data as long as Id() is not called.
	Id() Id
}

type MergeResult

type MergeResult struct {
	// Err is set when a terminal error occur in the process
	Err error

	Id     Id
	Status MergeStatus

	// Only set for Invalid status
	Reason string

	// Only set for New or Updated status
	Entity Interface
}

MergeResult hold the result of a merge operation on an Entity.

func NewMergeError

func NewMergeError(err error, id Id) MergeResult

func NewMergeInvalidStatus

func NewMergeInvalidStatus(id Id, reason string) MergeResult

func NewMergeNewStatus

func NewMergeNewStatus(id Id, entity Interface) MergeResult

func NewMergeNothingStatus

func NewMergeNothingStatus(id Id) MergeResult

func NewMergeUpdatedStatus

func NewMergeUpdatedStatus(id Id, entity Interface) MergeResult

func (MergeResult) String

func (mr MergeResult) String() string

type MergeStatus

type MergeStatus int

MergeStatus represent the result of a merge operation of an entity

const (
	MergeStatusNew     MergeStatus // a new Entity was created locally
	MergeStatusInvalid             // the remote data is invalid
	MergeStatusUpdated             // a local Entity has been updated
	MergeStatusNothing             // no changes were made to a local Entity (already up to date)
	MergeStatusError               // a terminal error happened
)

Directories

Path Synopsis
Package dag contains the base common code to define an entity stored in a chain of git objects, supporting actions like Push, Pull and Merge.
Package dag contains the base common code to define an entity stored in a chain of git objects, supporting actions like Push, Pull and Merge.

Jump to

Keyboard shortcuts

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