comptypes

package module
v0.0.0-...-6774f22 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: MIT Imports: 7 Imported by: 0

README

comptypes

Composite types, defined in JSON and matched with regex, written in golang

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddComptype

func AddComptype(name string, rules TypeGroup) error

Add a user defined `TypeLabel` in `data`

func ComptypeContainsATypeKey

func ComptypeContainsATypeKey(typeKey string) bool

func ComptypeExists

func ComptypeExists(target string) bool

func GetComptypeNames

func GetComptypeNames() []string

func GetMatchedPartsFromArgs

func GetMatchedPartsFromArgs(ct TypeGroup, arg string, matchedFields []interface{}) (string, []interface{})

GetFieldNamesFromArg will return the columns that match the provided arg, or nil on failure

func LoadComptypes

func LoadComptypes() error

Types

type Comptype

type Comptype struct {
	Name  string    `json:"name"`
	Rules TypeGroup `json:"rules"`
}

type ComptypeCategory

type ComptypeCategory int

ComptypeCategory is an enum used by `ComptypeRule`

const (
	Alias ComptypeCategory = iota
	Parse
	Enum
	Unit
)

type Conversion

type Conversion struct {
	BaseUnit      string `json:"baseUnit"`
	ThisUnitIndex int    `json:"thisUnitIndex"`
}

type Data

type Data struct {
	Comptypes []Comptype `json:"comptypes"`
}

type GroupRuleKey

type GroupRuleKey struct {
	Group   *TypeGroup `json:"group"`
	Rule    *TypeRule  `json:"rule"`
	TypeKey *string    `json:"typeKey"`
}

NOTE: This is only valid if TWO are nil

type PropsEnum

type PropsEnum struct {
	CaseSensitive bool     `json:"caseSensitive"`
	ValueSet      []string `json:"valueSet"`
}

type PropsParse

type PropsParse struct {
	FuncKey    string      `json:"funcKey"`
	OutType    string      `json:"outType"`
	Conversion *Conversion `json:"conversion"`
}

type PropsUnit

type PropsUnit struct {
	BaseUnit   string                    `json:"baseUnit"`
	OtherUnits map[string]UnitConversion `json:"otherUnits"`
}

type TypeGroup

type TypeGroup struct {
	Op              TypeOp         `json:"op"`
	GroupsRulesKeys []GroupRuleKey `json:"groupsRulesKeys"`
}

func GetComptypeRules

func GetComptypeRules(name string) *TypeGroup

func (*TypeGroup) Valid

func (g *TypeGroup) Valid(rootRuleKey string) error

type TypeOp

type TypeOp int
const (
	And TypeOp = iota
	Or
)

type TypeRule

type TypeRule struct {
	Name       string           `json:"name"`
	Rx         string           `json:"regex"`
	Category   ComptypeCategory `json:"category"`
	PropsParse *PropsParse      `json:"propsParse"`
	PropsEnum  *PropsEnum       `json:"propsEnum"`
	PropsUnit  *PropsUnit       `json:"propsUnit"`
}

ComptypeRule lets user specify rules to evaluate high level "types", a single user argument can have multiple rules, which are evaluated left to right, each rule corresponds to a column in a table. Rules include a regex to match the type on and a category that dictates how to evaluate the type. Categories include:

  • Alias: simply identifies the matched string with an alias name
  • Parse: for conversion of the matched string to another type, either directly or through a function (using a function key). A value that's parsed to a numeric type (float64 or int64) can also have a `UnitConversion` defined for it (e.g. g -> lbs)
  • Enum: are treated as strings by go, but are stored as enum types in the db and identified as enums by the frontend JS

func (*TypeRule) Valid

func (r *TypeRule) Valid() error

type UnitConversion

type UnitConversion struct {
	Rx               string `json:"rx"`
	ConversionFactor string `json:"conversionFactor"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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