Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Generate ¶
Generate takes a cue.Value and generates the corresponding TypeScript for all top-level members of that value that have appropriate @cuetsy attributes.
Hidden fields are ignored.
func IgnoreImportMapper ¶ added in v0.1.9
IgnoreImportMapper ignores all import paths cuetsy encounters, resulting in no import statements in generated TS output.
Types ¶
type Concreteness ¶
type Concreteness int
Concreteness is a measure of the level of concreteness of a value, where lower values mean more concrete.
Replicated from cuelang.org/internal/core/adt
const ( BottomLevel Concreteness = iota // Concrete indicates a concrete scalar value, list or struct. Concrete // Constraint indicates a non-concrete scalar value that is more specific, // than a top-level type. Constraint // Type indicates a top-level specific type, for instance, string, // bytes, number, or bool. Type // Any indicates any value, or top. Any )
type Config ¶
type Config struct { // ImportMapper determines how CUE imports are mapped to Typescript imports. If // nil, any non-stdlib import in the input CUE source will result in a fatal // error. // // Import conversions are only run if the input [cue.Value] or its top-level // conjuncts if [cue.Value.Source] returns an [*ast.File]. This eliminates // computed values, and values representing nodes other than a root file // node. ImportMapper // Export determines whether generated TypeScript symbols are exported. Export bool }
Config governs certain variable behaviors when converting CUE to Typescript.
type DeclPair ¶ added in v0.0.2
type DeclPair struct { // The generated type declaration. T ts.Decl // The default declaration corresponding to T. D ts.Decl }
DeclPair represents a generated type declaration, with its corresponding default declaration.
type ImportMapper ¶
An ImportMapper takes a string containing a CUE import path (e.g. "github.com/grafana/cuetsy") and returns a string indicating the import path that should be used in the corresponding generated typescript, or an error if no mapping can be made.
An empty string return indicates no TS import statements should be generated for that CUE import path.
type NewConfig ¶
type NewConfig struct { // Subpath is the path within the cue.Instance that cuetsy should treat as the // root object to be rendered. Optional. Subpath cue.Path // Self indicates that, rather than rendering all the attribute-annotated // children of provided instance, the instance itself should be rendered. Self bool // InjectCuetsyAttrs is an optional set of attribute bodies to be dynamically // injected onto values as they're being rendered. // // The keys will be passed to cue.ParsePath(). The value will be treated as // the body of a @cuetsy attribute (@cuetsy(<value>)) for values encountered at // that path, relative to the root. InjectCuetsyAttrs map[string]string }
type TSType ¶ added in v0.0.2
type TSType string
TSType strings indicate the kind of TypeScript declaration to which a CUE value should be translated. They are used in both @cuetsy attributes, and in calls to certain methods.
const ( // TypeAlias targets conversion of a CUE value to a TypeScript `type` // declaration, which are called type aliases: // https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#type-aliases TypeAlias TSType = "type" // TypeInterface targets conversion of a CUE value to a TypeScript `interface` // declaration: // https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#interfaces TypeInterface TSType = "interface" // TypeEnum targets conversion of a CUE value to a TypeScript `enum` // declaration: // https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#enums TypeEnum TSType = "enum" )
type TypeMapper ¶
type TypeMapper interface { Value() cue.Value Kind() cue.Kind Concreteness() Concreteness String() string }
TypeMapper is a general interface to describe a mapping between cue.Value and typescript kinds and types. Will necessarily need to omit expressions.