ent

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AllowPrivacyResult returns a value indicating that the ent should be visible to the viewer.
	// We use HTTP status code 200 for the lols
	AllowPrivacyResult privacyResult = 200

	// DenyPrivacyResult returns a value indicating that the ent should should not be visible to the viewer.
	// We use HTTP status code 401 for the lols
	DenyPrivacyResult privacyResult = 401

	// SkipPrivacyResult returns a value indicating that the ent should not be visible to the viewer.
	// We use HTTP status code 307 for the lols
	SkipPrivacyResult privacyResult = 307
)

Variables

View Source
var ErrAllOperations = errors.New("All operation dependencies")

ErrAllOperations is like io.EOF. It signals a known error state and that callers of Executor.Operation() can stop calling

Functions

func ApplyPrivacyForEnt

func ApplyPrivacyForEnt(v viewer.ViewerContext, entity Entity) error

ApplyPrivacyForEnt takes an ent and evaluates whether the ent is visible or not

func ApplyPrivacyPolicy

func ApplyPrivacyPolicy(v viewer.ViewerContext, policy PrivacyPolicy, ent Entity) error

ApplyPrivacyPolicy takes a viewer, a privacy policy and the underlying ent that the privacy will be applied to This is useful for things like actions or per-field privacy where the privacy policy is different than the privacy for the ent but we still need the ent because that's what's passed to each PrivacyPolicyRule

func CoalesceErr

func CoalesceErr(errs ...error) error

CoalesceErr a variable numbers of errors and returns an error for now, it returns the first element TODO: return something that handles all the errors together

func DisableCache

func DisableCache()

DisableCache disables the default in-memory cache. this is not thread safe TODO: provide better options for this and ways to configure memory/redis/etc

func EdgeData

func EdgeData(data string) func(*EdgeOperation)

EdgeData provides the ability to change the data field of an edge. Passed to Edge modification functions

func EdgeTime

func EdgeTime(t time.Time) func(*EdgeOperation)

EdgeTime provides the ability to change the time of an edge. Passed to Edge modification functions

func EdgeTimeRawNumber

func EdgeTimeRawNumber(num int64) func(*EdgeOperation)

EdgeTimeRawNumber provides the ability to store a raw number in the time field of an edge e.g. to keep track of an ordering, use this Passed to Edge modification functions

func EnableCache

func EnableCache()

EnableCache enables the in-memory cache. inverse of EnableCache

func GenLoadAssocEdges

func GenLoadAssocEdges() <-chan AssocEdgeDatasResult

GenLoadAssocEdges loads all assoc edges from the db TODO correct cache for this. we should load this once per request or have this be in a central cache easily available

func GenLoadEdgeByType

func GenLoadEdgeByType(id1, id2 string, edgeType EdgeType) <-chan *AssocEdgeResult

GenLoadEdgeByType is the concurrent version of LoadEdgeByType

func GenLoadEdgesByType

func GenLoadEdgesByType(id string, edgeType EdgeType, options ...func(*LoadEdgeConfig)) <-chan *AssocEdgesResult

GenLoadEdgesByType handles loading of edges concurrently. Because we get strong typing across all edges and for a consistent API with loading Nodes, we use the EdgesResult struct here

func GenLoadNode

func GenLoadNode(v viewer.ViewerContext, id string, loader PrivacyBackedLoader) <-chan error

GenLoadNode is the concurrent version of LoadNode.

func GenLoadNodes

func GenLoadNodes(v viewer.ViewerContext, ids []string, entLoader PrivacyBackedLoader) <-chan error

GenLoadNodes loads a list of nodes given the ids

func GenLoadNodesByType

func GenLoadNodesByType(v viewer.ViewerContext, id string, edgeType EdgeType, entLoader PrivacyBackedLoader) <-chan error

GenLoadNodesByType loads a list of nodes given the id and edgetype

func GenLoadNodesViaQueryClause

func GenLoadNodesViaQueryClause(v viewer.ViewerContext, entLoader PrivacyBackedLoader, clause sql.QueryClause) <-chan error

GenLoadNodesViaQueryClause loads a list of nodes givens a query clause e.g. fetching all nodes with a foreign key

func GenLoadUniqueEdgeByType

func GenLoadUniqueEdgeByType(id string, edgeType EdgeType) <-chan *AssocEdgeResult

GenLoadUniqueEdgeByType is the concurrent version of LoadUniqueEdgeByType

func GenLoadUniqueNodeByType

func GenLoadUniqueNodeByType(v viewer.ViewerContext, id string, edgeType EdgeType, loader PrivacyBackedLoader) chan error

GenLoadUniqueNodeByType loads the unique node for a given edge type

func GetEdgeInfos

func GetEdgeInfos(edgeTypes []string) (map[EdgeType]*AssocEdgeData, error)

GetEdgeInfos gets the edge information for a list of edges

func IsInvalidEntPrivacyError

func IsInvalidEntPrivacyError(err error) bool

IsInvalidEntPrivacyError returns a boolean indicating if an error is because an ent does not implement the right privacy policy

func IsInvalidPrivacyRule

func IsInvalidPrivacyRule(err error) bool

IsInvalidPrivacyRule returns a boolean indicating if an error is because of an invalid privacy rule which is why the ent is not visible

func IsPrivacyError

func IsPrivacyError(err error) bool

IsPrivacyError returns a boolean indicating if an error is a privacy error that indicates an ent is not visible

func Limit

func Limit(limit int) func(*LoadEdgeConfig)

Limit is an option passed to edge queries to limit the number of edges returned

func LoadNode

func LoadNode(v viewer.ViewerContext, id string, loader PrivacyBackedLoader) error

LoadNode fetches an id given the viewer and id

func LoadNodeRawData

func LoadNodeRawData(id string, entLoader Loader) (map[string]interface{}, error)

LoadNodeRawData is the public API to load the raw data for an ent without privacy checks

func LoadNodeRawDataViaQueryClause

func LoadNodeRawDataViaQueryClause(entLoader Loader, clause sql.QueryClause) (map[string]interface{}, error)

LoadNodeRawDataViaQueryClause takes a query clause e.g. sql.Eq("email_address", "test@email.com") and returns the raw data for a (the) node that maps to that

func LoadNodeViaQueryClause

func LoadNodeViaQueryClause(v viewer.ViewerContext, entLoader PrivacyBackedLoader, clause sql.QueryClause) error

LoadNodeViaQueryClause loads a node with a query clause e.g. load the user given the query to load via email address like sql.Eq("email_address", "test@example.com")

func LoadNodes

func LoadNodes(v viewer.ViewerContext, ids []string, entLoader PrivacyBackedLoader) error

LoadNodes loads a list of nodes given the ids

func LoadNodesByType

func LoadNodesByType(v viewer.ViewerContext, id string, edgeType EdgeType, entLoader PrivacyBackedLoader) error

LoadNodesByType loads a list of nodes given the id and edgetype

func LoadNodesRawData

func LoadNodesRawData(ids []string, entLoader Loader) ([]map[string]interface{}, error)

LoadNodesRawData loads raw data for multiple objects given their ids

func LoadNodesRawDataViaQueryClause

func LoadNodesRawDataViaQueryClause(entLoader Loader, clause sql.QueryClause) ([]map[string]interface{}, error)

LoadNodesRawDataViaQueryClause takes a query clause e.g. sql.Eq("id", "{id of foreign key here}") and returns the raw data for all nodes that map to that

func LoadNodesViaQueryClause

func LoadNodesViaQueryClause(v viewer.ViewerContext, entLoader PrivacyBackedLoader, clause sql.QueryClause) error

LoadNodesViaQueryClause loads a list of nodes givens a query clause e.g. fetching all nodes with a foreign key

func LoadRawNodesByType

func LoadRawNodesByType(id string, edgeType EdgeType, entLoader Loader) ([]map[string]interface{}, error)

LoadRawNodesByType loads the nodes at the end of an edge

func LoadRawQuery

func LoadRawQuery(query string, loader Loader) ([]map[string]interface{}, error)

LoadRawQuery takes a raw query string and runs it and gets the results in the raw format

func LoadUniqueNodeByType

func LoadUniqueNodeByType(v viewer.ViewerContext, id string, edgeType EdgeType, loader PrivacyBackedLoader) error

LoadUniqueNodeByType loads the unique node for a given edge type

func SaveChangeset

func SaveChangeset(changeset Changeset) error

SaveChangeset is the public API for saving a changeset

Types

type ActionConfig

type ActionConfig struct {
	// Action type
	Action ActionOperation
	Fields []string // restrict the fields that can be mutated in this action to the following fields
	//	MutationOnlyFields  // TODO v2  map[string]{Type of some sort} e.g. ConfirmPassword string
	CustomActionName string // override default generated Go name
	// Flag to hide action(s) from GraphQL
	HideFromGraphQL bool
	// override default graphql name generated
	CustomGraphQLName string
}

ActionConfig provides a way to configure the actions generated for the ent

type ActionOperation

type ActionOperation uint

ActionOperation is a named type that represents the different actions to be generated.

const (
	// CreateAction generates a create action for the ent. If no fields are provided, uses all fields
	// on the ent. Doesn't include private fields if no fields are provided.
	CreateAction ActionOperation = 1 << iota
	// EditAction generates an edit action for the ent. If no fields are provided, uses all fields
	// on the ent. Can have multiple EditActions with different fields provided. Doesn't include
	// private fields if no fields are provided.
	EditAction
	// DeleteAction generates a delete action for the ent.
	DeleteAction
	// MutationsAction is a shortcut to generate create, edit, and delete actions for an ent
	// Can be used to boostrap ents or for simple ents where the granularity of actions is overkill
	// Provides CUD	of CRUD. Can be the default for most ents. Should rarely be used for the `User` or `Account` ent
	MutationsAction
	// AddEdgeAction is used to provide the ability to add an edge in an AssociationEdge.
	AddEdgeAction
	// RemoveEdgeAction is used to provide the ability to remove an edge in an AssociationEdge.
	RemoveEdgeAction
	// EdgeGroupAction is used to provide the abilith to edit an edge group in an AssociationEdgeGroup.
	EdgeGroupAction
)

type AssocEdge

type AssocEdge struct {
	ID1      string         `db:"id1"`
	ID1Type  NodeType       `db:"id1_type"`
	EdgeType EdgeType       `db:"edge_type"`
	ID2      string         `db:"id2"`
	ID2Type  NodeType       `db:"id2_type"`
	Time     time.Time      `db:"time"`
	Data     sql.NullString `db:"data"`
}

AssocEdge is the information about an edge between two Nodes It's generic enough so that it applies across all types. Doesn't care what table it's stored in.

func LoadEdgeByType

func LoadEdgeByType(id string, id2 string, edgeType EdgeType) (*AssocEdge, error)

LoadEdgeByType checks if an edge exists between 2 ids

func LoadEdgesByType

func LoadEdgesByType(id string, edgeType EdgeType, options ...func(*LoadEdgeConfig)) ([]*AssocEdge, error)

LoadEdgesByType loads the edges for a given type

func LoadUniqueEdgeByType

func LoadUniqueEdgeByType(id string, edgeType EdgeType) (*AssocEdge, error)

LoadUniqueEdgeByType loads the unique edge for a given type. Applies a limit 1 to the query

func (*AssocEdge) DBFields

func (edge *AssocEdge) DBFields() DBFields

DBFields is used by the ent framework to load the edge from the underlying database

func (*AssocEdge) GetID

func (edge *AssocEdge) GetID() string

GetID returns a unique id for this ent TODO ola. audit where this is used right now

type AssocEdgeConfig

type AssocEdgeConfig struct {
	EdgeType        string `db:"edge_type"`
	EdgeName        string `db:"edge_type"`
	SymmetricEdge   bool   `db:"symmetric_edge"`
	InverseEdgeType string `db:"inverse_edge_type"`
	EdgeTable       string `db:"edge_table"`
}

AssocEdgeConfig is configuration used to configure edges in the ent-framework

func (*AssocEdgeConfig) GetTableName

func (config *AssocEdgeConfig) GetTableName() string

GetTableName returns the underyling database table the model's data is stored

type AssocEdgeData

type AssocEdgeData struct {
	EdgeType        EdgeType       `db:"edge_type" pkey:"true"` // if you have a pkey, don't add id uuid since we already have one...
	EdgeName        string         `db:"edge_name"`
	SymmetricEdge   bool           `db:"symmetric_edge"`
	InverseEdgeType sql.NullString `db:"inverse_edge_type"`
	EdgeTable       string         `db:"edge_table"`
	Timestamps
}

AssocEdgeData is corresponding ent for AssocEdgeConfig

func GetEdgeInfo

func GetEdgeInfo(edgeType EdgeType, tx *sqlx.Tx) (*AssocEdgeData, error)

GetEdgeInfo gets the edge information for a given edgeType TODO figure out correct long-term API here this is the single get of GenLoadAssocEdges so shouldn't be too hard

func (*AssocEdgeData) DBFields

func (edgeData *AssocEdgeData) DBFields() DBFields

DBFields is used by the ent framework to load the ent from the underlying database

func (*AssocEdgeData) GetConfig

func (edgeData *AssocEdgeData) GetConfig() Config

func (*AssocEdgeData) GetID

func (edgeData *AssocEdgeData) GetID() string

TODO.... all of these exist just to write the ent we need to break this up for tests or worst case translate AssocEdgeData to a fake object that is an ent for use by node_map_test.go

func (*AssocEdgeData) GetPrimaryKey

func (edgeData *AssocEdgeData) GetPrimaryKey() string

GetPrimaryKey is used to let the ent framework know what column is being edited

func (*AssocEdgeData) GetPrivacyPolicy

func (edgeData *AssocEdgeData) GetPrivacyPolicy() PrivacyPolicy

func (*AssocEdgeData) GetType

func (edgeData *AssocEdgeData) GetType() NodeType

func (*AssocEdgeData) GetViewer

func (edgeData *AssocEdgeData) GetViewer() viewer.ViewerContext

type AssocEdgeDataResult

type AssocEdgeDataResult struct {
	EdgeData *AssocEdgeData
	Err      error
}

AssocEdgeDataResult stores the result of loading AssocEdgeData

func (*AssocEdgeDataResult) Error

func (res *AssocEdgeDataResult) Error() string

type AssocEdgeDatasResult

type AssocEdgeDatasResult struct {
	Edges []*AssocEdgeData
	Err   error
}

AssocEdgeDatasResult stores the result of loading all assoc edges concurrently

func (*AssocEdgeDatasResult) Error

func (res *AssocEdgeDatasResult) Error() string

type AssocEdgeLoader

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

AssocEdgeLoader is used to load AssocEdgeData. implements Loader interface

func (*AssocEdgeLoader) GetConfig

func (res *AssocEdgeLoader) GetConfig() Config

GetConfig returns the config/scheme for this object

func (*AssocEdgeLoader) GetMap

func (res *AssocEdgeLoader) GetMap() map[EdgeType]*AssocEdgeData

GetMap returns a map of EdgeType to AssocEdgeData Provides a non-list API for the loaded data

func (*AssocEdgeLoader) GetNewInstance

func (res *AssocEdgeLoader) GetNewInstance() DBObject

GetNewInstance reutrns a new AssocEdgeData to be used to retrieve data from database

func (*AssocEdgeLoader) GetPrimaryKey

func (res *AssocEdgeLoader) GetPrimaryKey() string

GetPrimaryKey indicates which column is the primary key in the assoc_edge_config table

type AssocEdgeMap

type AssocEdgeMap map[string]*AssociationEdge

AssocEdgeMap is a mapping of name of edge to EdgeType

type AssocEdgeResult

type AssocEdgeResult struct {
	Edge *AssocEdge
	Err  error
}

AssocEdgeResult stores the result of loading an Edge concurrently

func (*AssocEdgeResult) Error

func (res *AssocEdgeResult) Error() string

type AssocEdgesResult

type AssocEdgesResult struct {
	Edges []*AssocEdge
	Err   error
}

AssocEdgesResult stores the result of loading a slice of edges concurrently

func (*AssocEdgesResult) Error

func (res *AssocEdgesResult) Error() string

type AssocStatusMap

type AssocStatusMap map[string]*AssociationEdgeGroupStatusInfo

type AssociationEdge

type AssociationEdge struct {
	EntConfig interface{} // zero-value of the struct
	//CustomTableName string      // TODO come back
	// have to pick one or the other
	InverseEdge *InverseAssocEdge
	Symmetric   bool
	// Unique indicates that there's only one instance of this edge
	Unique bool

	// TODO inverse and other fun things about edges
	// same with foreign key edge
	EdgeActions EdgeActions
}

AssociationEdge is the fb-style edge where the information is stored in the edges_info table. This is the preferred edge in the framework

func (AssociationEdge) Name

func (AssociationEdge) Name() string

type AssociationEdgeGroup

type AssociationEdgeGroup struct {
	EdgeGroups      AssocEdgeMap
	GroupStatusName string // Name of the group e.g. Rsvp. will be used to create a Node{GroupName}Status object and a bunch of other things
	EdgeActions     EdgeActions
	CustomTableName string

	// Edges limits the edges that are used in the status action calculations. status map.
	// If no edges are provided, all in the group are
	ActionEdges []string
}

func (AssociationEdgeGroup) Name

type AssociationEdgeGroupStatusInfo

type AssociationEdgeGroupStatusInfo struct {
	EdgeName          string
	Edge              EdgeType
	ConstName         interface{}
	UseInStatusAction bool
}

type Changeset

type Changeset interface {
	// Returns the Executor which is used to do the write.
	// This should be expected to be called multiple times easily.
	GetExecutor() Executor
	GetViewer() viewer.ViewerContext
	Entity() Entity
	// This should match the PlaceholderID of the MutationBuilder that produced this changeset
	GetPlaceholderID() string
	// keeping these 2 just in case...
	ExistingEnt() Entity //existing ent // hmm we just need ID!
	EntConfig() Config   // just in case...
}

Changeset is what's responsible for actually performing the write Once we get here, we assume that things like privacy and all other things that may prevent a mutation from executing have been dealt with A changeset can be bundled with other changesets to create a mutation dependency tree

type ChangesetWithDependencies

type ChangesetWithDependencies interface {
	Changeset
	// Map of placeholder id -> Builder
	// Useful for the executor to know the correct order of operations when performing writes
	Dependencies() MutationBuilderMap
	// List of dependent changesets
	Changesets() []Changeset
}

ChangesetWithDependencies represents a changeset that has other changesets as dependencies.

type Config

type Config interface {
	// GetTableName returns the underyling database table the model's data is stored
	// TODO how do we get a default value without reflection at run time.
	// TOOD embedding or something fancier later with default values may be better
	GetTableName() string
}

Config interface that configurations for an ent should implement.

type ConfigWithActions

type ConfigWithActions interface {
	Config
	GetActions() []*ActionConfig
}

ConfigWithActions is the interface that EntConfig which have actions implements

type ConfigWithEdges

type ConfigWithEdges interface {
	Config
	// GetEdges returns the edges that the ent supports
	GetEdges() EdgeMap
}

ConfigWithEdges is the interface that EntConfigs which have edges implement

type ConfigWithFields

type ConfigWithFields interface {
	Config
	GetFields() FieldMap
}

ConfigWithFields is the interface that EntConfigs which have fields implement

type DBFields

type DBFields map[string]func(interface{}) error

type DBObject

type DBObject interface {
	// TODO what happens for tables with composite primary keys??
	GetID() string
	DBFields() DBFields
}

DBObject references an item fetched from the database All ents are DBObjects but not all DBOjects are necessarily ents e.g. AssocEdge TODO rename to more generic name that's not DB only.

type DBObjectWithDiffKey

type DBObjectWithDiffKey interface {
	DBObject
	GetPrimaryKey() string // for now only do single primary key
}

DBObjectWithDiffKey should be implemented to indicate that the primary key in the table isn't "id" but a different field. For now only supports single primary key so not exposing it publicly Only used for update at the moment

type DataOperation

type DataOperation interface {
	PerformWrite(tx *sqlx.Tx) error
}

DataOperation corresponds to an individual operation to write to the database could be inserting a node, deleting a node, adding an edge, etc Ent framework comes with different operations which handle common things Each operation is returned by Executor

type DataOperationWithCreatedEnt

type DataOperationWithCreatedEnt interface {
	DataOperation
	CreatedEnt() Entity
}

DataOperationWithCreatedEnt indicates an operation which can create an ent This is used to track placeholder ids and id of the created ent

type DataOperationWithResolver

type DataOperationWithResolver interface {
	DataOperation
	Resolve(Executor) error
}

DataOperationWithResolver corresponds to an operation which can resolve placeholder ids so that the executor ca nbe passed to it as needed

type DeleteNodeOperation

type DeleteNodeOperation struct {
	ExistingEnt Entity
	EntConfig   Config
}

DeleteNodeOperation indicates we're deleting an ent

func (*DeleteNodeOperation) PerformWrite

func (op *DeleteNodeOperation) PerformWrite(tx *sqlx.Tx) error

PerformWrite deletes the node from the database

type DenyWithReasonResult

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

DenyWithReasonResult is the error returned by privacy

func DenyWithReason

func DenyWithReason(err error) DenyWithReasonResult

DenyWithReason is used to encode other errors as part of the privacy result

func (DenyWithReasonResult) Err

func (r DenyWithReasonResult) Err() error

Err returns the error that indicates the reason why the ent was denied

func (DenyWithReasonResult) Error

func (r DenyWithReasonResult) Error() string

Error exists to satisfy the error interface

func (DenyWithReasonResult) Result

func (r DenyWithReasonResult) Result() privacyResult

Result returns DenyPrivacyResult indicating that the privacy rule was enough to make the ent not visible to the viewer

type Edge

type Edge interface {
	Name() string
	// contains filtered or unexported methods
}

Edge indicates a relationship/connection between 2 or more nodes This interface isn't fully fleshed out yet but it allows the API to be clearer

type EdgeActionConfig

type EdgeActionConfig struct {
	Action            ActionOperation // only AddEdgeAction and RemoveEdgeAction are supported
	CustomActionName  string          // override default generated Go name
	HideFromGraphQL   bool            // Flag to hide action(s) from GraphQL
	CustomGraphQLName string          // override default graphql name generated
}

EdgeActionConfig provides a way to configure the actions generated for an AssociationEdge

type EdgeActions

type EdgeActions []*EdgeActionConfig

EdgeActions is a named type for a list of EdgeActionConfig for simpler typing

type EdgeMap

type EdgeMap map[string]Edge

EdgeMap is a mapping of name of edge to EdgeType

type EdgeOperation

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

EdgeOperation handles creating, editing or deleting an edge

func NewInboundEdge

func NewInboundEdge(
	edgeType EdgeType,
	op WriteOperation,
	id1 interface{},
	nodeType NodeType,
	mb MutationBuilder,
	options ...func(*EdgeOperation)) *EdgeOperation

NewInboundEdge returns a new edge from id1 -> viewer

func NewOutboundEdge

func NewOutboundEdge(
	edgeType EdgeType,
	op WriteOperation,
	id2 interface{},
	nodeType NodeType,
	mb MutationBuilder,
	options ...func(*EdgeOperation)) *EdgeOperation

NewOutboundEdge returns a new edge from viewer -> id2

func (*EdgeOperation) EdgeType

func (op *EdgeOperation) EdgeType() EdgeType

EdgeType returns the edge type of the Operation

func (*EdgeOperation) InverseEdge

func (op *EdgeOperation) InverseEdge(edgeType EdgeType) *EdgeOperation

InverseEdge returns the inverse edge of the current edge with the provided edgeType

func (*EdgeOperation) PerformWrite

func (op *EdgeOperation) PerformWrite(tx *sqlx.Tx) error

PerformWrite writes the edge to the database

func (*EdgeOperation) Resolve

func (op *EdgeOperation) Resolve(exec Executor) error

Resolve replaces any placeholders this operation has with the actual ID of the created ent

func (*EdgeOperation) SymmetricEdge

func (op *EdgeOperation) SymmetricEdge() *EdgeOperation

SymmetricEdge returns a symmetric edge of the current one with id1 and id2 swapped

type EdgeOptions

type EdgeOptions struct {
	Time time.Time
	Data string
}

EdgeOptions is a struct that can be used to configure an edge. Time refers to the time associated with the edge. If not specified, defaults to current time Data refers to whatever information that needs to be stored/associated with the edge It's up to 255 characters (hmm not true right now)

type EdgeType

type EdgeType string

EdgeType represents the edge between two nodes. Underlying format is uuid Generated automatically by the ent framework.

type EditNodeOperation

type EditNodeOperation struct {
	ExistingEnt         Entity
	Entity              Entity
	EntConfig           Config
	Fields              map[string]interface{}
	FieldsWithResolvers []string
	Operation           WriteOperation
}

EditNodeOperation indicates we're creating or editing an ent

func (*EditNodeOperation) CreatedEnt

func (op *EditNodeOperation) CreatedEnt() Entity

CreatedEnt returns the newly created ent (if any)

func (*EditNodeOperation) PerformWrite

func (op *EditNodeOperation) PerformWrite(tx *sqlx.Tx) error

PerformWrite writes the node to the database

func (*EditNodeOperation) Resolve

func (op *EditNodeOperation) Resolve(exec Executor) error

Resolve replaces any placeholders this operation has with the actual ID of the created ent

type Entity

type Entity interface {
	ObjectWithPrivacyPolicy
	// GetType returns the NodeType of this entity
	//	GetID() string // TODO uuid
	GetType() NodeType
	GetViewer() viewer.ViewerContext
	DBObject
}

type Executor

type Executor interface {
	// Provides an io.Read() style API where the underlying dependency details are hidden
	// away. works when it's one changeset with N operations or N changesets with operations across them.
	// When we're done with operations, it returns ErrAllOperations to signal EOF
	Operation() (DataOperation, error)
	// resolve placeholders from this mutation
	// Called by an Operation which has a placeholder id and returns the ent created by a previous operation so that
	// the right value can be written to the database
	ResolveValue(interface{}) Entity
}

Executor is responsible for sequencing complicated writes that have dependencies on each other For simple writes e.g. insert one row in the database, there's just one operation and nothing to do For complicated writes where there's dependencies between objects and the input of one is dependent on the output of the other, the Executor is expected to figure that and ensure that the operations are sequenced correctly so that the action goes off without a hitch The ent framework provides default Executor so only need to know this if default executor isn't suitable.

type FieldMap

type FieldMap map[string]*field.Field

FieldMap is a mapping of name of field to Field

type InvalidEntPrivacyError

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

InvalidEntPrivacyError is the error type returned when an ent does not implement the right privacy policy

func (*InvalidEntPrivacyError) Error

func (err *InvalidEntPrivacyError) Error() string

Error returns a formatted string that indicates why the ent is not visible

type InvalidPrivacyRule

type InvalidPrivacyRule struct{}

InvalidPrivacyRule is the error type returned when an ent does not have the right privacy rules

func (*InvalidPrivacyRule) Error

func (err *InvalidPrivacyRule) Error() string

Error returns a formatted string that indicates why the ent is not visible

type InverseAssocEdge

type InverseAssocEdge struct {
	EdgeName string
}

type LoadEdgeConfig

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

LoadEdgeConfig configures the way to load edges This will eventually be used in EntQuery but allows us to start testing and building some things...

type Loader

type Loader interface {
	// Returns a new instance of the underlying object to be returned to the client for this loader
	// When a privacy backed loader, should return an Entity with ViewerContext of object set
	GetNewInstance() DBObject
	// Returns the schema of the ent.
	GetConfig() Config
}

Loader is used to load one or more ents Loader with no Load method... We need it to work for also efficiently loading multiple ents so one Load() API doesn't work This will also eventually support different loading mechanisms e.g. db, rest API, memory, etc For now, only postgres db is supported

type LoaderWithDiffPrimaryKey

type LoaderWithDiffPrimaryKey interface {
	Loader
	GetPrimaryKey() string // for now only do single primary key
}

type MutationBuilder

type MutationBuilder interface {
	ExistingEnt() Entity
	Entity() Entity           // TODO Ola: maybe this should get loader instance?
	GetPlaceholderID() string // TODO GetMutationID()?
	GetViewer() viewer.ViewerContext
	GetChangeset() (Changeset, error) // TODO rename to Build()
	GetOperation() WriteOperation
}

MutationBuilder is the building block for a mutation or action. Pieces together the different parts needed for a write

type MutationBuilderMap

type MutationBuilderMap map[string]MutationBuilder

MutationBuilderMap is a named type for a map of placeholder ids to the corresponding MutationBuilder

type Node

type Node struct {
	ID string `db:"id"`
	Timestamps
}

Node is a default reusable object that comes with the ent-framework Right now, all ents have to be nodes. Eventually, we'll have a corresponding NodeConfig that is used to add this to the generated ents.

func (*Node) GetID

func (node *Node) GetID() string

GetID returns the ID of the ent

type NodeType

type NodeType string

NodeType represents each unique node in a project. Generated automatically by the ent framework Eventually will also be used for polymorphic edges, id disambiguation, generic ent loads and other such things

type ObjectWithPrivacyPolicy

type ObjectWithPrivacyPolicy interface {
	GetPrivacyPolicy() PrivacyPolicy
}

type PrivacyBackedLoader

type PrivacyBackedLoader interface {
	Loader
	// Called for each ent returned by GetNewInstance to indicate tbe
	// result of applying the privacy rules to each ent.
	// Loaders should keep track of this and not GetNewInstance() so as
	// to not have privacy violations in returning non-privacy backed code
	// back to clients out of the ent framework
	// @param id string
	// @param ent DBObject (non-nil) if visible to the viewer
	// @param err error error loading given id e.g. user was blocked or just generic privacy error
	SetPrivacyResult(string, DBObject, error)
}

PrivacyBackedLoader is used when we want to apply privacy rules APIs that take this exxpect each instance of the ent returned by GetNewInstance() to be an Entity with the Viewer set to the same viewer passed to the ent API Done this way to have strong typing everywhere with no reflection. Automatically handled by the code generated by the framework so should only be annoying for very custom implementations

type PrivacyError

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

PrivacyError is the error type returned when an ent is not visible due to privacy reasons

func (*PrivacyError) Error

func (err *PrivacyError) Error() string

Error returns a formatted string that indicates why the ent is not visible

type PrivacyPolicy

type PrivacyPolicy interface {
	Rules() []PrivacyPolicyRule
}

PrivacyPolicy defines the set of Privacy rules that need to be implemented by this ent to end up with a decision on if this ent is visible to the viewer

type PrivacyPolicyRule

type PrivacyPolicyRule interface {
	// Eval is the method called to evaluate the visibility of the ent
	Eval(v viewer.ViewerContext, ent Entity) PrivacyResult
}

PrivacyPolicyRule is an independent PrivacyRule that evaluates an ent and determines if it's visible or not

type PrivacyResult

type PrivacyResult interface {
	Result() privacyResult
}

PrivacyResult is what's returned by privacy methods to indicate what should be returned to the client of ent callers

func Allow

func Allow() PrivacyResult

Allow is the method that should be returned by privacy rule methods indicating that the privacy rule is enough to make the ent visible to the viewer

func Deny

func Deny() PrivacyResult

Deny is the method that should be returned by privacy rule methods indicating that the privacy rule is enough to make the ent NOT visible to the viewer

func Skip

func Skip() PrivacyResult

Skip is the method that should be returned by privacy rule methods indicating that the privacy rule does not have enough info to make the ent visible to the viewer. It's punting to the next privacy rule

type Timestamps

type Timestamps struct {
	CreatedAt time.Time `db:"created_at"`
	UpdatedAt time.Time `db:"updated_at"`
}

Timestamps adds 2 time fields to each ent. Right now, it's gotten from ent.Node which is automatically added 2 each ent. Eventually, there'll be a corresponding TimestampsConfig or TimestampsPattern which adds this and there could be ents which aren't Nodes which have these (e.g. AssocEdgeData)

type WriteOperation

type WriteOperation string

WriteOperation indicates if we're creating, editing or deleting an ent

const (
	// InsertOperation means we're creating a new ent
	InsertOperation WriteOperation = "insert"
	// EditOperation means we're editing an existing ent
	EditOperation WriteOperation = "edit"
	// DeleteOperation means we're deleting an ent
	DeleteOperation WriteOperation = "delete"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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