parser

package
v0.406.1 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeywordModel   = "model"
	KeywordModels  = "models"
	KeywordApi     = "api"
	KeywordMessage = "message"
	KeywordField   = "field"
	KeywordFields  = "fields"
	KeywordActions = "actions"
	KeywordDomains = "domains"
	KeywordEmails  = "emails"
	KeywordRole    = "role"
	KeywordEnum    = "enum"
	KeywordWith    = "with"
	KeywordReturns = "returns"
	KeywordJob     = "job"
	KeywordInput   = "inputs"
)

Keywords

View Source
const (
	FieldTypeID        = "ID"        // a uuid or similar
	FieldTypeText      = "Text"      // a string
	FieldTypeNumber    = "Number"    // an integer
	FieldTypeDecimal   = "Decimal"   // a decimal
	FieldTypeDate      = "Date"      // a date with no time element
	FieldTypeTimestamp = "Timestamp" // a UTC unix timestamp
	FieldTypeBoolean   = "Boolean"   // a boolean
	FieldTypeSecret    = "Secret"    // an encrypted secret
	FieldTypePassword  = "Password"  // a hashed password
	FieldTypeMarkdown  = "Markdown"  // a markdown rich text
	FieldTypeVector    = "Vector"    // a vector
	FieldTypeFile      = "File"      // a inline file supplied as a data-url
	FieldTypeDuration  = "Duration"  // a time duration
)

Built in Keel types. Worth noting a field type can also reference another user-defined model

View Source
const (
	ActionTypeGet    = "get"
	ActionTypeCreate = "create"
	ActionTypeUpdate = "update"
	ActionTypeList   = "list"
	ActionTypeDelete = "delete"

	// Arbitrary function action types
	ActionTypeRead  = "read"
	ActionTypeWrite = "write"
)

All possible action types

View Source
const (
	FieldNameId        = "id"
	FieldNameCreatedAt = "createdAt"
	FieldNameUpdatedAt = "updatedAt"
)

All models get a field named "id" implicitly. This set of constants provides the set of this, and other similar implicit fields.

View Source
const (
	IdentityModelName              = "Identity"
	IdentityFieldNameEmail         = "email"
	IdentityFieldNameEmailVerified = "emailVerified"
	IdentityFieldNamePassword      = "password"
	IdentityFieldNameExternalId    = "externalId"
	IdentityFieldNameIssuer        = "issuer"
	IdentityFieldNameName          = "name"
	IdentityFieldNameGivenName     = "givenName"
	IdentityFieldNameFamilyName    = "familyName"
	IdentityFieldNameMiddleName    = "middleName"
	IdentityFieldNameNickName      = "nickName"
	IdentityFieldNameProfile       = "profile"
	IdentityFieldNamePicture       = "picture"
	IdentityFieldNameWebsite       = "website"
	IdentityFieldNameGender        = "gender"
	IdentityFieldNameZoneInfo      = "zoneInfo"
	IdentityFieldNameLocale        = "locale"
)
View Source
const (
	RequestPasswordResetActionName = "requestPasswordReset"
	PasswordResetActionName        = "resetPassword"
)
View Source
const (
	AttributeUnique     = "unique"
	AttributePermission = "permission"
	AttributeWhere      = "where"
	AttributeSet        = "set"
	AttributePrimaryKey = "primaryKey"
	AttributeDefault    = "default"
	AttributeValidate   = "validate"
	AttributeRelation   = "relation"
	AttributeOrderBy    = "orderBy"
	AttributeSortable   = "sortable"
	AttributeSchedule   = "schedule"
	AttributeFunction   = "function"
	AttributeOn         = "on"
	AttributeEmbed      = "embed"
	AttributeComputed   = "computed"
	AttributeFacet      = "facet"
)
View Source
const (
	OrderByAscending  = "asc"
	OrderByDescending = "desc"
)
View Source
const (
	DefaultApi = "Api"
)
View Source
const (
	MessageFieldTypeAny = "Any"
)

Types for Message fields

Variables

View Source
var ErrInvalidAssignmentExpression = errors.New("expression is not a valid assignment")

Functions

func IsBuiltInFieldType

func IsBuiltInFieldType(s string) bool

Types

type APIModelActionNode added in v0.377.0

type APIModelActionNode struct {
	node.Node

	Name NameNode `@@`
}

type APIModelNode added in v0.377.0

type APIModelNode struct {
	node.Node

	Name     NameNode               `@@`
	Sections []*APIModelSectionNode `("{" @@* "}")*`
}

type APIModelSectionNode added in v0.377.0

type APIModelSectionNode struct {
	node.Node

	Actions []*APIModelActionNode `"actions" "{" @@* "}"`
}

type APINode

type APINode struct {
	node.Node

	Name     NameNode          `@@`
	Sections []*APISectionNode `"{" @@* "}"`
}

type APISectionNode

type APISectionNode struct {
	node.Node

	Models    []*APIModelNode `( "models" "{" @@* "}"`
	Attribute *AttributeNode  `| @@ )`
}

type AST

type AST struct {
	node.Node

	Raw                  string
	Declarations         []*DeclarationNode `@@*`
	EnvironmentVariables []string
	Secrets              []string
}

func Parse

func Parse(s *reader.SchemaFile) (*AST, error)

type ActionInputNode

type ActionInputNode struct {
	node.Node

	Label    *NameNode `(@@ ":")?`
	Type     Ident     `@@`
	Optional bool      `@( "?" )?`
}

func (*ActionInputNode) Name

func (a *ActionInputNode) Name() string

type ActionNode

type ActionNode struct {
	node.Node

	Type       NameNode           `@@`
	Name       NameNode           `@@`
	Inputs     []*ActionInputNode `"(" ( @@ ( "," @@ )* ","? )? ")"`
	With       []*ActionInputNode `( ( "with" "(" ( @@ ( "," @@ )* ","? )? ")" )`
	Returns    []*ActionInputNode `| ( "returns" "(" ( @@ ( "," @@ )* ) ")" ) )?`
	Attributes []*AttributeNode   `( "{" @@+ "}" | @@+ )?`

	BuiltIn bool
}

func (*ActionNode) IsArbitraryFunction

func (a *ActionNode) IsArbitraryFunction() bool

func (*ActionNode) IsFunction

func (a *ActionNode) IsFunction() bool

type AttributeArgumentNode

type AttributeArgumentNode struct {
	node.Node

	Label      *NameNode   `(@@ ":")?`
	Expression *Expression `@@`
}

type AttributeNameToken

type AttributeNameToken struct {
	node.Node

	Value string `"@" @Ident`
}

type AttributeNode

type AttributeNode struct {
	node.Node

	Name AttributeNameToken `@@`

	// This supports:
	// - no parenthesis at all
	// - empty parenthesis
	// - parenthesis with args
	Arguments []*AttributeArgumentNode `(( "(" ")" ) | ( "(" @@ ( "," @@ )* ")" ) )?`
}

Attributes: - @permission - @set - @validate - @where - @unique - @default - @orderBy - @sortable - @on

type DeclarationNode

type DeclarationNode struct {
	node.Node

	Model   *ModelNode   `("model" @@`
	Role    *RoleNode    `| "role" @@`
	API     *APINode     `| "api" @@`
	Enum    *EnumNode    `| "enum" @@`
	Message *MessageNode `| "message" @@`
	Job     *JobNode     `| "job" @@`
	Routes  *RoutesNode  `| "routes" @@)`
}

type DomainNode

type DomainNode struct {
	node.Node

	Domain string `@String`
}

type EmailsNode

type EmailsNode struct {
	node.Node

	Email string `@String`
}

type EnumNode

type EnumNode struct {
	node.Node

	Name   NameNode         `@@`
	Values []*EnumValueNode `"{" @@* "}"`
}

func (*EnumNode) NameNode

func (e *EnumNode) NameNode() NameNode

type EnumValueNode

type EnumValueNode struct {
	node.Node

	Name NameNode `@@`
}

type Error

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

func (Error) Error

func (e Error) Error() string

func (Error) GetPositionRange

func (e Error) GetPositionRange() (start lexer.Position, end lexer.Position)

func (Error) GetTokens

func (e Error) GetTokens() []lexer.Token

func (Error) HasEndPosition

func (e Error) HasEndPosition() bool

func (Error) InRange

func (e Error) InRange(position node.Position) bool

type Expression

type Expression struct {
	node.Node
}

func ParseExpression

func ParseExpression(source string) (*Expression, error)

func (*Expression) CleanString added in v0.400.0

func (e *Expression) CleanString() string

CleanString removes new lines and unnecessary whitespaces, preserving single spaces between tokens

func (*Expression) Parse added in v0.400.0

func (e *Expression) Parse(lex *lexer.PeekingLexer) error

func (*Expression) String added in v0.400.0

func (e *Expression) String() string

func (*Expression) ToAssignmentExpression added in v0.400.0

func (expr *Expression) ToAssignmentExpression() (*Expression, *Expression, error)

ToAssignmentExpression splits an assignment expression into two separate expressions. E.g. the expression `post.age = 1 + 1` will become `post.age` and `1 + 1`

type ExpressionIdent added in v0.400.0

type ExpressionIdent struct {
	node.Node

	Fragments []string
}

func (ExpressionIdent) String added in v0.400.0

func (ident ExpressionIdent) String() string

type FieldNode

type FieldNode struct {
	node.Node

	Name       NameNode         `@@`
	Type       NameNode         `@@`
	Repeated   bool             `@( "[" "]" )?`
	Optional   bool             `@( "?" )?`
	Attributes []*AttributeNode `( "{" @@+ "}" | @@+ )?`

	// Some fields are added implicitly after parsing the schema
	// For these fields this value is set to true so we can distinguish
	// them from fields defined by the user in the schema
	BuiltIn bool
}

func (*FieldNode) IsScalar

func (f *FieldNode) IsScalar() bool

type Ident

type Ident struct {
	node.Node

	Fragments []*IdentFragment `( @@ ( "." @@ )* )`
}

func (*Ident) ToString

func (ident *Ident) ToString() string

type IdentFragment

type IdentFragment struct {
	node.Node

	Fragment string `@Ident`
}

type JobInputNode

type JobInputNode struct {
	node.Node

	Name     NameNode `@@`
	Type     NameNode `@@`
	Repeated bool     `( @( "[" "]" )`
	Optional bool     `| @( "?" ))?`
}

type JobNode

type JobNode struct {
	node.Node

	Name     NameNode          `@@`
	Sections []*JobSectionNode `"{" @@* "}"`
}

type JobSectionNode

type JobSectionNode struct {
	node.Node

	Inputs    []*JobInputNode `( "inputs" "{" @@* "}"`
	Attribute *AttributeNode  `| @@ )`
}

type MessageNode

type MessageNode struct {
	node.Node

	Name    NameNode     `@@`
	Fields  []*FieldNode `"{" @@* "}"`
	BuiltIn bool
}

func (*MessageNode) NameNode

func (e *MessageNode) NameNode() NameNode

type ModelNode

type ModelNode struct {
	node.Node

	Name     NameNode            `@@`
	Sections []*ModelSectionNode `"{" @@* "}"`
	BuiltIn  bool
}

func (*ModelNode) NameNode

func (e *ModelNode) NameNode() NameNode

type ModelSectionNode

type ModelSectionNode struct {
	node.Node

	Fields    []*FieldNode   `( ("fields" "{" @@* "}")`
	Actions   []*ActionNode  `| ("actions" "{" @@* "}")`
	Attribute *AttributeNode `| @@ )`
}

type NameNode

type NameNode struct {
	node.Node

	Value string `@Ident`
}

type RoleNode

type RoleNode struct {
	node.Node

	Name     NameNode           `@@`
	Sections []*RoleSectionNode `"{" @@* "}"`
}

type RoleSectionNode

type RoleSectionNode struct {
	node.Node

	Domains []*DomainNode `("domains" "{" @@* "}"`
	Emails  []*EmailsNode `| "emails" "{" @@* "}")`
}

type RouteNode added in v0.405.2

type RouteNode struct {
	node.Node

	Method  NameNode `@@`
	Pattern string   `"(" @String`
	Handler NameNode `"," @@ ")"`
}

type RoutesNode added in v0.405.2

type RoutesNode struct {
	node.Node

	Routes []*RouteNode `"{" @@* "}"`
}

Jump to

Keyboard shortcuts

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