internal

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2024 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, strategy WriteFileStrategy) error

WritePrettyFileJSON writes JSON data with indent

Types

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 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 ObjectField added in v1.4.0

type ObjectField struct {
	Name        string
	Description *string
	Type        *TypeInfo
}

ObjectField represents the serialization information of an object field

type ObjectInfo added in v1.4.0

type ObjectInfo struct {
	IsAnonymous bool
	Type        *TypeInfo
	Fields      map[string]ObjectField
}

ObjectInfo represents the serialization information of an object type

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    *TypeInfo
}

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
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
	CustomScalars     map[string]*TypeInfo
	ScalarSchemas     schema.SchemaResponseScalarTypes
	Objects           map[string]ObjectInfo
	ObjectSchemas     schema.SchemaResponseObjectTypes
	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) Schema added in v1.4.0

Schema converts to a NDC schema

func (RawConnectorSchema) WriteGoSchema added in v1.4.0

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

WriteGoSchema writes the schema as Go codes

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"
	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"
)

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 TypeInfo added in v1.4.0

type TypeInfo struct {
	Name                 string
	SchemaName           string
	Description          *string
	PackagePath          string
	PackageName          string
	Embedded             bool
	IsScalar             bool
	ScalarRepresentation schema.TypeRepresentation
	TypeFragments        []string
	TypeAST              types.Type
	Schema               schema.TypeEncoder
}

TypeInfo represents the serialization information of a type

func (*TypeInfo) GetArgumentName added in v1.4.0

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

GetArgumentName returns the argument name

func (*TypeInfo) IsArray added in v1.4.0

func (ti *TypeInfo) IsArray() bool

IsArray checks if the current type is an array

func (*TypeInfo) IsNullable added in v1.4.0

func (ti *TypeInfo) IsNullable() bool

IsNullable checks if the current type is nullable

func (*TypeInfo) String added in v1.4.0

func (ti *TypeInfo) String() string

String implements the fmt.Stringer interface

type TypeKind added in v1.4.0

type TypeKind string

type WriteFileStrategy

type WriteFileStrategy string

Decide the strategy to do when the written file exists

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

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