input

package
v0.1.0-alpha.46 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareConstraints added in v0.0.39

func CompareConstraints(existing, constraints []*Constraint) []change.Change

func CompareIndices added in v0.0.39

func CompareIndices(existing, indices []*Index) []change.Change

TODO tests...

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

func PrivateOptionsEqual added in v0.1.0

func PrivateOptionsEqual(existing, p *PrivateOptions) bool

func UserConvertTypeEqual added in v0.1.0

func UserConvertTypeEqual(existing, convert *UserConvertType) 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
	HideFromGraphQL bool
	// contains filtered or unexported fields
}

func (*ActionField) GetEntType

func (f *ActionField) GetEntType(inputName string) (enttype.TSType, 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"`
	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"`
	ViewerBased     bool          `json:"viewerBased"`
	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 Config added in v0.1.0

type Config struct {
	// the prettier config that's being used is parsed and sent up to format the files as needed
	// since we're trying to use rome...
	RomeConfig *RomeConfig `json:"rome"`
}

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"
	IntEnum     DBType = "IntEnum"
	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                 *PrivateOptions `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 *string     `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"`
	HasFieldPrivacy            bool `json:"hasFieldPrivacy,omitempty"`

	Polymorphic         *PolymorphicOptions `json:"polymorphic,omitempty"`
	DerivedWhenEmbedded bool                `json:"derivedWhenEmbedded,omitempty"`
	DerivedFields       []*Field            `json:"derivedFields,omitempty"`
	UserConvert         *UserConvertType    `json:"convert,omitempty"`
	FetchOnDemand       bool                `json:"fetchOnDemand,omitempty"`
	DBOnly              bool                `json:"dbOnly,omitempty"`

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

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

func (*Field) ApplyOverride added in v0.1.0

func (f *Field) ApplyOverride(override *FieldOverride)

func (*Field) GetEntType

func (f *Field) GetEntType(nodeName string) (enttype.TSType, error)

need nodeName for enum ideally, there's a more elegant way of doing this in the future but we don't know the parent

func (*Field) GetImport

func (f *Field) GetImport(nodeName string) (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 FieldOverride added in v0.1.0

type FieldOverride struct {
	Nullable        *bool   `json:"nullable,omitempty"`
	StorageKey      string  `json:"storageKey,omitempty"`
	Unique          *bool   `json:"unique,omitempty"`
	HideFromGraphQL *bool   `json:"hideFromGraphQL,omitempty"`
	GraphQLName     string  `json:"graphqlName,omitempty"`
	Index           *bool   `json:"index,omitempty"`
	ServerDefault   *string `json:"serverDefault,omitempty"`
}

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
	// also sometimes used when DBType == JSON or JSONB for json that we store as json(b) in the db but represent as lists
	// in graphql and typescript
	ListElemType *FieldType `json:"listElemType,omitempty"`
	// required when DBType == DBType.Enum || DBType.StringEnum
	Values               []string          `json:"values,omitempty"`
	EnumMap              map[string]string `json:"enumMap,omitempty"`
	IntEnumMap           map[string]int    `json:"intEnumMap,omitempty"`
	DeprecatedIntEnumMap map[string]int    `json:"deprecatedIntEnumMap,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"`
	DisableUnknownType bool       `json:"disableUnknownType"`

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

	// list because go-lang map not stable and don't want generated fields to change often
	SubFields   []*Field `json:"subFields,omitempty"`
	UnionFields []*Field `json:"unionFields,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 FullText added in v0.0.39

type FullText struct {
	GeneratedColumnName string           `json:"generatedColumnName,omitempty"`
	Language            FullTextLanguage `json:"language,omitempty"`
	LanguageColumn      string           `json:"languageColumn,omitempty"`
	IndexType           IndexType        `json:"indexType,omitempty"`
	Weights             *FullTextWeight  `json:"weights,omitempty"`
}

type FullTextLanguage added in v0.0.39

type FullTextLanguage string
const (
	// rename to search config?
	English FullTextLanguage = "english"
	French  FullTextLanguage = "french"
	German  FullTextLanguage = "german"
	Simple  FullTextLanguage = "simple"
)

type FullTextWeight added in v0.0.39

type FullTextWeight struct {
	A []string `json:"A,omitempty"`
	B []string `json:"B,omitempty"`
	C []string `json:"C,omitempty"`
	D []string `json:"D,omitempty"`
}

func (*FullTextWeight) HasWeights added in v0.0.39

func (w *FullTextWeight) HasWeights() bool

type GlobalSchema added in v0.1.0

type GlobalSchema struct {
	ExtraEdgeFields []*Field     `json:"extraEdgeFields,omitempty"`
	GlobalEdges     []*AssocEdge `json:"globalEdges,omitempty"`
	InitForEdges    bool         `json:"initForEdges,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"`
	FullText *FullText `json:"fullText,omitempty"`
	// for regular indices. doesn't apply for full text...
	IndexType IndexType `json:"indexType,omitempty"`
}

type IndexType added in v0.0.39

type IndexType string

full text only supports gin | gist TODO https://github.com/lolopinto/ent/issues/1029 Index only currently supports gin | btree (will eventually support gist)

const (
	Gin   IndexType = "gin"
	Gist  IndexType = "gist"
	Btree IndexType = "btree"
)

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"`
	FieldOverrides   map[string]*FieldOverride `json:"fieldOverrides"`
	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"`
	TransformsSelect bool                      `json:"transformsSelect,omitempty"`
	TransformsDelete bool                      `json:"transformsDelete,omitempty"`
	SchemaPath       string                    `json:"schemaPath,omitempty"`
	Patterns         []string                  `json:"patternNames,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"`
	DisableMixin bool         `json:"disableMixin,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"`
	Name                   string   `json:"name,omitempty"`
}

type PrivateOptions added in v0.1.0

type PrivateOptions struct {
	ExposeToActions bool `json:"exposeToActions,omitempty"`
}

type RomeConfig added in v0.1.0

type RomeConfig struct {
	// we always do --indent-style=space
	IndentStyle     *string `json:"indentStyle"`
	LineWidth       *int    `json:"lineWidth"`
	IndentSize      *int    `json:"indentSize"`
	QuoteStyle      *string `json:"quoteStyle"`
	QuoteProperties *string `json:"quoteProperties"`
	TrailingComma   *string `json:"trailingComma"`
}

indicates the rome onfig that should be used here taken from the prettier config https://prettier.io/docs/en/options.html#quotes https://docs.rome.tools/formatter/#use-the-formatter-with-the-cli

func (*RomeConfig) GetArgs added in v0.1.0

func (cfg *RomeConfig) GetArgs() []string

type Schema

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

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

type UserConvertType added in v0.1.0

type UserConvertType struct {
	Path     string `json:"path,omitempty"`
	Function string `json:"function,omitempty"`
}

Jump to

Keyboard shortcuts

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