Documentation
¶
Index ¶
- Constants
- func IsErrMultipleMatch(err error) bool
- func IsErrNotFound(err error) bool
- func Resolve[T Resolved](rs Resolvers, id Id) (T, error)
- func SeparateIds(prefix string) (primaryPrefix string, secondaryPrefix string)
- type CachedResolver
- type CombinedId
- func (ci CombinedId) HasPrefix(prefix string) bool
- func (ci CombinedId) Human() string
- func (ci CombinedId) MarshalGQL(w io.Writer)
- func (ci CombinedId) PrimaryPrefix() string
- func (ci CombinedId) SecondaryPrefix() string
- func (ci CombinedId) String() string
- func (ci *CombinedId) UnmarshalGQL(v interface{}) error
- func (ci CombinedId) Validate() error
- type ErrInvalidFormat
- type ErrMultipleMatch
- type ErrNotFound
- type Id
- type Interface
- type MergeResult
- type MergeStatus
- type Resolved
- type Resolver
- type ResolverFunc
- type Resolvers
- type StreamedEntity
Constants ¶
const HumanIdLength = 7
const UnsetCombinedId = CombinedId("unset")
const UnsetId = Id("unset")
Variables ¶
This section is empty.
Functions ¶
func IsErrMultipleMatch ¶
func IsErrNotFound ¶
func Resolve ¶
Resolve use the appropriate sub-resolver for the given type and find the Entity matching the Id.
func SeparateIds ¶
SeparateIds extract primary and secondary prefix from an arbitrary length prefix of an Id created with CombineIds.
Types ¶
type CachedResolver ¶
type CachedResolver struct {
// contains filtered or unexported fields
}
CachedResolver is a resolver ensuring that loading is done only once through another Resolver.
func NewCachedResolver ¶
func NewCachedResolver(resolver Resolver) *CachedResolver
type CombinedId ¶
type CombinedId string
CombinedId is an Id holding information from both a primary Id and a secondary Id. While it looks like a regular Id, do not just cast from one to another. Instead, use CombineIds and SeparateIds to create it and split it.
func CombineIds ¶
func CombineIds(primary Id, secondary Id) CombinedId
CombineIds compute a merged Id holding information from both the primary Id and the secondary Id.
This allows 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 assumes 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 (CombinedId) HasPrefix ¶
func (ci CombinedId) HasPrefix(prefix string) bool
func (CombinedId) Human ¶
func (ci CombinedId) Human() string
Human return the identifier, shortened for human consumption
func (CombinedId) MarshalGQL ¶
func (ci CombinedId) MarshalGQL(w io.Writer)
MarshalGQL implement the Marshaler interface for gqlgen
func (CombinedId) PrimaryPrefix ¶
func (ci CombinedId) PrimaryPrefix() string
PrimaryPrefix is a helper to extract the primary prefix. If practical, use SeparateIds instead.
func (CombinedId) SecondaryPrefix ¶
func (ci CombinedId) SecondaryPrefix() string
SecondaryPrefix is a helper to extract the secondary prefix. If practical, use SeparateIds instead.
func (CombinedId) String ¶
func (ci CombinedId) String() string
String return the identifier as a string
func (*CombinedId) UnmarshalGQL ¶
func (ci *CombinedId) UnmarshalGQL(v interface{}) error
UnmarshalGQL implement the Unmarshaler interface for gqlgen
type ErrInvalidFormat ¶
type ErrInvalidFormat struct {
// contains filtered or unexported fields
}
ErrInvalidFormat is to be returned when reading on-disk data with an unexpected format or version.
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
}
ErrMultipleMatch is to be returned when more than one entity, item, element is found, where only one was expected.
func NewErrMultipleMatch ¶
func NewErrMultipleMatch(typename string, matching []Id) *ErrMultipleMatch
func (ErrMultipleMatch) Error ¶
func (e ErrMultipleMatch) Error() string
type ErrNotFound ¶
type ErrNotFound struct {
// contains filtered or unexported fields
}
ErrNotFound is to be returned when an entity, item, element is not found.
func NewErrNotFound ¶
func NewErrNotFound(typename string) *ErrNotFound
func (ErrNotFound) Error ¶
func (e ErrNotFound) Error() string
type Id ¶
type Id string
Id is an identifier for an entity or part of an entity
func RefsToIds ¶
RefsToIds parse a slice of git references and return the corresponding Entity's Id.
func (Id) MarshalGQL ¶
MarshalGQL implement the Marshaler interface for gqlgen
func (*Id) UnmarshalGQL ¶
UnmarshalGQL implement the Unmarshaler interface for gqlgen
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
// Validate check if the Entity data is valid
Validate() error
}
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 )
type Resolved ¶
type Resolved interface {
// Id returns the object identifier.
Id() Id
}
Resolved is a minimal interface on which Resolver operates on. Notably, this operates on Entity and Excerpt in the cache.
type Resolver ¶
Resolver is an interface to find an Entity from its Id
func MakeResolver ¶
MakeResolver create a resolver able to return the given entities.
type ResolverFunc ¶
ResolverFunc is a helper to morph a function resolver into a Resolver
Source Files
¶
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. |