codegen

package
v0.9.10 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CustomTargetResource = "resource"
	CustomTargetModel    = "model"
)

Variables

This section is empty.

Functions

func PrefixDropper

func PrefixDropper(prefix string) dstutil.ApplyFunc

PrefixDropper returns a dstutil.ApplyFunc that removes the provided prefix string when it appears as a leading sequence in type names, var names, and comments in a generated Go file.

func PrefixReplacer

func PrefixReplacer(prefix, replace string) dstutil.ApplyFunc

PrefixReplacer returns a dstutil.ApplyFunc that removes the provided prefix string when it appears as a leading sequence in type names, var names, and comments in a generated Go file.

When an exact match for prefix is found, the provided replace string is substituted.

Types

type CRDOutputEncoder

type CRDOutputEncoder func(any) ([]byte, error)

CRDOutputEncoder is a function which marshals an object into a desired output format

type CustomKindParser

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

CustomKindParser allows for parsing of github.com/grafana/thema cue Lineages, encapsulated as grafana CustomStructured kinds. The parser can validate inputs for correctness, and can generate codegen metadata objects from the provided CUE and pass them off to a Generator.

The CustomKindParser currently understands only grafana CustomStructured CUE types, with plans to support Thema #CRD types in the future.

func NewCustomKindParser

func NewCustomKindParser(rt *thema.Runtime, modFS fs.FS) (*CustomKindParser, error)

NewCustomKindParser creates a new CustomKindParser from the provided thema.Runtime and fs.FS. The fs should contain the cue.mod directory as well as any cue files expected to be parsed by the CustomKindParser. If thema cannot parse the provided fs.FS, an error will be returned.

func (*CustomKindParser) FilteredGenerate

func (g *CustomKindParser) FilteredGenerate(generator FilteredGenerator, selectors ...string) (codejen.Files, error)

FilteredGenerate parses the provided selectors, checks the parsed object against generator.Allowed(), and passes the resulting list of filtered objects to the FilteredGenerator, returning the files created from each step. If no selectors are passed, all supported selectors will be used.

func (*CustomKindParser) Generate

func (g *CustomKindParser) Generate(generator Generator, selectors ...string) (codejen.Files, error)

Generate parses the provided selectors and passes the parsed values to the Generator, returning the files created from each step. If no selectors are passed, all top-level declarations will be used.

func (*CustomKindParser) ListAllMainSelectors

func (g *CustomKindParser) ListAllMainSelectors() ([]string, error)

ListAllMainSelectors returns a list of string selectors that are top-level declarations in the CUE runtime. These selectors are the ones which will be considered by default in calls to Validate, Generate, and FilteredGenerate if no selectors are supplied.

func (*CustomKindParser) Validate

func (g *CustomKindParser) Validate(selectors ...string) (map[string]multierror.Error, error)

Validate validates the provided selectors, returning a map of <selector> -> <validation error list>. If no validation errors are found, len(map) will be 0. If no selectors are provided, all top-level declarations will be validated.

type FilteredGenerator

type FilteredGenerator interface {
	Generator
	// Allowed returns true if the Generator can be used for this particular object
	Allowed(kindsys.Custom) bool
}

FilteredGenerator allows a Generator to express an opinion on whether it should be used for a particular Custom-implementing type. When Allowed returns false, the Generator may return an error on Generate.

func Filter

func Filter(g Generator, filterFunc func(kindsys.Custom) bool) FilteredGenerator

Filter wraps a Generator to create a FilteredGenerator, using the supplied filterFunc to create the Allowed and Filter functions of the FilteredGenerator.

type Generator

type Generator interface {
	Generate(objs ...kindsys.Custom) (codejen.Files, error)
}

Generator is an interface which describes any code generator that can be passed to a Parser, such as CustomKindParser.

func BackendPluginGenerator

func BackendPluginGenerator(projectRepo, generatedAPIPath string) Generator

BackendPluginGenerator returns a Generator which will produce boilerplate backend plugin code

func CRDGenerator

func CRDGenerator(outputEncoder CRDOutputEncoder, outputExtension string) Generator

CRDGenerator returns a Generator which will create a CRD file

func ModelsGenerator

func ModelsGenerator() Generator

ModelsGenerator returns a Generator which will produce Go and CUE files for API contract models

func OperatorGenerator

func OperatorGenerator(projectRepo, codegenPath string) Generator

OperatorGenerator returns a Generator which will build out watcher boilerplate for each resource, and a main func to run an operator for the watchers.

func ResourceGenerator

func ResourceGenerator() Generator

ResourceGenerator returns a Generator which will produce Go and Cue files for using a schema for storage

func TypeScriptModelsGenerator

func TypeScriptModelsGenerator() Generator

TypeScriptModelsGenerator returns a Generator which generates TypeScript model code

type TSTypesJenny

type TSTypesJenny struct{}

TSTypesJenny is a [OneToOne] that produces TypeScript types and defaults for a Thema schema.

Thema's generic TS jenny will be able to replace this one once https://github.com/grafana/thema/issues/89 is complete.

func (TSTypesJenny) Generate

func (j TSTypesJenny) Generate(decl kindsys.Custom) (*codejen.File, error)

func (TSTypesJenny) JennyName

func (TSTypesJenny) JennyName() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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