actions

package
v0.395.11 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2024 License: AGPL-3.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidToken     = common.NewAuthenticationFailedMessageErr("cannot be parsed or verified as a valid JWT")
	ErrTokenExpired     = common.NewAuthenticationFailedMessageErr("token has expired")
	ErrIdentityNotFound = common.NewAuthenticationFailedMessageErr("identity not found")
)

Functions

func AuthoriseAction

func AuthoriseAction(scope *Scope, input map[string]any, rowsToAuthorise []map[string]any) (authorised bool, err error)

AuthoriseAction checks authorisation for rows using the permission and role rules applicable for an action, which could be defined at model- and action- levels.

func AuthoriseForActionType

func AuthoriseForActionType(scope *Scope, opType proto.ActionType, rowsToAuthorise []map[string]any) (authorised bool, err error)

AuthoriseForActionType checks authorisation for rows using permission and role rules defined for some action type, i.e. agnostic to any action.

func Create

func Create(scope *Scope, input map[string]any) (res map[string]any, err error)

func CreateIdentity

func CreateIdentity(ctx context.Context, schema *proto.Schema, email string, password string, issuer string) (auth.Identity, error)

func CreateIdentityWithClaims added in v0.386.0

func CreateIdentityWithClaims(ctx context.Context, schema *proto.Schema, externalId string, issuer string, standardClaims *oauth.IdTokenClaims, customClaims map[string]any) (auth.Identity, error)

func Delete

func Delete(scope *Scope, input map[string]any) (res *string, err error)

func Execute

func Execute(scope *Scope, input any) (result any, meta *common.ResponseMetadata, err error)

func FindIdentityByEmail

func FindIdentityByEmail(ctx context.Context, schema *proto.Schema, email string, issuer string) (auth.Identity, error)

func FindIdentityByExternalId

func FindIdentityByExternalId(ctx context.Context, schema *proto.Schema, externalId string, issuer string) (auth.Identity, error)

func FindIdentityById

func FindIdentityById(ctx context.Context, schema *proto.Schema, id string) (auth.Identity, error)

func GenerateListStatement

func GenerateListStatement(query *QueryBuilder, scope *Scope, input map[string]any) (*Statement, *Page, error)

func Get

func Get(scope *Scope, input map[string]any) (map[string]any, error)

func HandleAuthorizationHeader

func HandleAuthorizationHeader(ctx context.Context, schema *proto.Schema, headers http.Header) (auth.Identity, error)

func HandleBearerToken

func HandleBearerToken(ctx context.Context, schema *proto.Schema, token string) (auth.Identity, error)

func List

func List(scope *Scope, input map[string]any) (map[string]any, error)

func ParsePostgresArray added in v0.384.0

func ParsePostgresArray[T any](array string, parse func(string) (T, error)) ([]T, error)

func ResetPassword deprecated

func ResetPassword(scope *Scope, input map[string]any) error

Deprecated: we will be deprecating the authenticate action and password flow in favour of the new auth endpoints

func ResetRequestPassword

func ResetRequestPassword(scope *Scope, input map[string]any) error

func TransformInputs added in v0.395.1

func TransformInputs(schema *proto.Schema, message *proto.Message, input map[string]any, isFunction bool) (map[string]any, error)

TransformInputs will traverse through the input data structure and will ensure that values are correctly typed. This is necessary because we need the correct types when generating to SQL and because the JSON and RPC APIs don't type correctly when parsing the input JSON (for example, "Number" values become floats).

func TryResolveAuthorisationEarly

func TryResolveAuthorisationEarly(scope *Scope, permissions []*proto.PermissionRule) (canResolveAll bool, authorised bool, err error)

TryResolveAuthorisationEarly will attempt to check authorisation early without row-based querying. This will take into account logical conditions and multiple expression and role permission attributes.

func Update

func Update(scope *Scope, input map[string]any) (res map[string]any, err error)

func UpdateIdentityWithClaims added in v0.386.0

func UpdateIdentityWithClaims(ctx context.Context, schema *proto.Schema, externalId string, issuer string, standardClaims *oauth.IdTokenClaims, customClaims map[string]any) (auth.Identity, error)

Types

type ActionOperator

type ActionOperator int

An ActionOperator gives a symbolic, machine-readable name to each of the comparison operators that Keel Actions work with at a CONCEPTUAL level.

By design, the ActionOperator has no knowledge (in of itself) of how these might be expressed in schema's or in request inputs, or in expressions for example.

const (
	Unknown ActionOperator = iota

	Contains
	NotContains
	Equals
	NotEquals
	StartsWith
	EndsWith
	GreaterThan
	GreaterThanEquals
	LessThan
	LessThanEquals
	OneOf
	NotOneOf
	After
	Before
	OnOrAfter
	OnOrBefore

	AllEquals
	AnyEquals
	AllNotEquals
	AnyNotEquals
	AllGreaterThan
	AnyGreaterThan
	AllGreaterThanEquals
	AnyGreaterThanEquals
	AllLessThan
	AnyLessThan
	AllLessThanEquals
	AnyLessThanEquals
	AllAfter
	AnyAfter
	AllBefore
	AnyBefore
	AllOnOrAfter
	AnyOnOrAfter
	AllOnOrBefore
	AnyOnOrBefore
)

type JoinOption

type JoinOption struct {
	Type JoinType
}

type JoinType

type JoinType string
const (
	JoinTypeInner JoinType = "INNER"
	JoinTypeLeft  JoinType = "LEFT"
)

type Page

type Page struct {
	First  int
	Last   int
	After  string
	Before string
}

A Page describes which page you want from a list of records, in the style of this "Connection" pattern: https://relay.dev/graphql/connections.htm

Consider for example, that you previously fetched a page of 10 records and from that previous response you also knew that the last of those 10 records could be referred to with the opaque cursor "abc123". Armed with that information you can ask for the next page of 10 records by setting First to 10, and After to "abc123".

To move backwards, you'd set the Last and Before fields instead.

When you have no prior positional context you should specify First but leave Before and After to the empty string. This gives you the first N records.

func ParsePage

func ParsePage(args map[string]any) (Page, error)

ParsePage extracts page mandate information from the given map and uses it to compose a Page.

func (*Page) Cursor added in v0.383.0

func (p *Page) Cursor() string

Cursor returns the cursor used in the pagination based on the direction of pagination: - if backwards, it's `before` - if forward pagination, it's `after`

func (*Page) IsBackwards added in v0.383.0

func (p *Page) IsBackwards() bool

IsBackwards tells us if the page is backwards paginated (e.g. we're requesting elements before a cursor)

type PageInfo

type PageInfo struct {
	// Count returns the number of rows returned for the current page
	Count int

	// TotalCount returns the total number of rows across all pages
	TotalCount int

	// HasNextPage indicates if there is a subsequent page after the current page
	HasNextPage bool

	// StartCursor is the identifier representing the first row in the set
	StartCursor string

	// EndCursor is the identifier representing the last row in the set
	EndCursor string
}

func (*PageInfo) ToMap

func (pi *PageInfo) ToMap() map[string]any

type QueryBuilder

type QueryBuilder struct {
	// The base model this query builder is acting on.
	Model *proto.Model
	// contains filtered or unexported fields
}

func NewQuery

func NewQuery(model *proto.Model, opts ...QueryBuilderOption) *QueryBuilder

func (*QueryBuilder) AddWriteValue

func (query *QueryBuilder) AddWriteValue(operand *QueryOperand, value *QueryOperand)

Includes a value to be written during an INSERT or UPDATE.

func (*QueryBuilder) AddWriteValues

func (query *QueryBuilder) AddWriteValues(values map[string]*QueryOperand)

Includes values to be written during an INSERT or UPDATE.

func (*QueryBuilder) And

func (query *QueryBuilder) And()

Appends the next condition with a logical AND.

func (*QueryBuilder) AppendOrderBy

func (query *QueryBuilder) AppendOrderBy(operand *QueryOperand, direction string)

Include a column in ORDER BY. If the column already exists, then just update the sort direction.

func (*QueryBuilder) AppendReturning

func (query *QueryBuilder) AppendReturning(operand *QueryOperand)

Include a column in RETURNING.

func (*QueryBuilder) ApplyPaging

func (query *QueryBuilder) ApplyPaging(page Page) error

Apply pagination filters to the query.

func (*QueryBuilder) CloseParenthesis

func (query *QueryBuilder) CloseParenthesis()

Closes the current conditional scope in the where expression (i.e. close parethesis).

func (*QueryBuilder) Copy

func (query *QueryBuilder) Copy() *QueryBuilder

Creates a copy of the query builder.

func (*QueryBuilder) DeleteStatement

func (query *QueryBuilder) DeleteStatement(ctx context.Context) *Statement

Generates an executable DELETE statement with the list of arguments.

func (*QueryBuilder) DistinctOn added in v0.391.1

func (query *QueryBuilder) DistinctOn(operand *QueryOperand)

Include a column in this table in DISTINCT ON.

func (*QueryBuilder) InsertStatement

func (query *QueryBuilder) InsertStatement(ctx context.Context) *Statement

Generates an executable INSERT statement with the list of arguments.

func (*QueryBuilder) Join

func (query *QueryBuilder) Join(joinModel string, joinField *QueryOperand, modelField *QueryOperand)

Include an JOIN clause.

func (*QueryBuilder) Limit

func (query *QueryBuilder) Limit(limit int)

Set the LIMIT to a number.

func (*QueryBuilder) OpenParenthesis

func (query *QueryBuilder) OpenParenthesis()

Opens a new conditional scope in the where expression (i.e. open parethesis).

func (*QueryBuilder) Or

func (query *QueryBuilder) Or()

Appends the next condition with a logical OR.

func (*QueryBuilder) Select added in v0.391.1

func (query *QueryBuilder) Select(operand *QueryOperand)

Includes a column in SELECT.

func (*QueryBuilder) SelectClause added in v0.391.1

func (query *QueryBuilder) SelectClause(clause string)

Include a clause in SELECT.

func (*QueryBuilder) SelectStatement

func (query *QueryBuilder) SelectStatement() *Statement

Generates an executable SELECT statement with the list of arguments.

func (*QueryBuilder) SelectUnnested added in v0.391.1

func (query *QueryBuilder) SelectUnnested(operand *QueryOperand)

Includes an array column in SELECT and unnests it.

func (*QueryBuilder) UpdateStatement

func (query *QueryBuilder) UpdateStatement(ctx context.Context) *Statement

Generates an executable UPDATE statement with the list of arguments.

func (*QueryBuilder) Where

func (query *QueryBuilder) Where(left *QueryOperand, operator ActionOperator, right *QueryOperand) error

Include a WHERE condition, ANDed to the existing filters (unless an OR has been specified)

type QueryBuilderOption

type QueryBuilderOption func(qb *QueryBuilder)

func WithJoinType

func WithJoinType(joinType JoinType) QueryBuilderOption

type QueryOperand

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

func AllFields

func AllFields() *QueryOperand

All fields on the query builder's model.

func ExpressionField

func ExpressionField(fragments []string, field string) *QueryOperand

Some field from the fragments of an expression or input.

func Field

func Field(field string) *QueryOperand

Some field on the query builder's model.

func IdField

func IdField() *QueryOperand

The identifier field on the query builder's model.

func InlineQuery

func InlineQuery(query *QueryBuilder, column *QueryOperand) *QueryOperand

Represents an inline query. column refers to the single column to select from the inline query statement.

func Null

func Null() *QueryOperand

Represents a null value operand.

func Raw added in v0.369.1

func Raw(sql string) *QueryOperand

Represents a raw SQL operand.

func Value

func Value(value any) *QueryOperand

Represents a value operand.

func ValueOrNullIfEmpty added in v0.386.0

func ValueOrNullIfEmpty(value any) *QueryOperand

func (*QueryOperand) IsArrayValue added in v0.384.0

func (o *QueryOperand) IsArrayValue() bool

func (*QueryOperand) IsField

func (o *QueryOperand) IsField() bool

func (*QueryOperand) IsInlineQuery

func (o *QueryOperand) IsInlineQuery() bool

A query builder to be evaluated and injected as an operand.

func (*QueryOperand) IsNull

func (o *QueryOperand) IsNull() bool

func (*QueryOperand) IsRaw added in v0.369.1

func (o *QueryOperand) IsRaw() bool

Raw SQL to be used as a operand.

func (*QueryOperand) IsValue

func (o *QueryOperand) IsValue() bool

type Relationship

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

type Row

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

type Rows

type Rows = []map[string]interface{}

type Scope

type Scope struct {
	Context context.Context
	Action  *proto.Action
	Model   *proto.Model
	Job     *proto.Job
	Schema  *proto.Schema
}

func NewJobScope

func NewJobScope(
	ctx context.Context,
	job *proto.Job,
	schema *proto.Schema) *Scope

func NewModelScope

func NewModelScope(
	ctx context.Context,
	model *proto.Model,
	schema *proto.Schema) *Scope

func NewScope

func NewScope(
	ctx context.Context,
	action *proto.Action,
	schema *proto.Schema) *Scope

func (*Scope) WithContext

func (s *Scope) WithContext(ctx context.Context) *Scope

type Statement

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

The templated SQL statement and associated values, ready to be executed.

func GenerateCreateStatement

func GenerateCreateStatement(query *QueryBuilder, scope *Scope, input map[string]any) (*Statement, error)

func GenerateDeleteStatement

func GenerateDeleteStatement(query *QueryBuilder, scope *Scope, input map[string]any) (*Statement, error)

func GenerateGetStatement

func GenerateGetStatement(query *QueryBuilder, scope *Scope, input map[string]any) (*Statement, error)

func GeneratePermissionStatement

func GeneratePermissionStatement(scope *Scope, permissions []*proto.PermissionRule, input map[string]any, idsToAuthorise []string) (*Statement, error)

func GenerateUpdateStatement

func GenerateUpdateStatement(query *QueryBuilder, scope *Scope, input map[string]any) (*Statement, error)

func (*Statement) Execute

func (statement *Statement) Execute(ctx context.Context) (int, error)

Execute the SQL statement against the database, returning the number of rows affected.

func (*Statement) ExecuteToMany

func (statement *Statement) ExecuteToMany(ctx context.Context, page *Page) (Rows, *PageInfo, error)

Execute the SQL statement against the database, return the rows, number of rows affected, and a boolean to indicate if there is a next page.

func (*Statement) ExecuteToSingle

func (statement *Statement) ExecuteToSingle(ctx context.Context) (map[string]any, error)

Execute the SQL statement against the database and expects a single row, returns the single row or nil if no data is found.

func (*Statement) SqlArgs

func (statement *Statement) SqlArgs() []any

func (*Statement) SqlTemplate

func (statement *Statement) SqlTemplate() string

Jump to

Keyboard shortcuts

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