internal

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenRandomScalarValue

func GenRandomScalarValue(random *rand.Rand, name string, scalar *schema.ScalarType) any

GenRandomScalarValue generates random scalar value depending on its representation type.

func GenRandomString

func GenRandomString(src *rand.Rand, n int) string

GenRandomString generate random string with fixed length.

func ParseAndGenerateConnector added in v1.4.0

func ParseAndGenerateConnector(args ConnectorGenerationArguments, moduleName string) error

ParseAndGenerateConnector parses and generate connector codes.

func WritePrettyFileJSON

func WritePrettyFileJSON(fileName string, data any) error

WritePrettyFileJSON writes JSON data with indent.

Types

type ArrayType added in v1.6.1

type ArrayType struct {
	ElementType Type
}

ArrayType the information of the array type

func NewArrayType added in v1.6.1

func NewArrayType(input Type) *ArrayType

func (ArrayType) FullName added in v1.6.1

func (t ArrayType) FullName() string

func (*ArrayType) IsAnonymous added in v1.6.1

func (t *ArrayType) IsAnonymous() bool

func (*ArrayType) Kind added in v1.6.1

func (t *ArrayType) Kind() schema.TypeEnum

func (*ArrayType) Schema added in v1.6.1

func (t *ArrayType) Schema() schema.TypeEncoder

func (ArrayType) SchemaName added in v1.6.1

func (t ArrayType) SchemaName(isAbsolute bool) string

func (ArrayType) String added in v1.6.1

func (t ArrayType) String() string

type ConnectorGenerationArguments added in v1.4.0

type ConnectorGenerationArguments struct {
	Path         string   `` /* 135-byte string literal not displayed */
	ConnectorDir string   `help:"The directory where the connector.go file is placed" default:"."`
	Directories  []string `help:"Folders contain NDC operation functions" short:"d"`
	Trace        string   `help:"Enable tracing and write to target file path."`
	SchemaFormat string   `help:"The output format for the connector schema. Accept: json, go" enum:"json,go" default:"json"`
	Style        string   `` /* 134-byte string literal not displayed */
	TypeOnly     bool     `help:"Generate type only" default:"false"`
}

ConnectorGenerationArguments represent input arguments of the ConnectorGenerator.

type Field added in v1.6.1

type Field struct {
	Name        string
	Description *string
	Embedded    bool
	Type        Type
	TypeAST     types.Type
}

Field represents the serialization information of a field.

type FunctionInfo added in v1.4.0

type FunctionInfo OperationInfo

FunctionInfo represents a readable Go function info which can convert to a NDC function schema.

func (FunctionInfo) Schema added in v1.4.0

func (op FunctionInfo) Schema() schema.FunctionInfo

Schema returns a NDC function schema.

type NamedType added in v1.6.1

type NamedType struct {
	Name       string
	NativeType *TypeInfo
}

NamedType the information of a named type

func NewNamedType added in v1.6.1

func NewNamedType(name string, info *TypeInfo) *NamedType

func (NamedType) FullName added in v1.6.1

func (t NamedType) FullName() string

func (*NamedType) IsAnonymous added in v1.6.1

func (t *NamedType) IsAnonymous() bool

func (*NamedType) Kind added in v1.6.1

func (t *NamedType) Kind() schema.TypeEnum

func (*NamedType) Schema added in v1.6.1

func (t *NamedType) Schema() schema.TypeEncoder

func (NamedType) SchemaName added in v1.6.1

func (t NamedType) SchemaName(_ bool) string

func (*NamedType) String added in v1.6.1

func (t *NamedType) String() string

type NullableType added in v1.6.1

type NullableType struct {
	UnderlyingType Type
}

NullableType the information of the nullable type

func NewNullableType added in v1.6.1

func NewNullableType(input Type) *NullableType

func (NullableType) FullName added in v1.6.1

func (t NullableType) FullName() string

func (*NullableType) IsAnonymous added in v1.6.1

func (t *NullableType) IsAnonymous() bool

func (*NullableType) Kind added in v1.6.1

func (t *NullableType) Kind() schema.TypeEnum

func (*NullableType) Schema added in v1.6.1

func (t *NullableType) Schema() schema.TypeEncoder

func (NullableType) SchemaName added in v1.6.1

func (t NullableType) SchemaName(isAbsolute bool) string

func (NullableType) String added in v1.6.1

func (t NullableType) String() string

type ObjectInfo added in v1.4.0

type ObjectInfo struct {
	Description  *string
	Type         *TypeInfo
	Fields       map[string]Field
	SchemaFields schema.ObjectTypeFields
}

ObjectInfo represents the serialization information of an object type.

func (ObjectInfo) Schema added in v1.6.1

func (oi ObjectInfo) Schema() *schema.ObjectType

type OperationInfo added in v1.4.0

type OperationInfo struct {
	Kind          OperationKind
	Name          string
	OriginName    string
	PackageName   string
	PackagePath   string
	Description   *string
	ArgumentsType *TypeInfo
	Arguments     map[string]schema.ArgumentInfo
	ResultType    *Field
}

FunctionInfo represents a readable Go function info which can convert to a NDC function or procedure schema.

type OperationKind added in v1.4.0

type OperationKind string

OperationKind the operation kind of connectors

const (
	OperationFunction  OperationKind = "Function"
	OperationProcedure OperationKind = "Procedure"
)

type OperationNamingStyle added in v1.4.0

type OperationNamingStyle string

OperationNamingStyle the enum for operation naming style.

const (
	StyleCamelCase OperationNamingStyle = "camel-case"
	StyleSnakeCase OperationNamingStyle = "snake-case"
)

func ParseOperationNamingStyle added in v1.4.0

func ParseOperationNamingStyle(input string) (OperationNamingStyle, error)

ParseOperationNamingStyle parses a OperationNamingStyle enum from string.

func (OperationNamingStyle) IsValid added in v1.4.0

func (j OperationNamingStyle) IsValid() bool

IsValid checks if the value is invalid.

type ProcedureInfo added in v1.4.0

type ProcedureInfo FunctionInfo

ProcedureInfo represents a readable Go function info which can convert to a NDC procedure schema.

func (ProcedureInfo) Schema added in v1.4.0

func (op ProcedureInfo) Schema() schema.ProcedureInfo

Schema returns a NDC procedure schema.

type RawConnectorSchema added in v1.4.0

type RawConnectorSchema struct {
	StateType         *TypeInfo
	Imports           map[string]bool
	Scalars           map[string]Scalar
	Objects           map[string]ObjectInfo
	Functions         []FunctionInfo
	FunctionArguments map[string]ObjectInfo
	Procedures        []ProcedureInfo
}

RawConnectorSchema represents a readable Go schema object which can encode to NDC schema.

func NewRawConnectorSchema added in v1.4.0

func NewRawConnectorSchema() *RawConnectorSchema

NewRawConnectorSchema creates an empty RawConnectorSchema instance.

func (RawConnectorSchema) GetScalarFromType added in v1.6.1

func (rcs RawConnectorSchema) GetScalarFromType(ty Type) *Scalar

func (RawConnectorSchema) Schema added in v1.4.0

Schema converts to a NDC schema.

func (*RawConnectorSchema) SetScalar added in v1.6.1

func (rcs *RawConnectorSchema) SetScalar(name string, value Scalar)

func (RawConnectorSchema) WriteGoSchema added in v1.4.0

func (rcs RawConnectorSchema) WriteGoSchema(packageName string) (string, error)

WriteGoSchema writes the schema as Go codes.

type Scalar added in v1.6.1

type Scalar struct {
	Schema     schema.ScalarType
	NativeType *TypeInfo
}

Scalar the structured information of the scalar

type ScalarName added in v1.4.0

type ScalarName string
const (
	ScalarBoolean     ScalarName = "Boolean"
	ScalarString      ScalarName = "String"
	ScalarInt8        ScalarName = "Int8"
	ScalarInt16       ScalarName = "Int16"
	ScalarInt32       ScalarName = "Int32"
	ScalarInt64       ScalarName = "Int64"
	ScalarFloat32     ScalarName = "Float32"
	ScalarFloat64     ScalarName = "Float64"
	ScalarBigInt      ScalarName = "BigInt"
	ScalarBigDecimal  ScalarName = "BigDecimal"
	ScalarUUID        ScalarName = "UUID"
	ScalarDate        ScalarName = "Date"
	ScalarDuration    ScalarName = "Duration"
	ScalarTimestamp   ScalarName = "Timestamp"
	ScalarTimestampTZ ScalarName = "TimestampTZ"
	ScalarGeography   ScalarName = "Geography"
	ScalarBytes       ScalarName = "Bytes"
	ScalarJSON        ScalarName = "JSON"
	// ScalarRawJSON is a special scalar for raw json data serialization.
	// The underlying Go type for this scalar is json.RawMessage.
	// Note: we don't recommend to use this scalar for function arguments
	// because the decoder will re-encode the value to []byte that isn't performance-wise.
	ScalarRawJSON ScalarName = "RawJSON"
	ScalarURL     ScalarName = "URL"
)

type SchemaParser added in v1.4.0

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

func (SchemaParser) FindPackageByPath added in v1.4.0

func (sp SchemaParser) FindPackageByPath(input string) *packages.Package

FindPackageByPath finds the package by package path.

func (SchemaParser) GetCurrentPackage added in v1.4.0

func (sp SchemaParser) GetCurrentPackage() *packages.Package

GetCurrentPackage gets the current evaluating package.

type Type added in v1.6.1

type Type interface {
	Kind() schema.TypeEnum
	Schema() schema.TypeEncoder
	SchemaName(isAbsolute bool) string
	FullName() string
	String() string
	IsAnonymous() bool
}

Type the interface of a type schema

type TypeInfo added in v1.4.0

type TypeInfo struct {
	Name           string
	IsAnonymous    bool
	TypeParameters []Type
	SchemaName     string
	Description    *string
	PackagePath    string
	PackageName    string
	TypeAST        types.Type
}

TypeInfo represents the serialization information of a type.

func (*TypeInfo) CanMethod added in v1.6.1

func (ti *TypeInfo) CanMethod() bool

CanMethod checks whether generating decoding methods for this type.

func (*TypeInfo) GetAbsoluteName added in v1.6.1

func (ti *TypeInfo) GetAbsoluteName() string

GetAbsoluteName return the type name with absolute package paths.

func (*TypeInfo) GetArgumentName added in v1.4.0

func (ti *TypeInfo) GetArgumentName(packagePath string) string

GetArgumentName returns the argument name.

func (*TypeInfo) GetPackagePaths added in v1.6.1

func (ti *TypeInfo) GetPackagePaths(currentPackagePath string) []string

String implements the fmt.Stringer interface.

func (*TypeInfo) String added in v1.4.0

func (ti *TypeInfo) String() string

String implements the fmt.Stringer interface.

type TypeParser added in v1.6.1

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

func NewTypeParser added in v1.6.1

func NewTypeParser(schemaParser *SchemaParser, field *Field, ty types.Type, argumentFor *OperationKind) *TypeParser

func (*TypeParser) Parse added in v1.6.1

func (tp *TypeParser) Parse(fieldPaths []string) (*Field, error)

func (*TypeParser) ParseArgumentTypes added in v1.6.1

func (tp *TypeParser) ParseArgumentTypes(fieldPaths []string) (*ObjectInfo, error)

type WriteFileStrategy

type WriteFileStrategy string

Decide the strategy to do when the written file exists.

const (
	WriteFileStrategyNone           WriteFileStrategy = "none"
	WriteFileStrategyOverride       WriteFileStrategy = "override"
	WriteFileStrategyUpdateResponse WriteFileStrategy = "update_response"
)

func ParseWriteFileStrategy

func ParseWriteFileStrategy(input string) (WriteFileStrategy, error)

ParseWriteFileStrategy parses a WriteFileStrategy enum from string.

Jump to

Keyboard shortcuts

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