input

package
v0.0.38 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAbsoluteRootPathForTest

func GetAbsoluteRootPathForTest() string

func GetAbsoluteSchemaPathForTest

func GetAbsoluteSchemaPathForTest() string

func GetRawSchema added in v0.0.37

func GetRawSchema(dirPath string, fromTest bool) ([]byte, error)

func InverseFieldEdgeEqual added in v0.0.38

func InverseFieldEdgeEqual(existing, inverseFieldEdge *InverseFieldEdge) bool

func NodeEqual added in v0.0.38

func NodeEqual(existing, node *Node) bool

func PatternEqual added in v0.0.38

func PatternEqual(existing, pattern *Pattern) bool

func PolymorphicOptionsEqual added in v0.0.38

func PolymorphicOptionsEqual(existing, p *PolymorphicOptions) bool

Types

type Action

type Action struct {
	// Note that anytime anything changes here, have to update actionEqual in compare.go
	Operation         ent.ActionOperation `json:"operation,omitempty"`
	Fields            []string            `json:"fields,omitempty"`
	ExcludedFields    []string            `json:"excludedFields,omitempty"`
	OptionalFields    []string            `json:"optionalFields,omitempty"`
	RequiredFields    []string            `json:"requiredFields,omitempty"`
	NoFields          bool                `json:"noFields,omitempty"`
	CustomActionName  string              `json:"actionName,omitempty"`
	CustomGraphQLName string              `json:"graphQLName,omitempty"`
	CustomInputName   string              `json:"inputName,omitempty"`
	HideFromGraphQL   bool                `json:"hideFromGraphQL,omitempty"`
	ActionOnlyFields  []*ActionField      `json:"actionOnlyFields,omitempty"`
}

func (*Action) GetTSStringOperation

func (a *Action) GetTSStringOperation() string

type ActionField

type ActionField struct {
	// Note that anytime anything changes here, have to update actionOnlyFieldEqual in compare.go
	Name     string
	Type     ActionType
	Nullable bool

	ActionName     string
	ExcludedFields []string
	// contains filtered or unexported fields
}

func (*ActionField) GetEntType

func (f *ActionField) GetEntType(inputName string) (enttype.TSGraphQLType, error)

func (*ActionField) MarshalJSON added in v0.0.38

func (f *ActionField) MarshalJSON() ([]byte, error)

func (*ActionField) UnmarshalJSON

func (f *ActionField) UnmarshalJSON(data []byte) error

type ActionType

type ActionType string
const (
	// Note that these types should match ActionField.Type in schema.ts
	ActionTypeID      ActionType = "ID"
	ActionTypeBoolean ActionType = "Boolean"
	ActionTypeInt     ActionType = "Int"
	ActionTypeFloat   ActionType = "Float"
	ActionTypeString  ActionType = "String"
	ActionTypeTime    ActionType = "Time"
	ActionTypeObject  ActionType = "Object"
)

type AssocEdge

type AssocEdge struct {
	// Note that anytime anything changes here, have to update assocEdgeEqual in compare.go
	Name        string            `json:"name,omitempty"`
	SchemaName  string            `json:"schemaName,omitempty"`
	Symmetric   bool              `json:"symmetric,omitempty"`
	Unique      bool              `json:"unique,omitempty"`
	TableName   string            `json:"tableName,omitempty"`
	InverseEdge *InverseAssocEdge `json:"inverseEdge,omitempty"`
	EdgeActions []*EdgeAction     `json:"edgeActions,omitempty"`
	// Go specific
	EntConfig       *schemaparser.EntConfigInfo `json:"-"`
	HideFromGraphQL bool                        `json:"hideFromGraphQL,omitempty"`
	EdgeConstName   string                      `json:"edgeConstName,omitempty"`
	PatternName     string                      `json:"patternName,omitempty"`
}

type AssocEdgeGroup

type AssocEdgeGroup struct {
	// Note that anytime anything changes here, have to update assocEdgeGroupEqual in compare.go
	Name            string        `json:"name,omitempty"`
	GroupStatusName string        `json:"groupStatusName,omitempty"`
	TableName       string        `json:"tableName,omitempty"`
	AssocEdges      []*AssocEdge  `json:"assocEdges,omitempty"`
	EdgeActions     []*EdgeAction `json:"edgeActions,omitempty"`
	StatusEnums     []string      `json:"statusEnums,omitempty"`
	NullStateFn     string        `json:"nullStateFn,omitempty"`
	NullStates      []string      `json:"nullStates,omitempty"`

	// TS specific
	EdgeAction *EdgeAction `json:"edgeAction,omitempty"`

	// Go specific
	ActionEdges []string `json:"-"`
}

func (*AssocEdgeGroup) AddAssocEdge

func (g *AssocEdgeGroup) AddAssocEdge(edge *AssocEdge)

type Constraint

type Constraint struct {
	// Note that anytime anything changes here, have to update constraintEqual in compare.go
	Name       string          `json:"name,omitempty"`
	Type       ConstraintType  `json:"type,omitempty"`
	Columns    []string        `json:"columns,omitempty"`
	ForeignKey *ForeignKeyInfo `json:"fkey,omitempty"`
	Condition  string          `json:"condition,omitempty"`
}

func (*Constraint) GetConstraintTypeString

func (c *Constraint) GetConstraintTypeString() string

type ConstraintType

type ConstraintType string
const (
	// Note that these type should match enum ConstraintType in schema.ts
	PrimaryKeyConstraint ConstraintType = "primary"
	ForeignKeyConstraint ConstraintType = "foreign"
	UniqueConstraint     ConstraintType = "unique"
	CheckConstraint      ConstraintType = "check"
)

type CustomType

type CustomType string
const (
	EmailType    CustomType = "email"
	PhoneType    CustomType = "phone"
	PasswordType CustomType = "password"
)

type DBType

type DBType string
const (
	// Note that these types should match enum DBType in schema.ts
	UUID        DBType = "UUID"
	Int64ID     DBType = "Int64ID"
	Boolean     DBType = "Boolean"
	Int         DBType = "Int"
	BigInt      DBType = "BigInt"
	Float       DBType = "Float"
	String      DBType = "String"
	Timestamp   DBType = "Timestamp"
	Timestamptz DBType = "Timestamptz"
	Time        DBType = "Time"
	Timetz      DBType = "Timetz"
	Date        DBType = "Date"
	JSON        DBType = "JSON"
	JSONB       DBType = "JSONB"
	Enum        DBType = "Enum"
	StringEnum  DBType = "StringEnum"
	List        DBType = "List"
)

type EdgeAction

type EdgeAction struct {
	// Note that anytime anything changes here, have to update edgeActionEqual in compare.go
	Operation         ent.ActionOperation `json:"operation,omitempty"`
	CustomActionName  string              `json:"actionName,omitempty"`
	CustomGraphQLName string              `json:"graphQLName,omitempty"`
	CustomInputName   string              `json:"inputName,omitempty"`
	HideFromGraphQL   bool                `json:"hideFromGraphQL,omitempty"`
	ActionOnlyFields  []*ActionField      `json:"actionOnlyFields,omitempty"`
}

func (*EdgeAction) GetTSStringOperation

func (e *EdgeAction) GetTSStringOperation() string

type Field

type Field struct {
	// Note that anytime anything changes here, have to update fieldEqual in compare.go
	Name       string     `json:"name,omitempty"`
	Type       *FieldType `json:"type,omitempty"`
	Nullable   bool       `json:"nullable,omitempty"`
	StorageKey string     `json:"storageKey,omitempty"`
	// TODO need a way to indicate unique edge is Required also. this changes type generated in ent and graphql
	Unique                  bool   `json:"unique,omitempty"`
	HideFromGraphQL         bool   `json:"hideFromGraphQL,omitempty"`
	Private                 bool   `json:"private,omitempty"`
	GraphQLName             string `json:"graphqlName,omitempty"`
	Index                   bool   `json:"index,omitempty"`
	PrimaryKey              bool   `json:"primaryKey,omitempty"`
	DefaultToViewerOnCreate bool   `json:"defaultToViewerOnCreate,omitempty"`

	FieldEdge     *FieldEdge  `json:"fieldEdge,omitempty"` // this only really makes sense on id fields...
	ForeignKey    *ForeignKey `json:"foreignKey,omitempty"`
	ServerDefault interface{} `json:"serverDefault,omitempty"`
	// DisableUserEditable true == DefaultValueOnCreate required OR set in trigger
	DisableUserEditable        bool `json:"disableUserEditable,omitempty"`
	DisableUserGraphQLEditable bool `json:"disableUserGraphQLEditable,omitempty"`
	HasDefaultValueOnCreate    bool `json:"hasDefaultValueOnCreate,omitempty"`
	HasDefaultValueOnEdit      bool `json:"hasDefaultValueOnEdit,omitempty"`

	Polymorphic         *PolymorphicOptions `json:"polymorphic,omitempty"`
	DerivedWhenEmbedded bool                `json:"derivedWhenEmbedded,omitempty"`
	DerivedFields       []*Field            `json:"derivedFields,omitempty"`

	// Go specific information here
	TagMap          map[string]string `json:"-"`
	GoType          types.Type        `json:"-"`
	PkgPath         string            `json:"-"`
	DataTypePkgPath string            `json:"-"`

	// set when parsed via tsent generate schema
	Import enttype.Import `json:"-"`

	PatternName string `json:"patternName,omitempty"`
}

func (*Field) GetEntType

func (f *Field) GetEntType() (enttype.TSGraphQLType, error)

func (*Field) GetImport

func (f *Field) GetImport() (enttype.Import, error)

type FieldEdge

type FieldEdge struct {
	// Note that anytime anything changes here, have to update fieldEdgeEqual in compare.go
	Schema             string            `json:"schema,omitempty"`
	InverseEdge        *InverseFieldEdge `json:"inverseEdge,omitempty"`
	DisableBuilderType bool              `json:"disableBuilderType,omitempty"`
}

func (*FieldEdge) InverseEdgeName added in v0.0.35

func (f *FieldEdge) InverseEdgeName() string

type FieldType

type FieldType struct {
	// Note that anytime anything changes here, have to update fieldTypeEqual in compare.go
	DBType DBType `json:"dbType,omitempty"`
	// required when DBType == DBType.List
	ListElemType *FieldType `json:"listElemType,omitempty"`
	// required when DBType == DBType.Enum || DBType.StringEnum
	Values      []string          `json:"values,omitempty"`
	EnumMap     map[string]string `json:"enumMap,omitempty"`
	Type        string            `json:"type,omitempty"`
	GraphQLType string            `json:"graphQLType,omitempty"`
	// optional used by generator to specify different types e.g. email, phone, password
	CustomType CustomType `json:"customType,omitempty"`

	ImportType *tsimport.ImportPath `json:"importType,omitempty"`
}

type ForeignKey

type ForeignKey struct {
	// Note that anytime anything changes here, have to update foreignKeyEqual in compare.go
	Schema             string `json:"schema,omitempty"`
	Column             string `json:"column,omitempty"`
	Name               string `json:"name,omitempty"`
	DisableIndex       bool   `json:"disableIndex,omitempty"`
	DisableBuilderType bool   `json:"disableBuilderType,omitempty"`
}

type ForeignKeyInfo

type ForeignKeyInfo struct {
	// Note that anytime anything changes here, have to update foreignKeyInfoEqual in compare.go
	TableName string       `json:"tableName,omitempty"`
	Columns   []string     `json:"columns,omitempty"`
	OnDelete  OnDeleteFkey `json:"ondelete,omitempty"`
}

type Index

type Index struct {
	// Note that anytime anything changes here, have to update indexEqual in compare.go
	Name    string   `json:"name,omitempty"`
	Columns []string `json:"columns,omitempty"`
	Unique  bool     `json:"unique,omitempty"`
}

type InverseAssocEdge

type InverseAssocEdge struct {
	// Note that anytime anything changes here, have to update inverseAssocEdgeEqual in compare.go
	// TODO need to be able to mark this as unique
	// this is an easy way to get 1->many
	Name          string `json:"name,omitempty"`
	EdgeConstName string `json:"edgeConstName,omitempty"`
}

type InverseFieldEdge added in v0.0.35

type InverseFieldEdge struct {
	// Note that anytime anything changes here, have to update InverseFieldEdgeEqual in compare.go
	Name            string `json:"name,omitempty"`
	TableName       string `json:"tableName,omitempty"`
	HideFromGraphQL bool   `json:"hideFromGraphQL,omitempty"`
	EdgeConstName   string `json:"edgeConstName,omitempty"`
}

type Node

type Node struct {
	// Note that anytime anything changes here, have to update nodeEqual in compare.go
	TableName       string                   `json:"tableName,omitempty"`
	Fields          []*Field                 `json:"fields,omitempty"`
	AssocEdges      []*AssocEdge             `json:"assocEdges,omitempty"`
	AssocEdgeGroups []*AssocEdgeGroup        `json:"assocEdgeGroups,omitempty"`
	Actions         []*Action                `json:"actions,omitempty"`
	EnumTable       bool                     `json:"enumTable,omitempty"`
	DBRows          []map[string]interface{} `json:"dbRows,omitempty"`
	Constraints     []*Constraint            `json:"constraints,omitempty"`
	Indices         []*Index                 `json:"indices,omitempty"`
	HideFromGraphQL bool                     `json:"hideFromGraphQL,omitempty"`
	EdgeConstName   string                   `json:"edgeConstName,omitempty"`
	PatternName     string                   `json:"patternName,omitempty"`
}

func (*Node) AddAssocEdge

func (n *Node) AddAssocEdge(edge *AssocEdge)

func (*Node) AddAssocEdgeGroup

func (n *Node) AddAssocEdgeGroup(edgeGroup *AssocEdgeGroup)

type NullableItem

type NullableItem string
const NullableContents NullableItem = "contents"
const NullableContentsAndList NullableItem = "contentsAndList"
const NullableTrue NullableItem = "true"

type OnDeleteFkey

type OnDeleteFkey string
const (
	// Note that these type should match enum ForeignKeyInfo.ondelete in schema.ts
	Restrict   OnDeleteFkey = "RESTRICT"
	Cascade    OnDeleteFkey = "CASCADE"
	SetNull    OnDeleteFkey = "SET NULL"
	SetDefault OnDeleteFkey = "SET DEFAULT"
	NoAction   OnDeleteFkey = "NO ACTION"
)

type Pattern

type Pattern struct {
	// Note that anytime anything changes here, have to update patternEqual in compare.go
	Name string `json:"name,omitempty"`
	// at this point, should we support everything in Node
	Fields     []*Field     `json:"fields,omitempty"`
	AssocEdges []*AssocEdge `json:"assocEdges,omitempty"`
}

type PolymorphicOptions

type PolymorphicOptions struct {
	// Note that anytime anything changes here, have to update PolymorphicOptionsEqual in compare.go
	Types                  []string `json:"types,omitempty"`
	HideFromInverseGraphQL bool     `json:"hideFromInverseGraphQL,omitempty"`
	DisableBuilderType     bool     `json:"disableBuilderType,omitempty"`
}

type Schema

type Schema struct {
	Nodes    map[string]*Node    `json:"schemas,omitempty"`
	Patterns map[string]*Pattern `json:"patterns,omitempty"`
}

func ParseSchema

func ParseSchema(input []byte) (*Schema, error)

func ParseSchemaFromTSDir

func ParseSchemaFromTSDir(dirPath string, fromTest bool) (*Schema, error)

TODO: environment variable flag for fromTest instead of passing it in TODO: environment variable or flag for src/schema path instead of hardcoding it here

Jump to

Keyboard shortcuts

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