gruff

package
v0.0.0-...-83255ff Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const CHANGE_TYPE_CLONE_CLAIM int = 21
View Source
const CHANGE_TYPE_CREATED_ARGUMENT int = 2
View Source
const CHANGE_TYPE_CREATED_CLAIM int = 1
View Source
const CHANGE_TYPE_CREATED_CLAIM_AND_ARGUMENT int = 3
View Source
const CHANGE_TYPE_MERGE_ARGUMENTS int = 32
View Source
const CHANGE_TYPE_MERGE_CLAIMS int = 31
View Source
const CHANGE_TYPE_MOVED_ARGUMENT int = 11
View Source
const DEFAULT_ARGUMENT_SCORE float32 = 1.00
View Source
const DEFAULT_CLAIM_SCORE float32 = 0.50
View Source
const ERROR_CODE_BUSINESS_ERROR int = 400
View Source
const ERROR_CODE_NOT_FOUND int = 404
View Source
const ERROR_CODE_PERMISSION_ERROR int = 403
View Source
const ERROR_CODE_SERVER_ERROR int = 500
View Source
const ERROR_CODE_UNAUTHORIZED_ERROR int = 401
View Source
const ERROR_CODE_WARNING int = 300
View Source
const ERROR_SUBCODE_CREDENTIALS_INVALID int = -2009
View Source
const ERROR_SUBCODE_EMAIL_FORMAT int = -2006
View Source
const ERROR_SUBCODE_EMAIL_TAKEN int = -2005
View Source
const ERROR_SUBCODE_PASSWORD_FORMAT int = -2008
View Source
const ERROR_SUBCODE_PASSWORD_LENGTH int = -2007
View Source
const ERROR_SUBCODE_UNDEFINED int = -1999
View Source
const ERROR_SUBCODE_UNDEFINED_IGNORE int = -1000
View Source
const ERROR_SUBCODE_USERNAME_FORMAT int = -2004
View Source
const ERROR_SUBCODE_USERNAME_LENGTH int = -2003
View Source
const ERROR_SUBCODE_USERNAME_TAKEN int = -2002
View Source
const JWT_ISS = "gruff"
View Source
const NOTIFICATION_TYPE_MOVED int = 1
View Source
const NOTIFICATION_TYPE_NEW_ARGUMENT int = 3
View Source
const NOTIFICATION_TYPE_PARENT_MOVED int = 2
View Source
const OBJECT_TYPE_ARGUMENT int = 2
View Source
const OBJECT_TYPE_CLAIM int = 1
View Source
const PREMISE_RULE_ALL int = 1
View Source
const PREMISE_RULE_ANY int = 2
View Source
const PREMISE_RULE_ANY_TWO int = 3
View Source
const PREMISE_RULE_NONE int = 0

* A Claim is a proposed statement of fact * * Claims are described in detail in the Canonical Debate White Paper: https://github.com/canonical-debate-lab/paper#311_Claim * * According to David Zarefsky (https://www.thegreatcoursesplus.com/argumentation/argument-analysis-and-diagramming) there are 4 types: * - Fact: Al Gore received more popular votes than George Bush in the 2000 election * - Definition: Capital execution is murder * - Value: Environmental protection is more important than economic growth * - Policy: Congress should pass the president's budget * * Complex Claims: * - Series: Because of X, Y happened, which caused Z --> Not modeled in Gruff * - Convergent: Airline travel is becoming more unpleasant because of X, Y, Z, P, D, and Q --> Supported by standard Gruff structure * - Parallel: Same as convergent, except that any one argument is enough --> Supported by standard Gruff structure * * Complex Claims in the Canonical Debate are known as Multi-Premise Claims: https://github.com/canonical-debate-lab/paper#3115_Multipremise_Claims * They are currently unsupported, but soon will be. *

Variables

View Source
var DEFAULT_QUERY_PARAMETERS = ArangoQueryParameters{
	Sort:   support.StringPtr("obj.start DESC"),
	Offset: support.IntPtr(0),
	Limit:  support.IntPtr(20),
	Return: support.StringPtr("obj"),
}

QUERY PARAMETERS By convention, simple queries will use "obj" as the collection item reference in order to simplify the basic use cases

Functions

func CloseCursor

func CloseCursor(cursor arango.Cursor)

func DefaultListQuery

func DefaultListQuery(obj ArangoObject, params ArangoQueryParameters) string

func DefaultListQueryForUser

func DefaultListQueryForUser(obj ArangoObject, params ArangoQueryParameters) string

func FindArgumentMovedNotifications

func FindArgumentMovedNotifications(db *gorm.DB) *gorm.DB

func FindContext

func FindContext(ctx *ServerContext, contextArangoId string) (Context, Error)

func FindContextEdge

func FindContextEdge(ctx *ServerContext, contextArangoKey, claimArangoKey string) (ContextEdge, Error)

func FindParentArgumentMovedNotifications

func FindParentArgumentMovedNotifications(db *gorm.DB) *gorm.DB

func GetVersionedModel

func GetVersionedModel(item interface{}) (VersionedModel, Error)

func InitTestDB

func InitTestDB() (arango.Client, arango.Database)

func IsArangoObject

func IsArangoObject(t reflect.Type) bool

TODO: Test

func IsEdge

func IsEdge(t reflect.Type) bool

func IsEmptyValue

func IsEmptyValue(v reflect.Value) bool

TODO: I think there's a reflect.Zero(Type) method that should simplify this. First, make sure tests are in place.

func IsLoader

func IsLoader(t reflect.Type) bool

func IsRestrictor

func IsRestrictor(t reflect.Type) bool

func IsScorer

func IsScorer(t reflect.Type) bool

func IsValidator

func IsValidator(t reflect.Type) bool

func IsVersionedModel

func IsVersionedModel(t reflect.Type) bool

func IsVersioner

func IsVersioner(t reflect.Type) bool

func IssueJWTTokenForEmail

func IssueJWTTokenForEmail(uid uint, email string, exp time.Time) (string, error)

func IssueJWToken

func IssueJWToken(uid string, roles []string, exp time.Time) (string, error)

func JWTTokenExpirationDate

func JWTTokenExpirationDate() time.Time

func JsonToMap

func JsonToMap(jsonStr string) map[string]interface{}

func JsonToMapArray

func JsonToMapArray(jsonStr string) []map[string]interface{}

func JsonToModel

func JsonToModel(jsonStr string, item interface{}) error

func KeyField

func KeyField(t reflect.Type) (field *reflect.StructField, dbFieldName string)

func ModelToJson

func ModelToJson(model interface{}) string

func ModelToJsonMap

func ModelToJsonMap(modl interface{}) map[string]interface{}

func OpenArangoConnection

func OpenArangoConnection() (arango.Client, error)

func OpenArangoDatabase

func OpenArangoDatabase(client arango.Client) (arango.Database, error)

func OpenTestConnection

func OpenTestConnection() (arango.Client, error)

func OrderByBestArgument

func OrderByBestArgument(db *gorm.DB) *gorm.DB

func ParentCallerInfo

func ParentCallerInfo() string

func SearchContext

func SearchContext(ctx *ServerContext, contextText string) ([]Context, Error)

func SearchContexts

func SearchContexts(ctx *ServerContext, term string) ([]Context, Error)

func SetUserID

func SetUserID(item interface{}, id string) error

func TypeHasUserField

func TypeHasUserField(t reflect.Type) bool

func UserIDField

func UserIDField(t reflect.Type) (field *reflect.StructField, dbFieldName string)

func VerifyJWTToken

func VerifyJWTToken(tokenString, secretKey string) (*jwt.Token, error)

Types

type ArangoContext

type ArangoContext struct {
	Context     context.Context
	DB          arango.Database
	Collections map[string]arango.Collection
}

func (ArangoContext) Collection

func (ctx ArangoContext) Collection(name string) (arango.Collection, Error)

func (ArangoContext) CollectionFor

func (ctx ArangoContext) CollectionFor(item ArangoObject) (arango.Collection, Error)

func (ArangoContext) Rollback

func (ctx ArangoContext) Rollback() Error

type ArangoObject

type ArangoObject interface {
	CollectionName() string
	ArangoKey() string
	ArangoID() string
	DefaultQueryParameters() ArangoQueryParameters
	Create(*ServerContext) Error
	Update(*ServerContext, Updates) Error
	Delete(*ServerContext) Error
	PrepareForCreate(*ServerContext)
	PrepareForDelete(*ServerContext)
}

type ArangoQueryParameters

type ArangoQueryParameters struct {
	Sort   *string
	Offset *int
	Limit  *int
	Return *string
}

func (ArangoQueryParameters) Apply

func (aqp ArangoQueryParameters) Apply(query string) string

func (ArangoQueryParameters) Merge

type Argument

type Argument struct {
	VersionedModel
	TargetClaimID    *string    `json:"targetClaimId,omitempty"`
	TargetClaim      *Claim     `json:"targetClaim,omitempty" transient:"true"`
	TargetArgumentID *string    `json:"targetArgId,omitempty"`
	TargetArgument   *Argument  `json:"targetArg,omitempty" transient:"true"`
	ClaimID          string     `json:"claimId"`
	Claim            *Claim     `json:"claim,omitempty" transient:"true"`
	Title            string     `json:"title" valid:"length(3|1000)"`
	Negation         string     `json:"negation"`
	Question         string     `json:"question"`
	Description      string     `json:"desc" valid:"length(3|4000)"`
	Note             string     `json:"note"`
	Pro              bool       `json:"pro"`
	Relevance        float32    `json:"relevance"`
	Str              float32    `json:"strength"`
	ProArgs          []Argument `json:"proargs" transient:"true"`
	ConArgs          []Argument `json:"conargs" transient:"true"`
}

func (Argument) AddArgument

func (a Argument) AddArgument(ctx *ServerContext, arg Argument) Error

func (Argument) ArangoID

func (a Argument) ArangoID() string

func (Argument) ArangoKey

func (a Argument) ArangoKey() string

func (Argument) Arguments

func (a Argument) Arguments(ctx *ServerContext) ([]Argument, Error)

func (Argument) BaseClaimEdge

func (a Argument) BaseClaimEdge(ctx *ServerContext) (BaseClaimEdge, Error)

func (Argument) CollectionName

func (a Argument) CollectionName() string

func (*Argument) Create

func (a *Argument) Create(ctx *ServerContext) Error

func (Argument) DefaultQueryParameters

func (a Argument) DefaultQueryParameters() ArangoQueryParameters

func (*Argument) Delete

func (a *Argument) Delete(ctx *ServerContext) Error

func (Argument) Inference

func (a Argument) Inference(ctx *ServerContext) (Inference, Error)

func (Argument) Inferences

func (a Argument) Inferences(ctx *ServerContext) ([]Inference, Error)

func (*Argument) Load

func (a *Argument) Load(ctx *ServerContext) Error

func (*Argument) LoadFull

func (a *Argument) LoadFull(ctx *ServerContext) Error

func (*Argument) LoadTarget

func (a *Argument) LoadTarget(ctx *ServerContext) Error

func (*Argument) MoveTo

func (a *Argument) MoveTo(ctx *ServerContext, target ArangoObject, pro bool) Error

TODO: Test

func (*Argument) Score

func (a *Argument) Score(ctx *ServerContext) (float32, Error)

func (*Argument) Strength

func (a *Argument) Strength(ctx *ServerContext) (float32, Error)

func (*Argument) Update

func (a *Argument) Update(ctx *ServerContext, updates Updates) Error

func (*Argument) UpdateScore

func (a *Argument) UpdateScore(ctx *ServerContext) Error

func (Argument) UserCanCreate

func (a Argument) UserCanCreate(ctx *ServerContext) (bool, Error)

func (Argument) UserCanDelete

func (a Argument) UserCanDelete(ctx *ServerContext) (bool, Error)

func (Argument) UserCanUpdate

func (a Argument) UserCanUpdate(ctx *ServerContext, updates Updates) (bool, Error)

func (Argument) UserCanView

func (a Argument) UserCanView(ctx *ServerContext) (bool, Error)

Restrictor TODO: Test TODO: Call in CRUD and other methods

func (Argument) UserScores

func (a Argument) UserScores(ctx *ServerContext) ([]UserScore, Error)

func (Argument) ValidateField

func (a Argument) ValidateField(f string) Error

func (Argument) ValidateForCreate

func (a Argument) ValidateForCreate() Error

func (Argument) ValidateForDelete

func (a Argument) ValidateForDelete() Error

func (Argument) ValidateForUpdate

func (a Argument) ValidateForUpdate(updates Updates) Error

func (Argument) ValidateIDs

func (a Argument) ValidateIDs() Error

type ArgumentOpinion

type ArgumentOpinion struct {
	Model
	UserID     uint64    `json:"userId"`
	User       *User     `json:"user,omitempty"`
	ArgumentID uuid.UUID `json:"argumentId" sql:"type:uuid"`
	Argument   *Argument `json:"argument,omitempty"`
	Strength   float64   `json:"strength"`
}

func (ArgumentOpinion) ValidateField

func (ao ArgumentOpinion) ValidateField(f string) Error

func (ArgumentOpinion) ValidateForCreate

func (ao ArgumentOpinion) ValidateForCreate() Error

func (ArgumentOpinion) ValidateForUpdate

func (ao ArgumentOpinion) ValidateForUpdate() Error

type BaseClaimEdge

type BaseClaimEdge struct {
	Edge
}

BaseClaim is an edge pointing from an Argument to the Claim on which it is based (the true/false part of the Argument)

func (BaseClaimEdge) ArangoID

func (bc BaseClaimEdge) ArangoID() string

func (BaseClaimEdge) ArangoKey

func (bc BaseClaimEdge) ArangoKey() string

func (BaseClaimEdge) CollectionName

func (bc BaseClaimEdge) CollectionName() string

func (*BaseClaimEdge) Create

func (bc *BaseClaimEdge) Create(ctx *ServerContext) Error

func (BaseClaimEdge) DefaultQueryParameters

func (bc BaseClaimEdge) DefaultQueryParameters() ArangoQueryParameters

func (*BaseClaimEdge) Delete

func (bc *BaseClaimEdge) Delete(ctx *ServerContext) Error

func (*BaseClaimEdge) Update

func (bc *BaseClaimEdge) Update(ctx *ServerContext, updates Updates) Error

type BindVars

type BindVars map[string]interface{}

type ChangeLog

type ChangeLog struct {
	Model
	UserID     uint64    `json:"userId" sql:"not null"`
	User       *User     `json:"user,omitempty"`
	Type       int       `json:"type" sql:"not null"`
	ArgumentID *string   `json:"argumentId,omitempty" sql:"type:uuid"`
	Argument   *Argument `json:"argument,omitempty"`
	ClaimID    *string   `json:"claimId,omitempty" sql:"type:uuid"`
	Claim      Claim     `json:"claim"`
	OldClaimID *string   `json:"oldClaimId,omitempty" sql:"type:uuid"`
	OldClaim   *Claim    `json:"oldClaim,omitempty"`
	OldArgID   *string   `json:"oldArgId,omitempty" sql:"type:uuid"`
	OldArg     *Argument `json:"oldArg,omitempty"`
	NewClaimID *string   `json:"newClaimId,omitempty" sql:"type:uuid"`
	NewClaim   *Claim    `json:"newClaim,omitempty"`
	NewArgID   *string   `json:"newArgId,omitempty" sql:"type:uuid"`
	NewArg     *Argument `json:"newArg,omitempty"`
	OldArgType *int      `json:"oldArgType,omitempty"`
	NewArgType *int      `json:"newArgType,omitempty"`
}

Types of Changes, and fields used: - Created Claim: ClaimID - Created Argument: ArgumentID, NewArgType, NewClaimID or NewArgID (parent) - Created Claim and Argument: ArgumentID, NewArgType, NewClaimID or NewArgID (parent) - Moved Argument: ArgumentID, OldClaimID or OldArgID, NewClaimID or NewArgID (parent), OldArgType, NewArgType - Clone Claim:

  • One claim stays
  • New claim created, with same values, context, title and description (must be changed before saving)
  • Arguments stay with main claim --> Need Change Type add/remove values and contexts --> ClaimID, NewClaimID --> What about opinions?? I guess it would make a copy --> Would there be arguments between old and new claim(s)? ------- E.g. Fidel Castro is nice, and ended Apartheid --> Fidel Castro is nice, Fidel Castro ended Apartheid

- Merge Claims:

  • One claim becomes defunct
  • Must have "compatible" values/context (TBD)
  • All arguments attach to "winning" claim
  • Title, description stick with "winning" claim
  • All arguments with "losing" claim as base reattach to "winning" claim
  • Do we need a change log for each of these? Probably...
  • What about opinions? Should also merge...

func (ChangeLog) ValidateField

func (cl ChangeLog) ValidateField(f string) Error

func (ChangeLog) ValidateForCreate

func (cl ChangeLog) ValidateForCreate() Error

func (ChangeLog) ValidateForUpdate

func (cl ChangeLog) ValidateForUpdate() Error

type Claim

type Claim struct {
	VersionedModel
	Title         string     `json:"title" valid:"length(3|1000)"`
	Negation      string     `json:"negation"`
	Question      string     `json:"question"`
	Description   string     `json:"desc" valid:"length(3|4000)"`
	Note          string     `json:"note"`
	Image         string     `json:"img,omitempty"`
	MultiPremise  bool       `json:"mp"`
	PremiseRule   int        `json:"mprule"`
	Truth         float32    `json:"truth"` // Average score from direct opinions
	PremiseClaims []Claim    `json:"premises,omitempty" transient:"true"`
	ProArgs       []Argument `json:"proargs" transient:"true"`
	ConArgs       []Argument `json:"conargs" transient:"true"`
	Links         []Link     `json:"links,omitempty" transient:"true"`
	ContextElems  []Context  `json:"contexts" transient:"true"`
}

func (*Claim) AddContext

func (c *Claim) AddContext(ctx *ServerContext, context Context) Error

Contexts

func (*Claim) AddPremise

func (c *Claim) AddPremise(ctx *ServerContext, premise *Claim) Error

func (Claim) ArangoID

func (c Claim) ArangoID() string

func (Claim) ArangoKey

func (c Claim) ArangoKey() string

func (Claim) Arguments

func (c Claim) Arguments(ctx *ServerContext) ([]Argument, Error)

func (Claim) ArgumentsBasedOnThisClaim

func (c Claim) ArgumentsBasedOnThisClaim(ctx *ServerContext) ([]Argument, Error)

func (Claim) BaseClaimEdges

func (c Claim) BaseClaimEdges(ctx *ServerContext) ([]BaseClaimEdge, Error)

func (Claim) CollectionName

func (c Claim) CollectionName() string

func (Claim) ContextEdges

func (c Claim) ContextEdges(ctx *ServerContext) ([]ContextEdge, Error)

func (Claim) Contexts

func (c Claim) Contexts(ctx *ServerContext) ([]Context, Error)

func (*Claim) ConvertToMultiPremise

func (c *Claim) ConvertToMultiPremise(ctx *ServerContext) Error

TODO: Test

func (*Claim) Create

func (c *Claim) Create(ctx *ServerContext) Error

func (Claim) DefaultQueryParameters

func (c Claim) DefaultQueryParameters() ArangoQueryParameters

func (*Claim) Delete

func (c *Claim) Delete(ctx *ServerContext) Error

func (Claim) EdgesToThisPremise

func (c Claim) EdgesToThisPremise(ctx *ServerContext) ([]PremiseEdge, Error)

func (Claim) HasCycle

func (c Claim) HasCycle(ctx *ServerContext) (bool, Error)

TODO: THis could use the named graph debate_map

func (Claim) HasPremise

func (c Claim) HasPremise(ctx *ServerContext, premiseArangoKey string) (bool, Error)

func (Claim) Inferences

func (c Claim) Inferences(ctx *ServerContext) ([]Inference, Error)

func (*Claim) Load

func (c *Claim) Load(ctx *ServerContext) Error

If the Claim object has a key, that exact Claim will be loaded Otherwise, Load will look for Claims matching the ID If QueryAt is a non-nil value, it will load the Claim active at that time (if any) Otherwise, it will return the current active (undeleted) version.

func (*Claim) LoadFull

func (c *Claim) LoadFull(ctx *ServerContext) Error

func (Claim) NumberOfPremises

func (c Claim) NumberOfPremises(ctx *ServerContext) (int64, Error)

func (Claim) ParentArguments

func (c Claim) ParentArguments(ctx *ServerContext) ([]Argument, Error)

func (Claim) PremiseEdges

func (c Claim) PremiseEdges(ctx *ServerContext) ([]PremiseEdge, Error)

func (Claim) Premises

func (c Claim) Premises(ctx *ServerContext) ([]Claim, Error)

func (Claim) QueryForTopLevelClaims

func (c Claim) QueryForTopLevelClaims(params ArangoQueryParameters) string

TODO: Obviously, this is going to have to be denormalized at some point

func (*Claim) RemoveContext

func (c *Claim) RemoveContext(ctx *ServerContext, contextArangoKey string) Error

func (*Claim) RemovePremise

func (c *Claim) RemovePremise(ctx *ServerContext, premiseId string) Error

TODO: Test

func (Claim) ReorderPremise

func (c Claim) ReorderPremise(ctx *ServerContext, premise Claim, new int) ([]Claim, Error)

func (*Claim) Score

func (c *Claim) Score(ctx *ServerContext) (float32, Error)

func (*Claim) Update

func (c *Claim) Update(ctx *ServerContext, updates Updates) Error

func (*Claim) UpdateScore

func (c *Claim) UpdateScore(ctx *ServerContext) Error

func (Claim) UserCanCreate

func (c Claim) UserCanCreate(ctx *ServerContext) (bool, Error)

func (Claim) UserCanDelete

func (c Claim) UserCanDelete(ctx *ServerContext) (bool, Error)

func (Claim) UserCanUpdate

func (c Claim) UserCanUpdate(ctx *ServerContext, updates Updates) (bool, Error)

func (Claim) UserCanView

func (c Claim) UserCanView(ctx *ServerContext) (bool, Error)

func (Claim) UserScores

func (c Claim) UserScores(ctx *ServerContext) ([]UserScore, Error)

func (Claim) ValidateField

func (c Claim) ValidateField(f string) Error

func (Claim) ValidateForCreate

func (c Claim) ValidateForCreate() Error

func (Claim) ValidateForDelete

func (c Claim) ValidateForDelete() Error

func (Claim) ValidateForUpdate

func (c Claim) ValidateForUpdate(updates Updates) Error

type ClaimOpinion

type ClaimOpinion struct {
	Model
	UserID  uint64    `json:"userId"`
	User    *User     `json:"user,omitempty"`
	ClaimID uuid.UUID `json:"claimId" sql:"type:uuid"`
	Claim   *Claim    `json:"claim,omitempty"`
	Truth   float64   `json:"truth"`
}

func (ClaimOpinion) ValidateField

func (co ClaimOpinion) ValidateField(f string) Error

func (ClaimOpinion) ValidateForCreate

func (co ClaimOpinion) ValidateForCreate() Error

func (ClaimOpinion) ValidateForUpdate

func (co ClaimOpinion) ValidateForUpdate() Error

type Context

type Context struct {
	Model
	ShortName        string    `json:"name" valid:"length(1|60),required"`
	Title            string    `json:"title" sql:"not null" valid:"length(3|1000),required"`
	Description      string    `json:"desc" valid:"length(3|4000)"`
	URL              string    `json:"url" valid:"url,required"`
	MID              string    `json:"mid,omitempty"` // Google KG ID
	QID              string    `json:"qid,omitempty"` // Wikidata ID
	MetaDataURL      *MetaData `json:"meta_url,omitempty"`
	MetaDataGoogle   *MetaData `json:"meta_google,omitempty"`
	MetaDataWikidata *MetaData `json:"meta_wikidata,omitempty"`
}

func (Context) ArangoID

func (c Context) ArangoID() string

func (Context) ArangoKey

func (c Context) ArangoKey() string

func (Context) CollectionName

func (c Context) CollectionName() string

func (*Context) Create

func (c *Context) Create(ctx *ServerContext) Error

func (Context) DefaultQueryParameters

func (c Context) DefaultQueryParameters() ArangoQueryParameters

func (*Context) Delete

func (c *Context) Delete(ctx *ServerContext) Error

TODO: Test

func (*Context) Load

func (c *Context) Load(ctx *ServerContext) Error

func (*Context) LoadFull

func (c *Context) LoadFull(ctx *ServerContext) Error

func (Context) NumberOfClaims

func (c Context) NumberOfClaims(ctx *ServerContext) (int64, Error)

TODO: TEst

func (*Context) Update

func (c *Context) Update(ctx *ServerContext, updates Updates) Error

TODO: Test TODO: generic...

func (Context) UserCanCreate

func (c Context) UserCanCreate(ctx *ServerContext) (bool, Error)

func (Context) UserCanDelete

func (c Context) UserCanDelete(ctx *ServerContext) (bool, Error)

func (Context) UserCanUpdate

func (c Context) UserCanUpdate(ctx *ServerContext, updates Updates) (bool, Error)

func (Context) UserCanView

func (c Context) UserCanView(ctx *ServerContext) (bool, Error)

Restrictor TODO: Test TODO: Call in CRUD and other methods

func (Context) ValidateField

func (c Context) ValidateField(f string) Error

func (Context) ValidateForCreate

func (c Context) ValidateForCreate() Error

func (Context) ValidateForDelete

func (c Context) ValidateForDelete() Error

func (Context) ValidateForUpdate

func (c Context) ValidateForUpdate(updates Updates) Error

type ContextEdge

type ContextEdge struct {
	Edge
}

A ContextEdge is an edge that goes from a Context to one or more Claims that are made in that Context

func (ContextEdge) ArangoID

func (c ContextEdge) ArangoID() string

func (ContextEdge) ArangoKey

func (c ContextEdge) ArangoKey() string

func (ContextEdge) CollectionName

func (c ContextEdge) CollectionName() string

func (*ContextEdge) Create

func (c *ContextEdge) Create(ctx *ServerContext) Error

func (ContextEdge) DefaultQueryParameters

func (c ContextEdge) DefaultQueryParameters() ArangoQueryParameters

func (*ContextEdge) Delete

func (c *ContextEdge) Delete(ctx *ServerContext) Error

func (*ContextEdge) Update

func (c *ContextEdge) Update(ctx *ServerContext, updates Updates) Error

type CoreError

type CoreError struct {
	ErrCode     int
	ErrSubcode  int
	Message     string
	ErrLocation string
	ErrData     map[string]interface{}
}

func (CoreError) Code

func (err CoreError) Code() int

func (CoreError) Data

func (err CoreError) Data() map[string]interface{}

func (CoreError) Error

func (err CoreError) Error() string

func (CoreError) IsWarning

func (err CoreError) IsWarning() bool

func (CoreError) Location

func (err CoreError) Location() string

func (CoreError) Subcode

func (err CoreError) Subcode() int

type Edge

type Edge struct {
	Key         string     `json:"_key"`
	CreatedAt   time.Time  `json:"start"`
	DeletedAt   *time.Time `json:"end"`
	CreatedByID string     `json:"creator"`
	From        string     `json:"_from,omitempty"`
	To          string     `json:"_to,omitempty"`
}

func (*Edge) PrepareForCreate

func (e *Edge) PrepareForCreate(ctx *ServerContext)

func (*Edge) PrepareForDelete

func (e *Edge) PrepareForDelete(ctx *ServerContext)

func (Edge) ValidateField

func (e Edge) ValidateField(f string) Error

func (Edge) ValidateForCreate

func (e Edge) ValidateForCreate() Error

type Error

type Error interface {
	Code() int
	Subcode() int
	Error() string
	Location() string
	Data() map[string]interface{}
	IsWarning() bool
}

func ClearTransientData

func ClearTransientData(item interface{}, m map[string]interface{}) (map[string]interface{}, Error)

func ClearTransientFields

func ClearTransientFields(item interface{}) Error

func CreateArangoObject

func CreateArangoObject(ctx *ServerContext, obj ArangoObject) Error

func DeleteArangoObject

func DeleteArangoObject(ctx *ServerContext, obj ArangoObject) Error

func DeleteArangoObjects

func DeleteArangoObjects(ctx *ServerContext, collectionName, filter string, bindVars BindVars) Error

Note that this method does NOT check permissions nor perform validations It is up to the calling method to perform the necessary checks The filter must take the form of a match expression (e.g. "obj._id == @claim") TODO: Test

func FindArangoObject

func FindArangoObject(ctx *ServerContext, query string, bindVars BindVars, result interface{}) Error

func FindArangoObjects

func FindArangoObjects(ctx *ServerContext, query string, bindVars BindVars, results interface{}) Error

func GetFieldByJsonTag

func GetFieldByJsonTag(item interface{}, jsonKey string) (field *reflect.StructField, gerr Error)

func LoadArangoObject

func LoadArangoObject(ctx *ServerContext, result interface{}, arangoKey string) Error

func NewBusinessError

func NewBusinessError(msg string, opts ...interface{}) Error

func NewError

func NewError(code, subcode int, location, msg string, data map[string]interface{}) Error

func NewNotFoundError

func NewNotFoundError(msg string, opts ...interface{}) Error

func NewPermissionError

func NewPermissionError(msg string, opts ...interface{}) Error

func NewServerError

func NewServerError(msg string, opts ...interface{}) Error

func NewUnauthorizedError

func NewUnauthorizedError(msg string, opts ...interface{}) Error

func NewWarning

func NewWarning(msg string, opts ...interface{}) Error

func NotifyArgumentMoved

func NotifyArgumentMoved(ctx *ServerContext, userId uint64, argId string, oldTargetId string, oldTargetType int) Error

func NotifyNewArgument

func NotifyNewArgument(ctx ServerContext, userId uint64, item interface{}, newArg Argument) Error

func NotifyParentArgumentMoved

func NotifyParentArgumentMoved(ctx *ServerContext, userId uint64, parentArgId string, oldTargetId string, oldTargetType int) Error

func SetByJsonTag

func SetByJsonTag(item interface{}, jsonKey string, newVal interface{}) Error

func SetID

func SetID(item interface{}, id string) Error

func SetJsonValuesOnStruct

func SetJsonValuesOnStruct(item interface{}, values map[string]interface{}, abortOnError bool) Error

func SetKey

func SetKey(item interface{}, key string) Error

func UpdateArangoObject

func UpdateArangoObject(ctx *ServerContext, obj ArangoObject, updates Updates) Error

func ValidateRequiredFields

func ValidateRequiredFields(item interface{}, fields []string) Error

func ValidateStruct

func ValidateStruct(item interface{}) Error

func ValidateStructField

func ValidateStructField(item interface{}, f string) Error

func ValidateStructFields

func ValidateStructFields(item interface{}, fs []string) Error

type Inference

type Inference struct {
	Edge
}

Inference is an edge from the target (a Claim or Argument) of an Argument to the Argument that is making the inference

func (Inference) ArangoID

func (i Inference) ArangoID() string

func (Inference) ArangoKey

func (i Inference) ArangoKey() string

func (Inference) CollectionName

func (i Inference) CollectionName() string

func (*Inference) Create

func (i *Inference) Create(ctx *ServerContext) Error

func (Inference) DefaultQueryParameters

func (i Inference) DefaultQueryParameters() ArangoQueryParameters

func (*Inference) Delete

func (i *Inference) Delete(ctx *ServerContext) Error

func (*Inference) Update

func (i *Inference) Update(ctx *ServerContext, updates Updates) Error
type Link struct {
	VersionedModel
	Title       string    `json:"title" sql:"not null" valid:"length(3|1000)"`
	Description string    `json:"desc" valid:"length(3|4000)"`
	Url         string    `json:"url" valid:"length(3|4000)"`
	ClaimID     uuid.UUID `json:"claimId" sql:"type:uuid;not null"`
	Claim       *Claim    `json:"claim,omitempty"`
}

func (Link) ValidateField

func (l Link) ValidateField(f string) Error

func (Link) ValidateForCreate

func (l Link) ValidateForCreate() Error

func (Link) ValidateForDelete

func (l Link) ValidateForDelete() Error

func (Link) ValidateForUpdate

func (l Link) ValidateForUpdate(updates Updates) Error

type Loader

type Loader interface {
	Load(*ServerContext) Error
	LoadFull(*ServerContext) Error
}

type MetaData

type MetaData struct {
	Title       string `json:"title"`
	Description string `json:"description"`
	Image       string `json:"image"`
	URL         string `json:"url"`
}

type Model

type Model struct {
	Key       string     `json:"_key" settable:"false"`
	CreatedAt time.Time  `json:"start" settable:"false"`
	UpdatedAt time.Time  `json:"mod" settable:"false"`
	DeletedAt *time.Time `json:"end" settable:"false"`
}

func (*Model) PrepareForCreate

func (m *Model) PrepareForCreate(ctx *ServerContext)

func (*Model) PrepareForDelete

func (m *Model) PrepareForDelete(ctx *ServerContext)

type Notification

type Notification struct {
	Model
	UserID   uint64      `json:"userId" sql:"not null"`
	Type     int         `json:"type" sql:"not null"`
	ItemID   *string     `json:"itemId,omitempty" sql:"type:uuid"`
	ItemType *int        `json:"itemType"`
	Item     interface{} `json:"item,omitempty" gorm:"-"`
	OldID    *string     `json:"oldId,omitempty" sql:"type:uuid"`
	OldType  *int        `json:"oldType"`
	NewID    *string     `json:"newId,omitempty" sql:"type:uuid"`
	NewType  *int        `json:"newType"`
	Viewed   bool        `json:"viewed" sql:"not null"`
}

func (Notification) ValidateField

func (n Notification) ValidateField(f string) Error

func (Notification) ValidateForCreate

func (n Notification) ValidateForCreate() Error

func (Notification) ValidateForUpdate

func (n Notification) ValidateForUpdate() Error

type PremiseEdge

type PremiseEdge struct {
	Edge
	Order int `json:"order"`
}

A PremiseEdge is an edge that goes from a Multi-premise Claim to one of the Claims that represents a specific premise

func (PremiseEdge) ArangoID

func (p PremiseEdge) ArangoID() string

func (PremiseEdge) ArangoKey

func (p PremiseEdge) ArangoKey() string

func (PremiseEdge) CollectionName

func (p PremiseEdge) CollectionName() string

func (*PremiseEdge) Create

func (p *PremiseEdge) Create(ctx *ServerContext) Error

func (PremiseEdge) DefaultQueryParameters

func (p PremiseEdge) DefaultQueryParameters() ArangoQueryParameters

func (*PremiseEdge) Delete

func (p *PremiseEdge) Delete(ctx *ServerContext) Error

func (*PremiseEdge) Update

func (p *PremiseEdge) Update(ctx *ServerContext, updates Updates) Error

func (*PremiseEdge) UpdateOrder

func (p *PremiseEdge) UpdateOrder(ctx *ServerContext, order int) Error

TODO: Preserve history...

type ReplaceMany

type ReplaceMany struct {
	IDS []uint64 `json:"ids"`
}

type Restrictor

type Restrictor interface {
	UserCanView(ctx *ServerContext) (bool, Error)
	UserCanCreate(ctx *ServerContext) (bool, Error)
	UserCanUpdate(ctx *ServerContext, updates Updates) (bool, Error)
	UserCanDelete(ctx *ServerContext) (bool, Error)
}

UserCanUpdate should be called with the list of values that will be updated,

type Scorer

type Scorer interface {
	Score(*ServerContext) (float32, Error)
	UpdateScore(*ServerContext) Error
}

type ServerContext

type ServerContext struct {
	Context     context.Context
	Arango      ArangoContext
	Payload     map[string]interface{}
	Request     map[string]interface{}
	Type        reflect.Type
	ParentType  reflect.Type
	Test        bool
	UserContext User
	AppName     string
	Method      string
	Path        string
	Endpoint    string
	RequestID   string
	RequestAt   *time.Time
}

func (*ServerContext) RequestTime

func (ctx *ServerContext) RequestTime() time.Time

func (ServerContext) Rollback

func (ctx ServerContext) Rollback() Error

func (ServerContext) UserLoggedIn

func (ctx ServerContext) UserLoggedIn() bool

TODO: Test

type Updates

type Updates map[string]interface{}

type User

type User struct {
	Model
	Name            string     `json:"name" sql:"not null" valid:"length(3|50)"`
	Username        string     `` /* 127-byte string literal not displayed */
	Email           string     `json:"email" sql:"not null" valid:"email"`
	Password        string     `json:"password,omitempty" sql:"-" valid:"length(5|64)"`
	HashedPassword  string     `json:"hashed_password"` // TODO: don't return this value via the API
	Image           string     `json:"img,omitempty"`
	Curator         bool       `json:"curator"`
	Admin           bool       `json:"admin"`
	URL             string     `json:"url,omitempty"`
	EmailVerifiedAt *time.Time `json:"-" settable:"false"`
}

func (User) ArangoID

func (u User) ArangoID() string

func (User) ArangoKey

func (u User) ArangoKey() string

func (*User) ChangePassword

func (u *User) ChangePassword(ctx *ServerContext, oldPassword string) Error

func (User) CollectionName

func (u User) CollectionName() string

func (*User) Create

func (u *User) Create(ctx *ServerContext) Error

func (User) DefaultQueryParameters

func (u User) DefaultQueryParameters() ArangoQueryParameters

func (*User) Delete

func (u *User) Delete(ctx *ServerContext) Error

TODO: Test

func (*User) Load

func (u *User) Load(ctx *ServerContext) Error

func (*User) LoadFull

func (u *User) LoadFull(ctx *ServerContext) Error

func (User) Score

func (u User) Score(ctx *ServerContext, target ArangoObject, score float32) Error

func (*User) ScoreFor

func (u *User) ScoreFor(ctx *ServerContext, target ArangoObject) (*UserScore, Error)

func (*User) Update

func (u *User) Update(ctx *ServerContext, updates Updates) Error

TODO: Test

func (User) UserCanCreate

func (u User) UserCanCreate(ctx *ServerContext) (bool, Error)

func (User) UserCanDelete

func (u User) UserCanDelete(ctx *ServerContext) (bool, Error)

func (User) UserCanUpdate

func (u User) UserCanUpdate(ctx *ServerContext, updates Updates) (bool, Error)

func (User) UserCanView

func (u User) UserCanView(ctx *ServerContext) (bool, Error)

Restrictor TODO: Test TODO: Call in CRUD and other methods

func (User) ValidateField

func (u User) ValidateField(f string) Error

func (User) ValidateForCreate

func (u User) ValidateForCreate() Error

func (User) ValidateForDelete

func (u User) ValidateForDelete() Error

func (User) ValidateForUpdate

func (u User) ValidateForUpdate(updates Updates) Error

func (*User) VerifyPassword

func (u *User) VerifyPassword(ctx *ServerContext, password string) (bool, Error)

type UserScore

type UserScore struct {
	Edge
	Score float32 `json:"score"`
}

A UserScore is an edge that goes from a User to either a Claim (truth score) or an Argument (relevance score) UserScore corresponds directly to the "Personal Score" or "Belief Score" described in the Canonical Debate white paper: https://github.com/canonical-debate-lab/paper#33322-belief-scores The Score attribute is a float value from 0 to 1.0, corresponding to a % belief in the truth/relevance of the target (where 0 = 0% and 1.0 = 100%)

func (UserScore) ArangoID

func (u UserScore) ArangoID() string

func (UserScore) ArangoKey

func (u UserScore) ArangoKey() string

func (UserScore) CollectionName

func (u UserScore) CollectionName() string

func (*UserScore) Create

func (u *UserScore) Create(ctx *ServerContext) Error

func (UserScore) DefaultQueryParameters

func (u UserScore) DefaultQueryParameters() ArangoQueryParameters

func (*UserScore) Delete

func (u *UserScore) Delete(ctx *ServerContext) Error

func (*UserScore) Update

func (u *UserScore) Update(ctx *ServerContext, updates Updates) Error

type Validator

type Validator interface {
	ValidateForCreate() Error
	ValidateForUpdate(Updates) Error
	ValidateForDelete() Error
	ValidateField(string) Error
}

type VersionedModel

type VersionedModel struct {
	Key         string     `json:"_key" settable:"false"`
	ID          string     `json:"id" settable:"false"`
	CreatedAt   time.Time  `json:"start" settable:"false"`
	UpdatedAt   time.Time  `json:"mod" settable:"false"`
	DeletedAt   *time.Time `json:"end" settable:"false"`
	CreatedByID string     `json:"creator" settable:"false"`
	UpdatedByID string     `json:"editor,omitempty" settable:"false"`
	QueryAt     *time.Time `json:"-"`
}

func (VersionedModel) DateFilter

func (vm VersionedModel) DateFilter(bindVars map[string]interface{}) string

func (*VersionedModel) PrepareForCreate

func (vm *VersionedModel) PrepareForCreate(ctx *ServerContext)

func (*VersionedModel) PrepareForDelete

func (vm *VersionedModel) PrepareForDelete(ctx *ServerContext)

func (VersionedModel) QueryDate

func (vm VersionedModel) QueryDate() *time.Time

type Versioner

type Versioner interface {
	// contains filtered or unexported methods
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳