Documentation
¶
Overview ¶
Package datastore contains interfaces and code common to all datastores.
Index ¶
- Constants
- Variables
- func CoreFilterFromRelationshipFilter(filter *v1.RelationshipFilter) *core.RelationshipFilter
- func CredentialsProviderOptions() string
- func DefinitionsOf[T SchemaDefinition](revisionedDefinitions []RevisionedDefinition[T]) []T
- func DeleteAllData(ctx context.Context, ds Datastore) error
- func EngineOptions() string
- func FirstRelationshipIn(iter RelationshipIterator) (tuple.Relationship, bool, error)
- func IteratorToSlice(iter RelationshipIterator) ([]tuple.Relationship, error)
- func NewCaveatNameNotFoundErr(name string) error
- func NewCounterAlreadyRegisteredErr(counterName string, filter *core.RelationshipFilter) error
- func NewCounterNotRegisteredErr(counterName string) error
- func NewInvalidRevisionErr(revision Revision, reason InvalidRevisionReason) error
- func NewMaximumChangesSizeExceededError(maxSize uint64) error
- func NewNamespaceNotFoundErr(nsName string) error
- func NewReadonlyErr() error
- func NewWatchCanceledErr() error
- func NewWatchDisabledErr(reason string) error
- func NewWatchDisconnectedErr() error
- func NewWatchTemporaryErr(wrapped error) error
- func SortedEngineIDs() []string
- func UnwrapAs[T any](datastore Datastore) T
- type BulkWriteRelationshipSource
- type CaveatFilterOption
- type CaveatNameFilter
- type CaveatNameNotFoundError
- type CaveatReader
- type CaveatStorer
- type CounterAlreadyRegisteredError
- type CounterNotRegisteredError
- type CounterReader
- type CounterRegisterer
- type CredentialsProvider
- type Datastore
- type DeleteNamespacesRelationshipsOption
- type EmissionStrategy
- type ErrNotFound
- type ExpirationFilterOption
- type Explainable
- type Feature
- type FeatureStatus
- type Features
- type InvalidRevisionError
- type InvalidRevisionReason
- type MaximumChangesSizeExceededError
- type NamespaceNotFoundError
- type ObjectTypeStat
- type ParsedExplain
- type ReadOnlyDatastore
- type ReadOnlyError
- type ReadWriteTransaction
- type Reader
- type ReadyState
- type RelationshipCounter
- type RelationshipIterator
- type RelationshipQueryOperation
- type RelationshipsFilter
- type RelationshipsQueryTree
- type RepairOperation
- type RepairableDatastore
- type Revision
- type RevisionChanges
- type RevisionedCaveat
- type RevisionedDefinition
- type RevisionedNamespace
- type SQLDatastore
- type SchemaDefinition
- type StartableDatastore
- type Stats
- type StrictReadDatastore
- type SubjectRelationFilter
- func (sf SubjectRelationFilter) IsEmpty() bool
- func (sf SubjectRelationFilter) WithEllipsisRelation() SubjectRelationFilter
- func (sf SubjectRelationFilter) WithNonEllipsisRelation(relation string) SubjectRelationFilter
- func (sf SubjectRelationFilter) WithOnlyNonEllipsisRelations() SubjectRelationFilter
- func (sf SubjectRelationFilter) WithRelation(relation string) SubjectRelationFilter
- type SubjectsFilter
- type SubjectsSelector
- type TxUserFunc
- type UnwrappableDatastore
- type WatchCanceledError
- type WatchContent
- type WatchDisabledError
- type WatchDisconnectedError
- type WatchOptions
- type WatchRetryableError
Constants ¶
const ( // EmitWhenCheckpointedStrategy will buffer changes until a checkpoint is reached. This also means that // changes will be deduplicated and revisions will be sorted before emission as soon as they can be checkpointed. EmitWhenCheckpointedStrategy = iota // EmitImmediatelyStrategy emits changes as soon as they are available. This means changes will not be buffered, // and thus will be emitted as soon as they are available, but clients are responsible for buffering, deduplication, // and sorting revisions. In practical terms that can only happens if Checkpoints have been requested, so enabling // EmitImmediatelyStrategy without Checkpoints will return an error. EmitImmediatelyStrategy )
const (
// AWSIAMCredentialProvider generates AWS IAM tokens for authenticating with the datastore (i.e. RDS)
AWSIAMCredentialProvider = "aws-iam"
)
const Ellipsis = "..."
Ellipsis is a special relation that is assumed to be valid on the right hand side of a tuple.
Variables ¶
var ( ErrClosedIterator = errors.New("unable to iterate: iterator closed") ErrCursorsWithoutSorting = errors.New("cursors are disabled on unsorted results") ErrCursorEmpty = errors.New("cursors are only available after the first result") )
var BuilderForCredentialProvider = map[string]credentialsProviderBuilderFunc{ AWSIAMCredentialProvider: newAWSIAMCredentialsProvider, }
var Engines []string
Functions ¶
func CoreFilterFromRelationshipFilter ¶ added in v1.34.0
func CoreFilterFromRelationshipFilter(filter *v1.RelationshipFilter) *core.RelationshipFilter
CoreFilterFromRelationshipFilter constructs a core RelationshipFilter from a V1 RelationshipsFilter.
func CredentialsProviderOptions ¶ added in v1.32.0
func CredentialsProviderOptions() string
CredentialsProviderOptions returns the full set of credential provider names, sorted and quoted into a string.
func DefinitionsOf ¶ added in v1.16.2
func DefinitionsOf[T SchemaDefinition](revisionedDefinitions []RevisionedDefinition[T]) []T
DefinitionsOf returns just the schema definitions found in the list of revisioned definitions.
func DeleteAllData ¶ added in v1.35.0
DeleteAllData deletes all data from the datastore. Should only be used when explicitly requested. The data is transactionally deleted, which means it may time out.
func EngineOptions ¶
func EngineOptions() string
EngineOptions returns the full set of engine IDs, sorted and quoted into a string.
func FirstRelationshipIn ¶ added in v1.39.0
func FirstRelationshipIn(iter RelationshipIterator) (tuple.Relationship, bool, error)
FirstRelationshipIn returns the first relationship found via the iterator, if any.
func IteratorToSlice ¶ added in v1.39.0
func IteratorToSlice(iter RelationshipIterator) ([]tuple.Relationship, error)
func NewCaveatNameNotFoundErr ¶ added in v1.13.0
NewCaveatNameNotFoundErr constructs a new caveat name not found error.
func NewCounterAlreadyRegisteredErr ¶ added in v1.34.0
func NewCounterAlreadyRegisteredErr(counterName string, filter *core.RelationshipFilter) error
NewCounterAlreadyRegisteredErr constructs a new filter not registered error.
func NewCounterNotRegisteredErr ¶ added in v1.34.0
NewCounterNotRegisteredErr constructs a new counter not registered error.
func NewInvalidRevisionErr ¶
func NewInvalidRevisionErr(revision Revision, reason InvalidRevisionReason) error
NewInvalidRevisionErr constructs a new invalid revision error.
func NewMaximumChangesSizeExceededError ¶ added in v1.36.0
NewMaximumChangesSizeExceededError creates a new MaximumChangesSizeExceededError.
func NewNamespaceNotFoundErr ¶
NewNamespaceNotFoundErr constructs a new namespace not found error.
func NewReadonlyErr ¶
func NewReadonlyErr() error
NewReadonlyErr constructs an error for when a request has failed because the datastore has been configured to be read-only.
func NewWatchCanceledErr ¶
func NewWatchCanceledErr() error
NewWatchCanceledErr constructs a new watch was canceled error.
func NewWatchDisabledErr ¶ added in v1.16.0
NewWatchDisabledErr constructs a new watch is disabled error.
func NewWatchDisconnectedErr ¶
func NewWatchDisconnectedErr() error
NewWatchDisconnectedErr constructs a new watch was disconnected error.
func NewWatchTemporaryErr ¶ added in v1.29.0
NewWatchTemporaryErr wraps another error in watch, indicating that the error is likely a temporary condition and clients may consider retrying by calling watch again (vs a fatal error).
func SortedEngineIDs ¶
func SortedEngineIDs() []string
SortedEngineIDs returns the full set of engine IDs, sorted.
Types ¶
type BulkWriteRelationshipSource ¶ added in v1.22.0
type BulkWriteRelationshipSource interface {
// Next Returns a pointer to a relation tuple if one is available, or nil if
// there are no more or there was an error.
//
// Note: sources may re-use the same memory address for every tuple, data
// may change on every call to next even if the pointer has not changed.
Next(ctx context.Context) (*tuple.Relationship, error)
}
BulkWriteRelationshipSource is an interface for transferring relationships to a backing datastore with a zero-copy methodology.
type CaveatFilterOption ¶ added in v1.43.0
type CaveatFilterOption int
CaveatFilterOption is the filter option for the caveat name field on relationships.
const ( // CaveatFilterOptionNone indicates that the caveat filter should not be used: // relationships both with and without caveats will be returned. CaveatFilterOptionNone CaveatFilterOption = iota // CaveatFilterOptionHasMatchingCaveat indicates that the caveat filter should only // return relationships with the matching caveat. CaveatFilterOptionHasMatchingCaveat // CaveatFilterOptionNoCaveat indicates that the caveat filter should only // return relationships without a caveat. CaveatFilterOptionNoCaveat )
type CaveatNameFilter ¶ added in v1.43.0
type CaveatNameFilter struct {
// Option is the filter option to use for the caveat name.
Option CaveatFilterOption
// CaveatName is the name of the caveat to filter by. Must be specified if option is
// CaveatFilterOptionHasCaveat.
CaveatName string
}
CaveatNameFilter is a filter for caveat names.
func WithCaveatName ¶ added in v1.43.0
func WithCaveatName(caveatName string) CaveatNameFilter
func WithNoCaveat ¶ added in v1.43.0
func WithNoCaveat() CaveatNameFilter
type CaveatNameNotFoundError ¶ added in v1.39.0
type CaveatNameNotFoundError struct {
// contains filtered or unexported fields
}
CaveatNameNotFoundError is the error returned when a caveat is not found by its name
func (CaveatNameNotFoundError) CaveatName ¶ added in v1.39.0
func (err CaveatNameNotFoundError) CaveatName() string
CaveatName returns the name of the caveat that couldn't be found
func (CaveatNameNotFoundError) DetailsMetadata ¶ added in v1.39.0
func (err CaveatNameNotFoundError) DetailsMetadata() map[string]string
DetailsMetadata returns the metadata for details for this error.
func (CaveatNameNotFoundError) IsNotFoundError ¶ added in v1.39.0
func (err CaveatNameNotFoundError) IsNotFoundError() bool
type CaveatReader ¶ added in v1.13.0
type CaveatReader interface {
// ReadCaveatByName returns a caveat with the provided name.
// It returns an instance of CaveatNotFoundError if not found.
ReadCaveatByName(ctx context.Context, name string) (caveat *core.CaveatDefinition, lastWritten Revision, err error)
// ListAllCaveats returns all caveats stored in the system.
ListAllCaveats(ctx context.Context) ([]RevisionedCaveat, error)
// LookupCaveatsWithNames finds all caveats with the matching names.
LookupCaveatsWithNames(ctx context.Context, names []string) ([]RevisionedCaveat, error)
}
CaveatReader offers read operations for caveats
type CaveatStorer ¶ added in v1.13.0
type CaveatStorer interface {
CaveatReader
// WriteCaveats stores the provided caveats, and returns the assigned IDs
// Each element of the returning slice corresponds by position to the input slice
WriteCaveats(context.Context, []*core.CaveatDefinition) error
// DeleteCaveats deletes the provided caveats by name
DeleteCaveats(ctx context.Context, names []string) error
}
CaveatStorer offers both read and write operations for Caveats
type CounterAlreadyRegisteredError ¶ added in v1.39.0
type CounterAlreadyRegisteredError struct {
// contains filtered or unexported fields
}
CounterAlreadyRegisteredError indicates that a counter was already registered.
func (CounterAlreadyRegisteredError) DetailsMetadata ¶ added in v1.39.0
func (err CounterAlreadyRegisteredError) DetailsMetadata() map[string]string
DetailsMetadata returns the metadata for details for this error.
type CounterNotRegisteredError ¶ added in v1.39.0
type CounterNotRegisteredError struct {
// contains filtered or unexported fields
}
CounterNotRegisteredError indicates that a counter was not registered.
func (CounterNotRegisteredError) DetailsMetadata ¶ added in v1.39.0
func (err CounterNotRegisteredError) DetailsMetadata() map[string]string
DetailsMetadata returns the metadata for details for this error.
type CounterReader ¶ added in v1.34.0
type CounterReader interface {
// CountRelationships returns the count of relationships that match the provided counter. If the counter is not
// registered, returns an error.
CountRelationships(ctx context.Context, name string) (int, error)
// LookupCounters returns all registered counters.
LookupCounters(ctx context.Context) ([]RelationshipCounter, error)
}
CounterReader is an interface for reading counts.
type CounterRegisterer ¶ added in v1.34.0
type CounterRegisterer interface {
// RegisterCounter registers a count with the provided filter. If the counter already exists,
// returns an error.
RegisterCounter(ctx context.Context, name string, filter *core.RelationshipFilter) error
// UnregisterCounter unregisters a counter. If the counter did not exist, returns an error.
UnregisterCounter(ctx context.Context, name string) error
// StoreCounterValue stores a count for the counter with the given name, at the given revision.
// If the counter does not exist, returns an error.
StoreCounterValue(ctx context.Context, name string, value int, computedAtRevision Revision) error
}
CounterRegisterer is an interface for registering and unregistering counts.
type CredentialsProvider ¶ added in v1.32.0
type CredentialsProvider interface {
// Name returns the name of the provider
Name() string
// IsCleartextToken returns true if the token returned represents a token (rather than a password) that must be sent in cleartext to the datastore, or false otherwise.
// This may be used to configure the datastore options to avoid sending a hash of the token instead of its value.
// Note that it is always recommended that communication channel be encrypted.
IsCleartextToken() bool
// Get returns the username and password to use when connecting to the underlying datastore
Get(ctx context.Context, dbEndpoint string, dbUser string) (string, string, error)
}
CredentialsProvider allows datastore credentials to be retrieved dynamically
var NoCredentialsProvider CredentialsProvider = nil
func NewCredentialsProvider ¶ added in v1.32.0
func NewCredentialsProvider(ctx context.Context, name string) (CredentialsProvider, error)
NewCredentialsProvider create a new CredentialsProvider for the given name returns an error if no match is found, of if there is a problem creating the given CredentialsProvider
type Datastore ¶
type Datastore interface {
ReadOnlyDatastore
// ReadWriteTx starts a read/write transaction, which will be committed if no error is
// returned and rolled back if an error is returned.
ReadWriteTx(context.Context, TxUserFunc, ...options.RWTOptionsOption) (Revision, error)
}
Datastore represents tuple access for a single namespace.
type DeleteNamespacesRelationshipsOption ¶ added in v1.47.1
type DeleteNamespacesRelationshipsOption int
DeleteNamespacesRelationshipsOption is an option for deleting namespaces and their relationships.
const ( // DeleteNamespacesOnly indicates that only namespaces should be deleted. // It is therefore the caller's responsibility to delete any relationships in those namespaces. DeleteNamespacesOnly DeleteNamespacesRelationshipsOption = iota // DeleteNamespacesAndRelationships indicates that namespaces and all relationships // in those namespaces should be deleted. DeleteNamespacesAndRelationships )
type EmissionStrategy ¶ added in v1.39.0
type EmissionStrategy int
EmissionStrategy describes when changes are emitted to the client.
type ErrNotFound ¶ added in v1.16.2
type ErrNotFound interface {
IsNotFoundError() bool
}
ErrNotFound is a shared interface for not found errors.
type ExpirationFilterOption ¶ added in v1.40.0
type ExpirationFilterOption int
ExpirationFilterOption is the filter option for the expiration field on relationships.
const ( // ExpirationFilterOptionNone indicates that the expiration filter should not be used: // relationships both with and without expiration will be returned. ExpirationFilterOptionNone ExpirationFilterOption = iota // ExpirationFilterOptionHasExpiration indicates that the expiration filter should only // return relationships with an expiration. ExpirationFilterOptionHasExpiration // ExpirationFilterOptionNoExpiration indicates that the expiration filter should only // return relationships without an expiration. ExpirationFilterOptionNoExpiration )
type Explainable ¶ added in v1.42.0
type Explainable interface {
// BuildExplainQuery builds an EXPLAIN statement for the given SQL and arguments.
BuildExplainQuery(sql string, args []any) (string, []any, error)
// ParseExplain parses the output of an EXPLAIN statement.
ParseExplain(explain string) (ParsedExplain, error)
// PreExplainStatements returns any statements that should be run before the EXPLAIN statement.
PreExplainStatements() []string
}
Explainable is an interface for datastores that support EXPLAIN statements.
type Feature ¶ added in v1.11.0
type Feature struct {
Status FeatureStatus
Reason string
}
Feature represents a capability that a datastore can support, plus an optional message explaining the feature is available (or not).
type FeatureStatus ¶ added in v1.36.0
type FeatureStatus int
FeatureStatus are the possible statuses for a feature in the datastore.
const ( // FeatureStatusUnknown indicates that the status of the feature is unknown. // This can be returned, for example, when a call is made to OfflineFeatures // but the feature requires a call to the database to determine its status. FeatureStatusUnknown FeatureStatus = iota // FeatureSupported indicates that the feature is supported by the datastore. FeatureSupported // FeatureUnsupported indicates that the feature is not supported by the datastore. FeatureUnsupported )
type Features ¶ added in v1.11.0
type Features struct {
// Watch is enabled if the underlying datastore can support the Watch api.
Watch Feature
// ContinuousCheckpointing is enabled if the underlying datastore supports continuous checkpointing
// via the Watch API. If not supported, clients of the Watch API may expect checkpoints only when
// new transactions are committed.
ContinuousCheckpointing Feature
// WatchEmitsImmediately indicates if the datastore supports the EmitImmediatelyStrategy EmissionStrategy.
// If not supported, clients of the Watch API will receive an error when calling Watch API with
// EmitImmediatelyStrategy option.
WatchEmitsImmediately Feature
// IntegrityData is enabled if the underlying datastore supports retrieving and storing
// integrity information.
IntegrityData Feature
}
Features holds values that represent what features a database can support.
type InvalidRevisionError ¶ added in v1.39.0
type InvalidRevisionError struct {
// contains filtered or unexported fields
}
InvalidRevisionError occurs when a revision specified to a call was invalid.
func (InvalidRevisionError) InvalidRevision ¶ added in v1.39.0
func (err InvalidRevisionError) InvalidRevision() Revision
InvalidRevision is the revision that failed.
func (InvalidRevisionError) MarshalZerologObject ¶ added in v1.39.0
func (err InvalidRevisionError) MarshalZerologObject(e *zerolog.Event)
MarshalZerologObject implements zerolog object marshalling.
func (InvalidRevisionError) Reason ¶ added in v1.39.0
func (err InvalidRevisionError) Reason() InvalidRevisionReason
Reason is the reason the revision failed.
type InvalidRevisionReason ¶
type InvalidRevisionReason int
InvalidRevisionReason is the reason the revision could not be used.
const ( // RevisionStale is the reason returned when a revision is outside the window of // validity by being too old. RevisionStale InvalidRevisionReason = iota // CouldNotDetermineRevision is the reason returned when a revision for a // request could not be determined. CouldNotDetermineRevision )
type MaximumChangesSizeExceededError ¶ added in v1.36.0
type MaximumChangesSizeExceededError struct {
// contains filtered or unexported fields
}
MaximumChangesSizeExceededError is returned when the maximum size of changes is exceeded.
type NamespaceNotFoundError ¶ added in v1.39.0
type NamespaceNotFoundError struct {
// contains filtered or unexported fields
}
NamespaceNotFoundError occurs when a namespace was not found.
func (NamespaceNotFoundError) DetailsMetadata ¶ added in v1.39.0
func (err NamespaceNotFoundError) DetailsMetadata() map[string]string
DetailsMetadata returns the metadata for details for this error.
func (NamespaceNotFoundError) IsNotFoundError ¶ added in v1.39.0
func (err NamespaceNotFoundError) IsNotFoundError() bool
func (NamespaceNotFoundError) MarshalZerologObject ¶ added in v1.39.0
func (err NamespaceNotFoundError) MarshalZerologObject(e *zerolog.Event)
MarshalZerologObject implements zerolog object marshalling.
func (NamespaceNotFoundError) NotFoundNamespaceName ¶ added in v1.39.0
func (err NamespaceNotFoundError) NotFoundNamespaceName() string
NotFoundNamespaceName is the name of the namespace not found.
type ObjectTypeStat ¶
type ObjectTypeStat struct {
// NumRelations is the number of relations defined in a single object type.
NumRelations uint32
// NumPermissions is the number of permissions defined in a single object type.
NumPermissions uint32
}
ObjectTypeStat represents statistics for a single object type (namespace).
func ComputeObjectTypeStats ¶
func ComputeObjectTypeStats(objTypes []RevisionedNamespace) []ObjectTypeStat
ComputeObjectTypeStats creates a list of object type stats from an input list of parsed object types.
type ParsedExplain ¶ added in v1.42.0
type ParsedExplain struct {
// IndexesUsed is the list of indexes used in the query.
IndexesUsed []string
}
ParsedExplain represents the parsed output of an EXPLAIN statement.
type ReadOnlyDatastore ¶ added in v1.35.0
type ReadOnlyDatastore interface {
// MetricsID returns an identifier for the datastore for use in metrics.
// This identifier is typically the hostname of the datastore (where applicable)
// and may not be unique; callers should not rely on uniqueness.
MetricsID() (string, error)
// UniqueID returns a unique identifier for the datastore. This identifier
// must be stable across restarts of the datastore if the datastore is
// persistent.
UniqueID(context.Context) (string, error)
// SnapshotReader creates a read-only handle that reads the datastore at the specified revision.
// Any errors establishing the reader will be returned by subsequent calls.
SnapshotReader(Revision) Reader
// OptimizedRevision gets a revision that will likely already be replicated
// and will likely be shared amongst many queries.
OptimizedRevision(ctx context.Context) (Revision, error)
// HeadRevision gets a revision that is guaranteed to be at least as fresh as
// right now.
HeadRevision(ctx context.Context) (Revision, error)
// CheckRevision checks the specified revision to make sure it's valid and
// hasn't been garbage collected.
CheckRevision(ctx context.Context, revision Revision) error
// RevisionFromString will parse the revision text and return the specific type of Revision
// used by the specific datastore implementation.
RevisionFromString(serialized string) (Revision, error)
// Watch notifies the caller about changes to the datastore, based on the specified options.
//
// All events following afterRevision will be sent to the caller. Changes made *in* afterRevision will not be included.
//
// When the changes channel is closed, callers MUST discard any changes received (they will be the zero value).
//
// Errors returned will fall into a few classes:
// - WatchDisconnectedError - the watch has fallen too far behind and has been disconnected.
// - WatchCanceledError - the watch was canceled by the caller.
// - WatchDisabledError - the watch is disabled by being unsupported by the datastore.
// - WatchRetryableError - the watch is retryable, and the caller may retry after some backoff time.
// - InvalidRevisionError - the revision specified has passed the datastore's watch history window and
// the watch cannot be retried.
// - Other errors - the watch should not be retried due to a fatal error.
Watch(ctx context.Context, afterRevision Revision, options WatchOptions) (<-chan RevisionChanges, <-chan error)
// ReadyState returns a state indicating whether the datastore is ready to accept data.
// Datastores that require database schema creation will return not-ready until the migrations
// have been run to create the necessary tables.
ReadyState(ctx context.Context) (ReadyState, error)
// Features returns an object representing what features this
// datastore can support. Can make calls to the database, so should
// only be used when a connection is allowed.
Features(ctx context.Context) (*Features, error)
// OfflineFeatures returns an object representing what features this
// datastore supports code-wise, without making any calls to the database.
OfflineFeatures() (*Features, error)
// Statistics returns relevant values about the data contained in this cluster.
Statistics(ctx context.Context) (Stats, error)
// Close closes the data store.
Close() error
}
ReadOnlyDatastore is an interface for reading relationships from the datastore.
type ReadOnlyError ¶ added in v1.39.0
type ReadOnlyError struct {
// contains filtered or unexported fields
}
ReadOnlyError is returned when the operation cannot be completed because the datastore is in read-only mode.
type ReadWriteTransaction ¶
type ReadWriteTransaction interface {
Reader
CaveatStorer
CounterRegisterer
// WriteRelationships takes a list of tuple mutations and applies them to the datastore.
WriteRelationships(ctx context.Context, mutations []tuple.RelationshipUpdate) error
// DeleteRelationships deletes relationships that match the provided filter, with
// the optional limit. Returns the number of deleted relationships. If a limit
// is provided and reached, the method will return true as the second return value.
// Otherwise, the boolean can be ignored.
DeleteRelationships(ctx context.Context, filter *v1.RelationshipFilter,
options ...options.DeleteOptionsOption,
) (uint64, bool, error)
// WriteNamespaces takes proto namespace definitions and persists them.
WriteNamespaces(ctx context.Context, newConfigs ...*core.NamespaceDefinition) error
// DeleteNamespaces deletes namespaces.
DeleteNamespaces(ctx context.Context, nsNames []string, delOption DeleteNamespacesRelationshipsOption) error
// BulkLoad takes a relationship source iterator, and writes all of the
// relationships to the backing datastore in an optimized fashion. This
// method can and will omit checks and otherwise cut corners in the
// interest of performance, and should not be relied upon for OLTP-style
// workloads.
BulkLoad(ctx context.Context, iter BulkWriteRelationshipSource) (uint64, error)
}
type Reader ¶
type Reader interface {
CaveatReader
CounterReader
// QueryRelationships reads relationships, starting from the resource side.
QueryRelationships(
ctx context.Context,
filter RelationshipsFilter,
options ...options.QueryOptionsOption,
) (RelationshipIterator, error)
// ReverseQueryRelationships reads relationships, starting from the subject.
ReverseQueryRelationships(
ctx context.Context,
subjectsFilter SubjectsFilter,
options ...options.ReverseQueryOptionsOption,
) (RelationshipIterator, error)
// ReadNamespaceByName reads a namespace definition and the revision at which it was created or
// last written. It returns an instance of NamespaceNotFoundError if not found.
ReadNamespaceByName(ctx context.Context, nsName string) (ns *core.NamespaceDefinition, lastWritten Revision, err error)
// ListAllNamespaces lists all namespaces defined.
ListAllNamespaces(ctx context.Context) ([]RevisionedNamespace, error)
// LookupNamespacesWithNames finds all namespaces with the matching names.
LookupNamespacesWithNames(ctx context.Context, nsNames []string) ([]RevisionedNamespace, error)
}
Reader is an interface for reading relationships from the datastore.
type ReadyState ¶ added in v1.18.1
type ReadyState struct {
// Message is a human-readable status message for the current state.
Message string
// IsReady indicates whether the datastore is ready.
IsReady bool
}
ReadyState represents the ready state of the datastore.
type RelationshipCounter ¶ added in v1.34.0
type RelationshipCounter struct {
// Name is the name of the counter.
Name string
// Filter is the filter that the count represents.
Filter *core.RelationshipFilter
// Count is the count of relationships that match the filter.
Count int
// ComputedAtRevision is the revision at which the count was last computed. If NoRevision,
// the count has never been computed.
ComputedAtRevision Revision
}
RelationshipCounter is a struct that represents a count of relationships that match a filter.
type RelationshipIterator ¶
type RelationshipIterator iter.Seq2[tuple.Relationship, error]
RelationshipIterator is an iterator over matched tuples. It is a single use iterator.
type RelationshipQueryOperation ¶ added in v1.16.0
type RelationshipQueryOperation int
const ( RelationshipQueryNone RelationshipQueryOperation = 0 RelationshipQueryOr RelationshipQueryOperation = 1 RelationshipQueryAnd RelationshipQueryOperation = 2 )
type RelationshipsFilter ¶ added in v1.12.0
type RelationshipsFilter struct {
// OptionalResourceType is the namespace/type for the resources to be found.
OptionalResourceType string
// OptionalResourceIds are the IDs of the resources to find. If nil empty, any resource ID will be allowed.
// Cannot be used with OptionalResourceIDPrefix.
OptionalResourceIds []string
// OptionalResourceIDPrefix is the prefix to use for resource IDs. If empty, any prefix is allowed.
// Cannot be used with OptionalResourceIds.
OptionalResourceIDPrefix string
// OptionalResourceRelation is the relation of the resource to find. If empty, any relation is allowed.
OptionalResourceRelation string
// OptionalSubjectsSelectors is the selectors to use for subjects of the relationship. If nil, all subjects are allowed.
// If specified, relationships matching *any* selector will be returned.
OptionalSubjectsSelectors []SubjectsSelector
// OptionalCaveatNameFilter is the filter to use for caveated relationships, filtering by a specific caveat name.
// By default, no caveat filtered is done (one direction or the other).
OptionalCaveatNameFilter CaveatNameFilter
// OptionalExpirationOption is the filter to use for relationships with or without an expiration.
OptionalExpirationOption ExpirationFilterOption
}
RelationshipsFilter is a filter for relationships.
func RelationshipsFilterFromCoreFilter ¶ added in v1.34.0
func RelationshipsFilterFromCoreFilter(filter *core.RelationshipFilter) (RelationshipsFilter, error)
RelationshipsFilterFromCoreFilter constructs a datastore RelationshipsFilter from a core RelationshipFilter.
func RelationshipsFilterFromPublicFilter ¶ added in v1.12.0
func RelationshipsFilterFromPublicFilter(filter *v1.RelationshipFilter) (RelationshipsFilter, error)
RelationshipsFilterFromPublicFilter constructs a datastore RelationshipsFilter from an API-defined RelationshipFilter.
func (RelationshipsFilter) Test ¶ added in v1.30.0
func (rf RelationshipsFilter) Test(relationship tuple.Relationship) bool
Test returns true iff the given relationship is matched by this filter.
type RelationshipsQueryTree ¶ added in v1.16.0
type RelationshipsQueryTree struct {
// contains filtered or unexported fields
}
func NewRelationshipQueryTree ¶ added in v1.16.0
func NewRelationshipQueryTree(filter RelationshipsFilter) RelationshipsQueryTree
type RepairOperation ¶ added in v1.28.0
type RepairOperation struct {
// Name is the command-line name for the repair operation.
Name string
// Description is the human-readable description for the repair operation.
Description string
}
RepairOperation represents a single kind of repair operation that can be run in a repairable datastore.
type RepairableDatastore ¶ added in v1.28.0
type RepairableDatastore interface {
Datastore
// Repair runs the repair operation on the datastore.
Repair(ctx context.Context, operationName string, outputProgress bool) error
// RepairOperations returns the available repair operations for the datastore.
RepairOperations() []RepairOperation
}
RepairableDatastore is an optional extension to the datastore interface that, when implemented, provides the ability for callers to repair the datastore's data in some fashion.
type Revision ¶
type Revision interface {
fmt.Stringer
// Equal returns whether the revisions should be considered equal.
Equal(Revision) bool
// GreaterThan returns whether the receiver is probably greater than the right hand side.
GreaterThan(Revision) bool
// LessThan returns whether the receiver is probably less than the right hand side.
LessThan(Revision) bool
// ByteSortable returns true if the string representation of the Revision is byte sortable, false otherwise.
ByteSortable() bool
}
Revision is an interface for a comparable revision type that can be different for each datastore implementation.
var NoRevision Revision = nilRevision{}
NoRevision is a zero type for the revision that will make changing the revision type in the future a bit easier if necessary. Implementations should use any time they want to signal an empty/error revision.
type RevisionChanges ¶
type RevisionChanges struct {
Revision Revision
// RelationshipChanges are any relationships that were changed at this revision.
RelationshipChanges []tuple.RelationshipUpdate
// ChangedDefinitions are any definitions that were added or changed at this revision.
ChangedDefinitions []SchemaDefinition
// DeletedNamespaces are any namespaces that were deleted.
DeletedNamespaces []string
// DeletedCaveats are any caveats that were deleted.
DeletedCaveats []string
// IsCheckpoint, if true, indicates that the datastore has reported all changes
// up until and including the Revision and that no additional schema updates can
// have occurred before this point.
IsCheckpoint bool
// Metadatas is the list of metadata associated with the revision, if any.
Metadatas []*structpb.Struct
}
RevisionChanges represents the changes in a single revision.
func (RevisionChanges) DebugString ¶ added in v1.40.0
func (rc RevisionChanges) DebugString() string
func (RevisionChanges) MarshalZerologObject ¶ added in v1.29.0
func (rc RevisionChanges) MarshalZerologObject(e *zerolog.Event)
type RevisionedCaveat ¶ added in v1.16.2
type RevisionedCaveat = RevisionedDefinition[*core.CaveatDefinition]
RevisionedCaveat is a revisioned version of a caveat definition.
type RevisionedDefinition ¶ added in v1.16.2
type RevisionedDefinition[T SchemaDefinition] struct { // Definition is the namespace or caveat definition. Definition T // LastWrittenRevision is the revision at which the namespace or caveat was last updated. LastWrittenRevision Revision }
RevisionedDefinition holds a schema definition and its last updated revision.
func (RevisionedDefinition[T]) GetLastWrittenRevision ¶ added in v1.25.0
func (rd RevisionedDefinition[T]) GetLastWrittenRevision() Revision
type RevisionedNamespace ¶ added in v1.16.2
type RevisionedNamespace = RevisionedDefinition[*core.NamespaceDefinition]
RevisionedNamespace is a revisioned version of a namespace definition.
type SQLDatastore ¶ added in v1.42.0
type SQLDatastore interface {
Datastore
Explainable
}
SQLDatastore is an interface for datastores that support SQL-based operations.
type SchemaDefinition ¶ added in v1.16.2
SchemaDefinition represents a namespace or caveat definition under a schema.
type StartableDatastore ¶ added in v1.25.0
type StartableDatastore interface {
Datastore
// Start starts any background operations on the datastore. The context provided, if canceled, will
// also cancel the background operation(s) on the datastore.
Start(ctx context.Context) error
}
StartableDatastore is an optional extension to the datastore interface that, when implemented, provides the ability for callers to start background operations on the datastore.
type Stats ¶
type Stats struct {
// UniqueID is a unique string for a single datastore.
UniqueID string
// EstimatedRelationshipCount is a best-guess estimate of the number of relationships
// in the datastore. Computing it should use a lightweight method such as reading
// table statistics.
EstimatedRelationshipCount uint64
// ObjectTypeStatistics returns a slice element for each object type (namespace)
// stored in the datastore.
ObjectTypeStatistics []ObjectTypeStat
}
Stats represents statistics for the entire datastore.
type StrictReadDatastore ¶ added in v1.35.0
type StrictReadDatastore interface {
Datastore
// IsStrictReadModeEnabled returns whether the datastore is in strict read mode.
IsStrictReadModeEnabled() bool
}
StrictReadDatastore is an interface for datastores that support strict read mode.
type SubjectRelationFilter ¶ added in v1.11.0
type SubjectRelationFilter struct {
// NonEllipsisRelation is the relation of the subject type to find. If empty,
// IncludeEllipsisRelation must be true.
NonEllipsisRelation string
// IncludeEllipsisRelation, if true, indicates that the ellipsis relation
// should be included as an option.
IncludeEllipsisRelation bool
// OnlyNonEllipsisRelations, if true, indicates that only non-ellipsis relations
// should be included.
OnlyNonEllipsisRelations bool
}
SubjectRelationFilter is the filter to use for relation(s) of subjects being queried.
func (SubjectRelationFilter) IsEmpty ¶ added in v1.11.0
func (sf SubjectRelationFilter) IsEmpty() bool
IsEmpty returns true if the subject relation filter is empty.
func (SubjectRelationFilter) WithEllipsisRelation ¶ added in v1.11.0
func (sf SubjectRelationFilter) WithEllipsisRelation() SubjectRelationFilter
WithEllipsisRelation indicates that the subject filter should include the ellipsis relation as an option for the subjects' relation.
func (SubjectRelationFilter) WithNonEllipsisRelation ¶ added in v1.11.0
func (sf SubjectRelationFilter) WithNonEllipsisRelation(relation string) SubjectRelationFilter
WithNonEllipsisRelation indicates that the specified non-ellipsis relation should be included as an option for the subjects' relation.
func (SubjectRelationFilter) WithOnlyNonEllipsisRelations ¶ added in v1.16.0
func (sf SubjectRelationFilter) WithOnlyNonEllipsisRelations() SubjectRelationFilter
WithOnlyNonEllipsisRelations indicates that only non-ellipsis relations should be included.
func (SubjectRelationFilter) WithRelation ¶ added in v1.16.0
func (sf SubjectRelationFilter) WithRelation(relation string) SubjectRelationFilter
WithRelation indicates that the specified relation should be included as an option for the subjects' relation.
type SubjectsFilter ¶ added in v1.11.0
type SubjectsFilter struct {
// SubjectType is the namespace/type for the subjects to be found.
SubjectType string
// OptionalSubjectIds are the IDs of the subjects to find. If nil or empty, any subject ID will be allowed.
OptionalSubjectIds []string
// RelationFilter is the filter to use for the relation(s) of the subjects. If neither field
// is set, any relation is allowed.
RelationFilter SubjectRelationFilter
}
SubjectsFilter is a filter for subjects.
func (SubjectsFilter) AsSelector ¶ added in v1.16.0
func (sf SubjectsFilter) AsSelector() SubjectsSelector
type SubjectsSelector ¶ added in v1.16.0
type SubjectsSelector struct {
// OptionalSubjectType is the namespace/type for the subjects to be found, if any.
OptionalSubjectType string
// OptionalSubjectIds are the IDs of the subjects to find. If nil or empty, any subject ID will be allowed.
OptionalSubjectIds []string
// RelationFilter is the filter to use for the relation(s) of the subjects. If neither field
// is set, any relation is allowed.
RelationFilter SubjectRelationFilter
}
SubjectsSelector is a selector for subjects.
func (SubjectsSelector) Test ¶ added in v1.30.0
func (ss SubjectsSelector) Test(subject tuple.ObjectAndRelation) bool
Test returns true iff the given subject is matched by this filter.
type TxUserFunc ¶
type TxUserFunc func(context.Context, ReadWriteTransaction) error
TxUserFunc is a type for the function that users supply when they invoke a read-write transaction.
type UnwrappableDatastore ¶ added in v1.16.0
type UnwrappableDatastore interface {
// Unwrap returns the wrapped datastore.
Unwrap() Datastore
}
UnwrappableDatastore represents a datastore that can be unwrapped into the underlying datastore.
type WatchCanceledError ¶ added in v1.39.0
type WatchCanceledError struct {
// contains filtered or unexported fields
}
WatchCanceledError occurs when a watch was canceled by the caller.
type WatchContent ¶ added in v1.29.0
type WatchContent int
const ( WatchRelationships WatchContent = 1 << 0 WatchSchema WatchContent = 1 << 1 WatchCheckpoints WatchContent = 1 << 2 )
type WatchDisabledError ¶ added in v1.39.0
type WatchDisabledError struct {
// contains filtered or unexported fields
}
WatchDisabledError occurs when watch is disabled by being unsupported by the datastore.
type WatchDisconnectedError ¶ added in v1.39.0
type WatchDisconnectedError struct {
// contains filtered or unexported fields
}
WatchDisconnectedError occurs when a watch has fallen too far behind and was forcibly disconnected as a result.
type WatchOptions ¶ added in v1.29.0
type WatchOptions struct {
// Content is the content to watch.
Content WatchContent
// CheckpointInterval is the interval to use for checkpointing in the watch.
// If given the zero value, the datastore's default will be used. If smaller
// than the datastore's minimum, the minimum will be used.
CheckpointInterval time.Duration
// WatchBufferLength is the length of the buffer for the watch channel. If
// given the zero value, the datastore's default will be used.
WatchBufferLength uint16
// WatchBufferWriteTimeout is the timeout for writing to the watch channel.
// If given the zero value, the datastore's default will be used.
WatchBufferWriteTimeout time.Duration
// WatchConnectTimeout is the timeout for connecting to the watch channel.
// If given the zero value, the datastore's default will be used.
// May not be supported by the datastore.
WatchConnectTimeout time.Duration
// MaximumBufferedChangesByteSize is the maximum byte size of the buffered changes struct.
// If unspecified, no maximum will be enforced. If the maximum is reached before
// the changes can be sent, the watch will be closed with an error.
MaximumBufferedChangesByteSize uint64
// EmissionStrategy defines when are changes streamed to the client. If unspecified, changes will be buffered until
// they can be checkpointed, which is the default behavior.
EmissionStrategy EmissionStrategy
}
WatchOptions are options for a Watch call.
func WatchJustRelationships ¶ added in v1.29.0
func WatchJustRelationships() WatchOptions
WatchJustRelationships returns watch options for just relationships.
func WatchJustSchema ¶ added in v1.29.0
func WatchJustSchema() WatchOptions
WatchJustSchema returns watch options for just schema.
func (WatchOptions) WithCheckpointInterval ¶ added in v1.29.0
func (wo WatchOptions) WithCheckpointInterval(interval time.Duration) WatchOptions
WithCheckpointInterval sets the checkpoint interval on a watch options, returning an updated options struct.
type WatchRetryableError ¶ added in v1.39.0
type WatchRetryableError struct {
// contains filtered or unexported fields
}
WatchRetryableError is returned when a transient/temporary error occurred in watch and indicates that the caller *may* retry the watch after some backoff time.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
|
Code generated by github.com/ecordell/optgen.
|
Code generated by github.com/ecordell/optgen. |