property

package
v0.3.1-rc1 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAny

func GetAny[T any](i IProperty) (T, bool, error)

GetAny returns the underlay value as the given generic type, if not found or parse error, returns false.

func GetMap

func GetMap[T any](i IProperty) (map[string]T, bool, error)

GetMap returns the underlay value as a string map with the given generic type, if not found or parse error, returns false.

func GetObject

func GetObject[T any](i IProperty) (T, bool, error)

GetObject returns the underlay value as a T object with the given generic type, if not found or parse error, returns false.

func GetSet

func GetSet[T comparable](i IProperty) (sets.Set[T], bool, error)

GetSet returns the underlay value as a set with the given generic type, if not found or parse error, returns false.

func GetSlice

func GetSlice[T any](i IProperty) ([]T, bool, error)

GetSlice returns the underlay value as a slice with the given generic type, if not found or parse error, returns false.

func PropertiesField

func PropertiesField(name string) *otherBuilder

PropertiesField returns a new ent.Field with type Properties.

func SchemasField

func SchemasField(name string) *otherBuilder

SchemasField returns a new ent.Field with type Schemas.

func ValuesField

func ValuesField(name string) *otherBuilder

ValuesField returns a new ent.Field with type Values.

Types

type IProperty

type IProperty interface {
	// GetType returns the Type of the property.
	GetType() Type
	// GetValue returns the Value of the property.
	GetValue() Value
	// GetNumber returns the underlay value as a number,
	// if not found, returns false.
	GetNumber() (any, bool, error)
	// GetUint64 returns the underlay value as uint64,
	// if not found, returns false.
	GetUint64() (uint64, bool, error)
	// GetUint32 returns the underlay value as uint32,
	// if not found, returns false.
	GetUint32() (uint32, bool, error)
	// GetUint16 returns the underlay value as uint16,
	// if not found, returns false.
	GetUint16() (uint16, bool, error)
	// GetUint8 returns the underlay value as uint8,
	// if not found, returns false.
	GetUint8() (uint8, bool, error)
	// GetUint returns the underlay value as uint,
	// if not found, returns false.
	GetUint() (uint, bool, error)
	// GetInt64 returns the underlay value as int64,
	// if not found, returns false.
	GetInt64() (int64, bool, error)
	// GetInt32 returns the underlay value as int32,
	// if not found, returns false.
	GetInt32() (int32, bool, error)
	// GetInt16 returns the underlay value as int16,
	// if not found, returns false.
	GetInt16() (int16, bool, error)
	// GetInt8 returns the underlay value as int8,
	// if not found, returns false.
	GetInt8() (int8, bool, error)
	// GetInt returns the underlay value as int,
	// if not found, returns false.
	GetInt() (int, bool, error)
	// GetFloat64 returns the underlay value as float64,
	// if not found, returns false.
	GetFloat64() (float64, bool, error)
	// GetFloat32 returns the underlay value as float32,
	// if not found, returns false.
	GetFloat32() (float32, bool, error)
	// GetDuration returns the underlay value as time.Duration,
	// if not found, returns false.
	GetDuration() (time.Duration, bool, error)
	// GetBool returns the underlay value as bool,
	// if not found, returns false.
	GetBool() (bool, bool, error)
	// GetString returns the underlay value as string,
	// if not found, returns false.
	GetString() (string, bool, error)
	// Cty returns the cty.Type and cty.Value of this value.
	Cty() (cty.Type, cty.Value, error)
}

IProperty holds the functions of the property.

type Properties

type Properties map[string]Property

Properties holds the Property collection in map, the key of map is the name of Property, stores into json.

func (Properties) Cty

func (i Properties) Cty() (cty.Type, cty.Value, error)

Cty returns the type and value of this property.

func (*Properties) Scan

func (i *Properties) Scan(src any) error

Scan implements sql.Scanner.

func (Properties) TypedValues

func (i Properties) TypedValues() (m map[string]any, err error)

TypedValues returns a map stores the typed value.

func (Properties) Value

func (i Properties) Value() (driver.Value, error)

Value implements driver.Valuer.

func (Properties) Values

func (i Properties) Values() Values

Values returns a map stores the underlay value.

type Property

type Property struct {
	// Type specifies the type of this property.
	Type Type `json:"type"`
	// Value specifies the value of this property.
	Value Value `json:"value,omitempty"`
}

Property holds the type and underlay value of the property.

func AnyProperty

func AnyProperty(v any) Property

AnyProperty wraps any value into a property.

func BoolProperty

func BoolProperty(v bool) Property

BoolProperty wraps bool value into a property.

func DurationProperty

func DurationProperty(v time.Duration) Property

DurationProperty wraps time.Duration value into a property.

func Float32Property

func Float32Property(v float32) Property

Float32Property wraps float32 value into a property.

func Float64Property

func Float64Property(v float64) Property

Float64Property wraps float64 value into a property.

func Int16Property

func Int16Property(v int16) Property

Int16Property wraps int16 value into a property.

func Int32Property

func Int32Property(v int32) Property

Int32Property wraps int32 value into a property.

func Int64Property

func Int64Property(v int64) Property

Int64Property wraps int64 value into a property.

func Int8Property

func Int8Property(v int8) Property

Int8Property wraps int8 value into a property.

func IntProperty

func IntProperty(v int) Property

IntProperty wraps int value into a property.

func MapProperty

func MapProperty[T any](v map[string]T) Property

MapProperty wraps map value into a property.

func ObjectProperty

func ObjectProperty[T any](v T) Property

ObjectProperty wraps object value into a property.

func SetProperty

func SetProperty[T comparable](v sets.Set[T]) Property

SetProperty wraps set value into a property.

func SliceProperty

func SliceProperty[T any](v []T) Property

SliceProperty wraps slice value into a property.

func StringProperty

func StringProperty(v string) Property

StringProperty wraps string value into a property.

func Uint16Property

func Uint16Property(v uint16) Property

Uint16Property wraps uint16 value into a property.

func Uint32Property

func Uint32Property(v uint32) Property

Uint32Property wraps uint32 value into a property.

func Uint64Property

func Uint64Property(v uint64) Property

Uint64Property wraps uint64 value into a property.

func Uint8Property

func Uint8Property(v uint8) Property

Uint8Property wraps uint8 value into a property.

func UintProperty

func UintProperty(v uint) Property

UintProperty wraps uint value into a property.

func (Property) Cty

func (i Property) Cty() (cty.Type, cty.Value, error)

func (Property) GetBool

func (i Property) GetBool() (bool, bool, error)

func (Property) GetDuration

func (i Property) GetDuration() (time.Duration, bool, error)

func (Property) GetFloat32

func (i Property) GetFloat32() (float32, bool, error)

func (Property) GetFloat64

func (i Property) GetFloat64() (float64, bool, error)

func (Property) GetInt

func (i Property) GetInt() (int, bool, error)

func (Property) GetInt16

func (i Property) GetInt16() (int16, bool, error)

func (Property) GetInt32

func (i Property) GetInt32() (int32, bool, error)

func (Property) GetInt64

func (i Property) GetInt64() (int64, bool, error)

func (Property) GetInt8

func (i Property) GetInt8() (int8, bool, error)

func (Property) GetNumber

func (i Property) GetNumber() (any, bool, error)

func (Property) GetString

func (i Property) GetString() (string, bool, error)

func (Property) GetType

func (i Property) GetType() Type

func (Property) GetUint

func (i Property) GetUint() (uint, bool, error)

func (Property) GetUint16

func (i Property) GetUint16() (uint16, bool, error)

func (Property) GetUint32

func (i Property) GetUint32() (uint32, bool, error)

func (Property) GetUint64

func (i Property) GetUint64() (uint64, bool, error)

func (Property) GetUint8

func (i Property) GetUint8() (uint8, bool, error)

func (Property) GetValue

func (i Property) GetValue() Value

type Schema

type Schema struct {
	// Name specifies the name of this property.
	Name string `json:"name"`
	// Description specifies the description of this property.
	Description string `json:"description,omitempty"`
	// Type specifies the type of this property.
	Type Type `json:"type"`
	// Default specifies the default value of this property.
	Default Value `json:"default,omitempty"`
	// Value argument takes an expression whose result is to generate value.
	Value []byte `json:"value,omitempty"`
	// Required indicates this property is required or not.
	Required bool `json:"required,omitempty"`
	// Sensitive indicates this property is sensitive or not.
	Sensitive bool `json:"sensitive,omitempty"`
	// Label specifies the UI label of this property.
	Label string `json:"label,omitempty"`
	// Group specifies the UI group of this property,
	// combines multiple levels with a slash.
	Group string `json:"group,omitempty"`
	// Options specifies available options of this property when the type is string.
	Options []Value `json:"options,omitempty"`
	// ShowIf specifies to show this property if the condition is true,
	// e.g. ShowIf: foo=bar.
	ShowIf string `json:"showIf,omitempty"`
	// Hidden specifies the field should be hidden or not,
	// default is visible.
	Hidden bool `json:"hidden,omitempty"`
}

Schema holds the schema of the property.

func AnySchema

func AnySchema(n string, d any) Schema

AnySchema returns any schema.

func BoolSchema

func BoolSchema(n string, d *bool) Schema

BoolSchema returns bool schema.

func DurationSchema

func DurationSchema(n string, d *time.Duration) Schema

DurationSchema returns time.Duration schema.

func Float32Schema

func Float32Schema(n string, d *float32) Schema

Float32Schema returns float32 schema.

func Float64Schema

func Float64Schema(n string, d *float64) Schema

Float64Schema returns float64 schema.

func GuessSchema

func GuessSchema(n, t string, d any) (Schema, error)

GuessSchema guesses the schema with the given type and data, returns any schema if blank type and nil data(in fact, terraform validation must not let this pass), returns implied type schema if data is not nil, returns parsed type schema if type is not blank.

func Int16Schema

func Int16Schema(n string, d *int16) Schema

Int16Schema returns int16 schema.

func Int32Schema

func Int32Schema(n string, d *int32) Schema

Int32Schema returns int32 schema.

func Int64Schema

func Int64Schema(n string, d *int64) Schema

Int64Schema returns int64 schema.

func Int8Schema

func Int8Schema(n string, d *int8) Schema

Int8Schema returns int8 schema.

func IntSchema

func IntSchema(n string, d *int) Schema

IntSchema returns int schema.

func MapSchema

func MapSchema[T any](n string, d map[string]T) Schema

MapSchema returns map[string]T schema.

func ObjectSchema

func ObjectSchema[T any](n string, d T) Schema

ObjectSchema returns T schema.

func SetSchema

func SetSchema[T comparable](n string, d []T) Schema

SetSchema returns sets.Set[T] schema.

func SliceSchema

func SliceSchema[T any](n string, d []T) Schema

SliceSchema returns []T schema.

func StringSchema

func StringSchema(n string, d *string) Schema

StringSchema returns string schema.

func Uint16Schema

func Uint16Schema(n string, d *uint16) Schema

Uint16Schema returns uint16 schema.

func Uint32Schema

func Uint32Schema(n string, d *uint32) Schema

Uint32Schema returns uint32 schema.

func Uint64Schema

func Uint64Schema(n string, d *uint64) Schema

Uint64Schema returns uint64 schema.

func Uint8Schema

func Uint8Schema(n string, d *uint8) Schema

Uint8Schema returns uint8 schema.

func UintSchema

func UintSchema(n string, d *uint) Schema

UintSchema returns uint schema.

func (Schema) WithDescription

func (i Schema) WithDescription(d string) Schema

WithDescription indicates the description of schema.

func (Schema) WithGroup

func (i Schema) WithGroup(g string) Schema

WithGroup indicates the group of schema.

func (Schema) WithHidden

func (i Schema) WithHidden() Schema

WithHidden indicates the schema is hidden.

func (Schema) WithLabel

func (i Schema) WithLabel(l string) Schema

WithLabel indicates the label of schema.

func (Schema) WithOptions

func (i Schema) WithOptions(o ...Value) Schema

WithOptions indicates the options of schema.

func (Schema) WithRequired

func (i Schema) WithRequired() Schema

WithRequired indicates the schema is required.

func (Schema) WithSensitive

func (i Schema) WithSensitive() Schema

WithSensitive indicates the schema is sensitive.

func (Schema) WithShowIf

func (i Schema) WithShowIf(s string) Schema

WithShowIf indicates the condition of schema.

func (Schema) WithValue

func (i Schema) WithValue(expr []byte) Schema

WithValue indicates the value expression of schema.

type Schemas

type Schemas []Schema

Schemas holds the Schema collection in slice, stores into json.

func (*Schemas) Scan

func (i *Schemas) Scan(src any) error

Scan implements sql.Scanner.

func (Schemas) Value

func (i Schemas) Value() (driver.Value, error)

Value implements driver.Valuer.

type Type

type Type = cty.Type

Type indicates the type of property, supported types described as below.

|          Definition           |           JSON Output         |
| ----------------------------- | ----------------------------- |
| any                           | "dynamic"                     |
|                               |                               |
| string                        | "string"                      |
|                               |                               |
| number                        | "number"                      |
|                               |                               |
| bool                          | "bool"                        |
|                               |                               |
| map(any)                      | [                             |
|                               |   "map",                      |
|                               |   "dynamic"                   |
|                               | ]                             |
| map(string)                   | [                             |
|                               |   "map",                      |
|                               |   "string"                    |
|                               | ]                             |
|                               |                               |
| list(string)                  | [                             |
|                               |   "list",                     |
|                               |   "string"                    |
|                               | ]                             |
|                               |                               |
| list(object({                 | [                             |
|   a = string                  |   "list",                     |
|   b = number                  |   [                           |
|   c = bool                    |     "object",                 |
| }))                           |     {                         |
|                               |       "a":"string",           |
|                               |       "b":"number",           |
|                               |       "c":"bool"              |
|                               |     }                         |
|                               |   ]                           |
|                               | ]                             |
|                               |                               |
| object({                      | [                             |
|   a = string                  |   "object",                   |
|   b = number                  |   {                           |
|   c = bool                    |     "a":"string",             |
| })                            |     "b":"number",             |
|                               |     "c":"bool"                |
|                               |   }                           |
|                               | ]                             |
|                               |                               |
| object({                      | [                             |
|   a = string                  |  "object",                    |
|   b = list(object({           |  {                            |
|     c = bool                  |    "a":"string",              |
|   }))                         |    "b":[                      |
| })                            |         "list",               |
|                               |         [                     |
|                               |          "object",            |
|                               |          {                    |
|                               |            "c":"bool"         |
|                               |          }                    |
|                               |         ]                     |
|                               |        ]                      |
|                               |  }                            |
|                               | ]                             |
|                               |                               |
| tuple([string, bool, number]) | [                             |
|                               |   "tuple",                    |
|                               |   [                           |
|                               |     "string",                 |
|                               |     "bool",                   |
|                               |     "number"                  |
|                               |   ]                           |
|                               | ]                             |

type Value

type Value = json.RawMessage

Value indicates the value of property.

type Values

type Values map[string]Value

Values holds the Value collection in map, the key of map is the name of Property, stores into json.

func (*Values) Scan

func (i *Values) Scan(src any) error

Scan implements sql.Scanner.

func (Values) StringTypesWith

func (i Values) StringTypesWith(schemas Schemas) map[string]string

StringTypesWith is similar with TypesWith, but returns the property type in string.

func (Values) TypesWith

func (i Values) TypesWith(schemas Schemas) map[string]Type

TypesWith aligns the property name and type with the given property.Schemas.

func (Values) ValidateWith

func (i Values) ValidateWith(schemas Schemas) error

ValidateWith validates the property value with the given schemas.

func (Values) Value

func (i Values) Value() (driver.Value, error)

Value implements driver.Valuer.

Jump to

Keyboard shortcuts

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