namespace

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewNamespaceNotFoundErr

func NewNamespaceNotFoundErr(nsName string) error

NewNamespaceNotFoundErr constructs a new namespace not found error.

func NewRelationNotFoundErr

func NewRelationNotFoundErr(nsName string, relationName string) error

NewRelationNotFoundErr constructs a new relation not found error.

Types

type AllowedDirectRelation

type AllowedDirectRelation int
const (
	// UnknownIfRelationAllowed indicates that no type information is defined for
	// this relation.
	UnknownIfRelationAllowed AllowedDirectRelation = iota

	// DirectRelationValid indicates that the specified subject relation is valid as
	// part of a *direct* tuple on the relation.
	DirectRelationValid

	// DirectRelationNotValid indicates that the specified subject relation is not
	// valid as part of a *direct* tuple on the relation.
	DirectRelationNotValid
)

type Delta

type Delta struct {
	// Type is the type of this delta.
	Type DeltaType

	// RelationName is the name of the relation to which this delta applies, if any.
	RelationName string

	// DirectType is the direct relation type added or removed, if any.
	DirectType *v0.RelationReference
}

type DeltaType

type DeltaType string

DeltaType defines the type of namespace deltas.

const (
	// NamespaceAdded indicates that the namespace was newly added/created.
	NamespaceAdded DeltaType = "namespace-added"

	// NamespaceRemoved indicates that the namespace was removed.
	NamespaceRemoved DeltaType = "namespace-removed"

	// AddedRelation indicates that the relation was added to the namespace.
	AddedRelation DeltaType = "added-relation"

	// RemovedRelation indicates that the relation was removed from the namespace.
	RemovedRelation DeltaType = "removed-relation"

	// ChangedRelationImpl indicates that the implementation of the relation has changed in some
	// way.
	ChangedRelationImpl DeltaType = "changed-relation-implementation"

	// RelationDirectTypeAdded indicates that an allowed direct relation type has been added to
	// the relation.
	RelationDirectTypeAdded DeltaType = "relation-direct-type-added"

	// RelationDirectTypeRemoved indicates that an allowed direct relation type has been removed from
	// the relation.
	RelationDirectTypeRemoved DeltaType = "relation-direct-type-removed"
)

type ErrNamespaceNotFound

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

ErrNamespaceNotFound occurs when a namespace was not found.

func (ErrNamespaceNotFound) MarshalZerologObject

func (enf ErrNamespaceNotFound) MarshalZerologObject(e *zerolog.Event)

func (ErrNamespaceNotFound) NotFoundNamespaceName

func (enf ErrNamespaceNotFound) NotFoundNamespaceName() string

NotFoundNamespaceName returns the name of the namespace that was not found.

type ErrRelationNotFound

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

ErrRelationNotFound occurs when a relation was not found under a namespace.

func (ErrRelationNotFound) MarshalZerologObject

func (erf ErrRelationNotFound) MarshalZerologObject(e *zerolog.Event)

func (ErrRelationNotFound) NamespaceName

func (erf ErrRelationNotFound) NamespaceName() string

NamespaceName returns the name of the namespace in which the relation was not found.

func (ErrRelationNotFound) NotFoundRelationName

func (erf ErrRelationNotFound) NotFoundRelationName() string

NotFoundRelationName returns the name of the relation not found.

type LookupNamespace added in v0.0.2

type LookupNamespace func(ctx context.Context, name string) (*v0.NamespaceDefinition, error)

LookupNamespace is a function used to lookup a namespace.

type Manager

type Manager interface {
	// ReadNamespace reads a namespace definition and version and returns it if found.
	//
	// Returns ErrNamespaceNotFound if the namespace cannot be found.
	// Returns the direct downstream error for all other unknown error.
	ReadNamespace(ctx context.Context, nsName string) (*v0.NamespaceDefinition, decimal.Decimal, error)

	// CheckNamespaceAndRelation checks that the specified namespace and relation exist in the
	// datastore.
	//
	// Returns ErrNamespaceNotFound if the namespace cannot be found.
	// Returns ErrRelationNotFound if the relation was not found in the namespace.
	// Returns the direct downstream error for all other unknown error.
	CheckNamespaceAndRelation(ctx context.Context, namespace, relation string, allowEllipsis bool) error

	// ReadNamespaceAndTypes reads a namespace definition, version, and type system and returns it if found.
	ReadNamespaceAndTypes(ctx context.Context, nsName string) (*v0.NamespaceDefinition, *NamespaceTypeSystem, decimal.Decimal, error)
}

Manager is a subset of the datastore interface that can read (and possibly cache) namespaces.

func NewCachingNamespaceManager

func NewCachingNamespaceManager(
	delegate datastore.Datastore,
	expiration time.Duration,
	cacheConfig *ristretto.Config,
) (Manager, error)

type NamespaceDiff

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

NamespaceDiff holds the diff between two namespaces.

func DiffNamespaces

func DiffNamespaces(existing *v0.NamespaceDefinition, updated *v0.NamespaceDefinition) (*NamespaceDiff, error)

DiffNamespaces performs a diff between two namespace definitions. One or both of the definitions can be `nil`, which will be treated as an add/remove as applicable.

func (NamespaceDiff) Deltas

func (nd NamespaceDiff) Deltas() []Delta

Deltas returns the deltas between the two namespaces.

type NamespaceTypeSystem

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

NamespaceTypeSystem represents typing information found in a namespace.

func BuildNamespaceTypeSystem

func BuildNamespaceTypeSystem(nsDef *v0.NamespaceDefinition, lookupNamespace LookupNamespace) (*NamespaceTypeSystem, error)

BuildNamespaceTypeSystem constructs a type system view of a namespace definition.

func BuildNamespaceTypeSystemForDefs added in v0.0.2

func BuildNamespaceTypeSystemForDefs(nsDef *v0.NamespaceDefinition, allDefs []*v0.NamespaceDefinition) (*NamespaceTypeSystem, error)

BuildNamespaceTypeSystemForDefs constructs a type system view of a namespace definition, with lookup in the list of definitions given.

func BuildNamespaceTypeSystemForManager added in v0.0.2

func BuildNamespaceTypeSystemForManager(nsDef *v0.NamespaceDefinition, manager Manager) (*NamespaceTypeSystem, error)

BuildNamespaceTypeSystemForManager constructs a type system view of a namespace definition, with automatic lookup via the namespace manager.

func BuildNamespaceTypeSystemWithFallback added in v0.0.2

func BuildNamespaceTypeSystemWithFallback(nsDef *v0.NamespaceDefinition, manager Manager, additionalDefs []*v0.NamespaceDefinition) (*NamespaceTypeSystem, error)

BuildNamespaceTypeSystemWithFallback constructs a type system view of a namespace definition, with automatic lookup via the additional defs first, and then the namespace manager as a fallback.

func (*NamespaceTypeSystem) AllowedDirectRelations

func (nts *NamespaceTypeSystem) AllowedDirectRelations(sourceRelationName string) ([]*v0.RelationReference, error)

AllowedDirectRelations returns the allowed subject relations for a source relation.

func (*NamespaceTypeSystem) HasRelation

func (nts *NamespaceTypeSystem) HasRelation(relationName string) bool

HasRelation returns true if the namespace has the given relation defined.

func (*NamespaceTypeSystem) HasTypeInformation added in v0.0.2

func (nts *NamespaceTypeSystem) HasTypeInformation(relationName string) bool

HasTypeInformation returns true if the relation with the given name exists and has type information defined.

func (*NamespaceTypeSystem) IsAllowedDirectRelation

func (nts *NamespaceTypeSystem) IsAllowedDirectRelation(sourceRelationName string, targetNamespaceName string, targetRelationName string) (AllowedDirectRelation, error)

IsAllowedDirectRelation returns whether the subject relation is allowed to appear on the right hand side of a tuple placed in the source relation with the given name.

func (*NamespaceTypeSystem) IsPermission added in v0.0.2

func (nts *NamespaceTypeSystem) IsPermission(relationName string) bool

IsPermission returns true if the namespace has the given relation defined and it is a permission.

func (*NamespaceTypeSystem) Validate

func (nts *NamespaceTypeSystem) Validate(ctx context.Context) error

Validate runs validation on the type system for the namespace to ensure it is consistent.

Jump to

Keyboard shortcuts

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