codegen

package
v0.0.0-...-fb7f86c Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2023 License: AGPL-3.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

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.

func SlashHeaderMapper

func SlashHeaderMapper(maingen string) codejen.FileMapper

SlashHeaderMapper produces a FileMapper that injects a comment header onto a codejen.File indicating the main generator that produced it (via the provided maingen, which should be a path) and the jenny or jennies that constructed the file.

Types

type Any

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

func (*Any) String

func (u *Any) String() string

func (*Any) UnmarshalJSON

func (u *Any) UnmarshalJSON(data []byte) error

type CoreKindJennyConfig

type CoreKindJennyConfig struct {
	// GenDirName returns the name of the directory in which the file should be
	// generated. Defaults to DefForGen.Lineage().Name() if nil.
	GenDirName func(kindsys.Kind) string
}

CoreKindJennyConfig holds configuration options for CoreKindJenny.

type GoTypesJenny

type GoTypesJenny struct {
	ApplyFuncs       []dstutil.ApplyFunc
	ExpandReferences bool
}

GoTypesJenny is a OneToOne that produces Go types for the provided thema.Schema.

func (GoTypesJenny) Generate

func (j GoTypesJenny) Generate(sfg SchemaForGen) (*codejen.File, error)

func (GoTypesJenny) JennyName

func (j GoTypesJenny) JennyName() string

type ManyToMany

type ManyToMany codejen.ManyToMany[kindsys.Kind]

type ManyToOne

type ManyToOne codejen.ManyToOne[kindsys.Kind]

func BaseCoreRegistryJenny

func BaseCoreRegistryJenny(path, kindrelroot string) ManyToOne

BaseCoreRegistryJenny generates a static registry for core kinds that only initializes their kindsys.Kind. No slot kinds are composed.

Path should be the relative path to the directory that will contain the generated registry. kindrelroot should be the repo-root-relative path to the parent directory to all directories that contain generated kind bindings (e.g. pkg/kind).

func TSVeneerIndexJenny

func TSVeneerIndexJenny(dir string) ManyToOne

TSVeneerIndexJenny generates an index.gen.ts file with references to all generated TS types. Elements with the attribute @grafana(TSVeneer="type") are exported from a handwritten file, rather than the raw generated types.

The provided dir is the path, relative to the grafana root, to the directory that should contain the generated index.

Implicitly depends on output patterns in TSTypesJenny. TODO this is wasteful; share-nothing generator model entails re-running the cuetsy gen that TSTypesJenny already did

type OneToMany

type OneToMany codejen.OneToMany[kindsys.Kind]

func LatestMajorsOrXJenny

func LatestMajorsOrXJenny(parentdir string, forceGroup bool, inner codejen.OneToOne[SchemaForGen]) OneToMany

LatestMajorsOrXJenny returns a jenny that repeats the input for the latest in each major version.

TODO remove forceGroup option, it's a temporary hack to accommodate core kinds

type OneToOne

type OneToOne codejen.OneToOne[kindsys.Kind]

func CoreKindJenny

func CoreKindJenny(gokindsdir string, cfg *CoreKindJennyConfig) OneToOne

CoreKindJenny generates the implementation of kindsys.Core for the provided kind declaration.

gokindsdir should be the relative path to the parent directory that contains all generated kinds.

This generator only has output for core structured kinds.

func DocsJenny

func DocsJenny(docsPath string) OneToOne

func LatestJenny

func LatestJenny(parentdir string, inner codejen.OneToOne[SchemaForGen]) OneToOne

LatestJenny returns a jenny that runs another jenny for only the latest schema in a DefForGen, and prefixes the resulting file with the provided parentdir (e.g. "pkg/kinds/") and with a directory based on the kind's machine name (e.g. "dashboard/").

type PropertyType

type PropertyType string
const (
	PropertyTypeString  PropertyType = "string"
	PropertyTypeNumber  PropertyType = "number"
	PropertyTypeBoolean PropertyType = "boolean"
	PropertyTypeObject  PropertyType = "object"
	PropertyTypeArray   PropertyType = "array"
	PropertyTypeNull    PropertyType = "null"
)

type PropertyTypes

type PropertyTypes []PropertyType

func (*PropertyTypes) HasType

func (pts *PropertyTypes) HasType(pt PropertyType) bool

func (*PropertyTypes) UnmarshalJSON

func (pts *PropertyTypes) UnmarshalJSON(data []byte) error

type ResourceGoTypesJenny

type ResourceGoTypesJenny struct {
	ApplyFuncs       []dstutil.ApplyFunc
	ExpandReferences bool
}

func (*ResourceGoTypesJenny) Generate

func (ag *ResourceGoTypesJenny) Generate(kind kindsys.Kind) (*codejen.File, error)

func (*ResourceGoTypesJenny) JennyName

func (*ResourceGoTypesJenny) JennyName() string

type SchemaForGen

type SchemaForGen struct {
	// The PascalCase name of the schematized type.
	Name string
	// The schema to be rendered for the type itself.
	Schema thema.Schema
	// Whether the schema is grouped. See https://github.com/grafana/thema/issues/62
	IsGroup bool
}

SchemaForGen is an intermediate values type for jennies that holds both a thema.Schema, and values relevant to generating the schema that should properly, eventually, be in thema itself.

TODO this will be replaced by thema-native constructs

func ForLatestSchema

func ForLatestSchema(k kindsys.Kind) SchemaForGen

ForLatestSchema returns a SchemaForGen for the latest schema in the provided kindsys.Kind's lineage.

TODO this will be replaced by thema-native constructs

type SubresourceGoTypesJenny

type SubresourceGoTypesJenny struct {
	ApplyFuncs       []dstutil.ApplyFunc
	ExpandReferences bool
}

func (*SubresourceGoTypesJenny) Generate

func (g *SubresourceGoTypesJenny) Generate(kind kindsys.Kind) (codejen.Files, error)

func (*SubresourceGoTypesJenny) JennyName

func (*SubresourceGoTypesJenny) JennyName() string

type TSResourceJenny

type TSResourceJenny struct{}

TSResourceJenny 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 (TSResourceJenny) Generate

func (j TSResourceJenny) Generate(sfg SchemaForGen) (*codejen.File, error)

func (TSResourceJenny) JennyName

func (j TSResourceJenny) JennyName() string

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(sfg SchemaForGen) (*codejen.File, error)

func (TSTypesJenny) JennyName

func (j TSTypesJenny) JennyName() string

Jump to

Keyboard shortcuts

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