graphify

package module
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: May 1, 2025 License: Unlicense Imports: 55 Imported by: 1

README

graphify

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	OTPRequestedTopic = Topic("auth.otp.requested")
)

Functions

func AdminKeyFromContext added in v0.6.7

func AdminKeyFromContext(ctx context.Context) (value string, found bool)

func BaseType added in v0.8.0

func BaseType(elem any) reflect.Type

func Collection added in v0.0.19

func Collection[T any]() string

Collection returns the name of the collection for the given element

func ContextWithAdminKey added in v0.6.7

func ContextWithAdminKey(parent context.Context, key string) context.Context

func ContextWithSession added in v0.8.0

func ContextWithSession(parent context.Context, session *authv1.Session) context.Context

func DoubleQuote added in v0.7.11

func DoubleQuote(s string) string

DoubleQuote ...

func Enforce added in v0.8.0

func Enforce[T proto.Message](ctx context.Context, enforcer casbin.IEnforcer, subjectFn SubjectFn[T], enforceFn EnforceFn[T]) (subject T, authorized bool)

Enforce is a helper function to enforce a policy

func Enforcer added in v0.8.0

func Enforcer(m model.Model, p persist.Adapter) (casbin.IEnforcer, error)

func ExposeNodes added in v0.4.3

func ExposeNodes(nodes ...any) exposedNodes

ExposeNodes ...

func ID added in v0.8.0

func ID[T any](key string) string

NODE HELPERS

func JSONName added in v0.7.11

func JSONName(f reflect.StructField) string

JSONName returns the name of the field in the JSON tag

func Map added in v0.4.39

func Map[T any](size int, fn func(int) T) (result []T)

Map converts a slice of values to a slice of values using a function

func Must added in v0.7.1

func Must[T any](v T, err error) T

Must panics if an error is returned

func Mutation added in v0.1.0

func Mutation[Arg, Out proto.Message](fn func(context.Context, Arg) (Out, error)) mutation

Mutation ...

func NewConnection

func NewConnection(ctx context.Context, conf ConnectionConfig) *connection

NewConnection ...

func NewDbFileStorage added in v0.4.33

func NewDbFileStorage(access Access) *dbFileStorage

NewDbFileStorage ...

func NewFilesystemStorage added in v0.0.6

func NewFilesystemStorage(params FilesystemStorageConfig) *filesystemStorage

NewFilesystemStorage ...

func NewGraph

func NewGraph() *graph

NewGraph ...

func NewObserver

func NewObserver[T comparable]() *observer[T]

NewObserver ...

func ProtoMarshal added in v0.7.1

func ProtoMarshal(v any, out proto.Message) error

func ProvideAs added in v0.8.0

func ProvideAs[T any](val any) fx.Option

ProvideAs provides a value annotated with a specific type

func Pure added in v0.4.6

func Pure[T any](v T) (result T)

Pure converts a value to a pure JSON value

func Query added in v0.1.0

func Query[Arg, Out proto.Message](fn func(context.Context, Arg) (Out, error)) query

Query ...

func QueryJoin added in v0.4.43

func QueryJoin(parts ...string) string

QueryJoin joins a slice of strings with a space

func Quote added in v0.4.43

func Quote(s string) string

Quote ...

func RegisterAdmin added in v0.4.36

func RegisterAdmin(ctx context.Context, access Access, req *dashboardv1.CreateAccountRequest) (err error)

func ResourceID added in v0.8.0

func ResourceID(resource, key string) string

func Select added in v0.8.0

func Select(v string) selector

func SessionFromContext added in v0.8.0

func SessionFromContext(ctx context.Context) (session *authv1.Session, found bool)

func Should added in v0.8.0

func Should[T any](v T, _ error) T

Should returns a value and an ignores the error

func Subject added in v0.8.0

func Subject[T proto.Message](ctx context.Context, subject SubjectFn[T]) (val T, err error)

Subject returns a value and an error from a SubjectFn

func ToMap added in v0.4.6

func ToMap(v any) (result map[string]any)

ToMap converts a value to a map[string]any

func Vars added in v0.4.3

func Vars() bindVars

Vars ...

func VarsFor added in v0.8.0

func VarsFor[T proto.Message](elem T) bindVars

Types

type Access added in v0.4.43

type Access interface {
	// AutoMigrate ...
	AutoMigrate(ctx context.Context, graph Graph) error

	// Collection ...
	Collection(ctx context.Context, elem any, callbacks ...CollectionCallback) (driver.Collection, error)

	// Query returns a list of elements
	Query(ctx context.Context, query string, bindVars map[string]any, out any) error

	// Fetch returns a single element
	Fetch(ctx context.Context, query string, bindVars map[string]any, out any) error

	// List ...
	List(ctx context.Context, bindVars BindVars, out any) (int64, error)

	// Find ...
	Find(ctx context.Context, bindVars BindVars, out any) error

	// Create ...
	Create(ctx context.Context, val any) ([]string, error)

	// Update ...
	Update(ctx context.Context, key string, item any) error

	// Replace ...
	Replace(ctx context.Context, key string, item any) error

	// Delete ...
	Delete(ctx context.Context, item any) error

	// Relations ...
	Relations(ctx context.Context, id string, bindVars BindVars, direction Direction, out any) (int64, error)
}

Access ...

type AdminHandler added in v0.4.3

AdminHandler ...

func NewAdminHandler added in v0.4.3

func NewAdminHandler(ctx context.Context, config AdminHandlerConfig, params AdminHandlerParams) *AdminHandler

NewAdminHandler ...

func (*AdminHandler) CreateAccount added in v0.4.6

func (*AdminHandler) CreateResource added in v0.4.6

func (*AdminHandler) DeleteResource added in v0.4.6

func (*AdminHandler) FilesDownloadHandler added in v0.4.6

func (h *AdminHandler) FilesDownloadHandler(w http.ResponseWriter, r *http.Request, pathParams map[string]string)

func (*AdminHandler) FilesUploadHandler added in v0.4.6

func (h *AdminHandler) FilesUploadHandler(w http.ResponseWriter, r *http.Request, _ map[string]string)

func (*AdminHandler) GetAccount added in v0.4.6

func (*AdminHandler) GetResource added in v0.4.6

func (*AdminHandler) GetResourceRelation added in v0.4.6

func (*AdminHandler) GetSchema added in v0.4.6

func (*AdminHandler) Handler added in v0.4.3

func (h *AdminHandler) Handler(ctx context.Context) http.Handler

func (*AdminHandler) ListResources added in v0.4.6

func (*AdminHandler) Login added in v0.4.6

func (*AdminHandler) UpdateResource added in v0.4.6

type AdminHandlerConfig added in v0.4.3

type AdminHandlerConfig struct {
	Secret []byte
}

AdminHandlerConfig ...

type AdminHandlerParams added in v0.4.3

type AdminHandlerParams struct {
	fx.In

	Access   Access
	Graph    Graph
	Storage  FileStorage
	Observer Observer[Topic]
}

AdminHandlerParams ...

type ApplicationConfig added in v0.0.9

type ApplicationConfig struct {
	// Name ...
	Name string `json:"name"`
	// Domain ...
	Domain string `json:"domain"`
	Logo string `json:"logo"`
}

ApplicationConfig ...

type ArangoAccess added in v0.4.3

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

func NewArangoAccess added in v0.4.3

func NewArangoAccess(conn Connection, observer Observer[Topic]) *ArangoAccess

func (*ArangoAccess) AutoMigrate added in v0.4.3

func (e *ArangoAccess) AutoMigrate(ctx context.Context, graph Graph) error

AutoMigrate ...

func (*ArangoAccess) Collection added in v0.4.3

func (e *ArangoAccess) Collection(ctx context.Context, elem any, callbacks ...CollectionCallback) (col driver.Collection, err error)

Collection ...

func (*ArangoAccess) Create added in v0.4.3

func (e *ArangoAccess) Create(ctx context.Context, val any) ([]string, error)

Create ...

func (*ArangoAccess) Delete added in v0.4.3

func (e *ArangoAccess) Delete(ctx context.Context, item any) error

Delete ...

func (*ArangoAccess) Fetch added in v0.4.43

func (e *ArangoAccess) Fetch(ctx context.Context, query string, bindVars map[string]any, out any) error

Fetch ...

func (*ArangoAccess) Find added in v0.4.3

func (e *ArangoAccess) Find(ctx context.Context, bindVars BindVars, out any) error

Find ...

func (*ArangoAccess) List added in v0.4.3

func (e *ArangoAccess) List(ctx context.Context, bindVars BindVars, out any) (int64, error)

List ...

func (*ArangoAccess) Query added in v0.4.43

func (e *ArangoAccess) Query(ctx context.Context, query string, bindVars map[string]any, out any) error

Query ...

func (*ArangoAccess) Relations added in v0.4.3

func (e *ArangoAccess) Relations(ctx context.Context, id string, bindVars BindVars, direction Direction, out any) (int64, error)

Relations ...

func (*ArangoAccess) Replace added in v0.4.3

func (e *ArangoAccess) Replace(ctx context.Context, key string, item any) error

Replace ...

func (*ArangoAccess) Update added in v0.4.3

func (e *ArangoAccess) Update(ctx context.Context, key string, item any) error

Update ...

type AuthHandler added in v0.8.0

type AuthHandler struct {
	authv1.UnsafeAuthenticationServiceServer
	// contains filtered or unexported fields
}

func NewAuthHandler added in v0.8.0

func NewAuthHandler(ctx context.Context, config AuthHandlerConfig, params AuthHandlerParams) *AuthHandler

func (*AuthHandler) Handler added in v0.8.0

func (h *AuthHandler) Handler(ctx context.Context) http.Handler

func (*AuthHandler) Middleware added in v0.8.0

func (h *AuthHandler) Middleware(path *regexp.Regexp, methods ...string) mux.MiddlewareFunc

func (*AuthHandler) ParseClaims added in v0.8.0

func (h *AuthHandler) ParseClaims(tokenString string) (*jwt.RegisteredClaims, error)

func (*AuthHandler) RefreshToken added in v0.8.0

func (h *AuthHandler) RefreshToken(ctx context.Context, req *emptypb.Empty) (*authv1.RefreshTokenResponse, error)

func (*AuthHandler) RequestOTP added in v0.8.0

func (h *AuthHandler) RequestOTP(ctx context.Context, req *authv1.RequestOTPRequest) (*emptypb.Empty, error)

func (*AuthHandler) ValidateSSOToken added in v0.8.0

func (h *AuthHandler) ValidateSSOToken(ctx context.Context, req *emptypb.Empty) (*authv1.ValidateSSOTokenResponse, error)

func (*AuthHandler) VerifyOTP added in v0.8.0

type AuthHandlerConfig added in v0.8.0

type AuthHandlerConfig struct {
	Issuer          string
	Secret          []byte
	TokenTTL        time.Duration
	RefreshTokenTTL time.Duration
}

type AuthHandlerParams added in v0.8.0

type AuthHandlerParams struct {
	fx.In

	Access   Access
	Observer Observer[Topic]
}

type BindVars added in v0.8.0

type BindVars interface {
	// Limit ...
	Limit() string

	// Filters ...
	Filters() string

	// Values ...
	Values() map[string]interface{}
}

BindVars ...

type CasbinAdapter added in v0.8.0

type CasbinAdapter[T proto.Message] struct {
	// contains filtered or unexported fields
}

CasbinAdapter ...

func NewCasbinAdapter added in v0.8.0

func NewCasbinAdapter[T proto.Message](ctx context.Context, access Access) *CasbinAdapter[T]

NewCasbinAdapter ...

func (*CasbinAdapter[T]) AddPolicy added in v0.8.0

func (a *CasbinAdapter[T]) AddPolicy(sec string, ptype string, rule []string) error

AddPolicy implements persist.Adapter.

func (*CasbinAdapter[T]) Fields added in v0.8.0

func (a *CasbinAdapter[T]) Fields() (result []protoreflect.FieldDescriptor)

func (*CasbinAdapter[T]) LoadPolicy added in v0.8.0

func (a *CasbinAdapter[T]) LoadPolicy(model model.Model) error

LoadPolicy implements persist.Adapter.

func (*CasbinAdapter[T]) Marshal added in v0.8.0

func (a *CasbinAdapter[T]) Marshal(el T) (sec string, ptype string, rule []string)

func (*CasbinAdapter[T]) RemoveFilteredPolicy added in v0.8.0

func (a *CasbinAdapter[T]) RemoveFilteredPolicy(sec string, ptype string, fieldIndex int, fieldValues ...string) error

RemoveFilteredPolicy implements persist.Adapter.

func (*CasbinAdapter[T]) RemovePolicy added in v0.8.0

func (a *CasbinAdapter[T]) RemovePolicy(sec string, ptype string, rule []string) error

RemovePolicy implements persist.Adapter.

func (*CasbinAdapter[T]) SavePolicy added in v0.8.0

func (a *CasbinAdapter[T]) SavePolicy(model model.Model) error

SavePolicy implements persist.Adapter.

func (*CasbinAdapter[T]) Unmarshal added in v0.8.0

func (a *CasbinAdapter[T]) Unmarshal(sec string, ptype string, rule []string) (out T, err error)

type CollectionCallback added in v0.4.3

type CollectionCallback func(context.Context, driver.Collection)

CollectionCallback ...

type Connection added in v0.4.43

type Connection interface {
	// Database ...
	Database(ctx context.Context) (driver.Database, error)
	// Collection ...
	Collection(ctx context.Context, elem any) (driver.Collection, error)
	// Reflect ...
	Reflect(ctx context.Context, elem reflect.Type) (driver.Collection, error)
}

Connection ...

type ConnectionConfig added in v0.4.3

type ConnectionConfig struct {
	// DBName ...
	DBName string
	// UserName ...
	UserName string
	// Password ...
	Password string
	// Connection ...
	Connection http.ConnectionConfig
}

ConnectionConfig ...

type Direction added in v0.0.12

type Direction string
const (
	DirectionInbound  Direction = "INBOUND"
	DirectionOutbound Direction = "OUTBOUND"
	DirectionAny      Direction = "ANY"
)

func (Direction) String added in v0.8.0

func (d Direction) String() string

type EnforceFn added in v0.8.0

type EnforceFn[T proto.Message] func(subject T) ([]interface{}, error)

EnforceFn is a function that returns a slice of any and an error

type Event

type Event[T comparable] struct {
	// Topic ...
	Topic T
	// Payload ...
	Payload protoreflect.ProtoMessage
	// Timestamp ...
	Timestamp time.Time
}

Event ...

type FileStorage added in v0.4.43

type FileStorage interface {
	// StoreFile ...
	StoreFile(name string, file []byte) (err error)

	// StoreByHash ...
	StoreByHash(file []byte) (hash string, err error)

	// ReadFile ...
	ReadFile(name string) (fileContent []byte, errr error)

	// MaxMemory ...
	MaxMemory() int
}

FileStorage ...

type FilesystemStorageConfig added in v0.4.3

type FilesystemStorageConfig struct {
	// BasePath ...
	BasePath string
	// MaxMemory ...
	MaxMemory int
}

FilesystemStorageConfig ...

type Graph added in v0.4.3

type Graph interface {
	// Node ...
	Node(node any)
	// Edge ...
	Edge(from, to, edge any)

	// Nodes ...
	Nodes() []reflect.Type
	// Edges ...
	Edges() []reflect.Type
	// Relation ...
	Relation(edge reflect.Type) *Relation

	// CollectionFor ...
	CollectionFor(elem reflect.Type) string
	// TypeOf ...
	TypeOf(name string) reflect.Type
}

Graph ...

type GraphqlHandler added in v0.4.3

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

GraphqlHandler ...

func NewGraphqlHandler added in v0.4.3

func NewGraphqlHandler(access Access, graph Graph) *GraphqlHandler

NewGraphqlHandler ...

func (*GraphqlHandler) Handle added in v0.4.8

func (e *GraphqlHandler) Handle(ctx context.Context, handlers ...interface{}) *handler.Handler

Handle ...

type Observer

type Observer[T comparable] interface {
	// Subscribe ...
	Subscribe(t T, p Processor[T]) SourceID
	// Unsubscribe ...
	Unsubscribe(s SourceID)
	// Emit ...
	Emit(e *Event[T]) error
}

Observer ...

type Processor

type Processor[T comparable] func(e *Event[T]) error

Processor ...

type Relation added in v0.4.3

type Relation struct {
	From reflect.Type `json:"_from"`
	To   reflect.Type `json:"_to"`
}

Relation

type SourceID

type SourceID int64

SourceID ...

type SubjectFn added in v0.8.0

type SubjectFn[T proto.Message] func(ctx context.Context, session *domainv1.Session) (T, error)

SubjectFn is a function that returns a value and an error

type Topic

type Topic string
var (
	CreatedTopic  Topic = "created"
	UpdatedTopic  Topic = "updated"
	ReplacedTopic Topic = "replaced"
	DeletedTopic  Topic = "deleted"
)
var (
	AdminCreatedTopic  Topic = "admin.created"
	AdminReplacedTopic Topic = "admin.replaced"
	AdminDeletedTopic  Topic = "admin.deleted"
)

func (Topic) For added in v0.0.2

func (t Topic) For(elem any) Topic

Jump to

Keyboard shortcuts

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