Documentation
¶
Index ¶
- func GenerateClient(actions []ActionFunc, outputDir string) error
- func GenerateStreamClient(streams []StreamFunc, outputDir string) error
- func GenerateTypeInterfaces(structs []StructDef, outputDir string) error
- func MapGoTypeToTS(goType string) string
- type ActionFunc
- type ActionParam
- type Generator
- type StreamFunc
- type StructDef
- type StructField
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateClient ¶
func GenerateClient(actions []ActionFunc, outputDir string) error
GenerateClient groups actions by their declaring package and writes one TypeScript file per package to outputDir/<package>.ts, plus a barrel file at outputDir/index.ts that re-exports every generated package file. Generated functions call native fetch only; no external libraries are imported.
func GenerateStreamClient ¶ added in v1.1.0
func GenerateStreamClient(streams []StreamFunc, outputDir string) error
GenerateStreamClient groups stream functions by package and writes one TypeScript file per package to outputDir/<package>.streams.ts, plus a barrel export in outputDir/streams.ts.
Each generated function returns a ready-to-use React hook that internally calls useZyraStream and connects over WebSocket to GET /__zyra/stream/{package}/{name}.
func GenerateTypeInterfaces ¶
GenerateTypeInterfaces writes outputDir/types.ts containing one exported TypeScript interface per StructDef. Each field's JSON tag name is used as the TypeScript property name when present; fields tagged json:"-" are omitted, and fields tagged with omitempty are rendered as optional properties.
func MapGoTypeToTS ¶
MapGoTypeToTS converts a Go type string (as produced by go/types.ExprString) into the corresponding TypeScript type.
Recognized mappings:
string -> string bool -> boolean int, int8..int64, uint, uint8.. -> number float32, float64, byte, rune -> number error -> void []T -> <TS(T)>[] *SomeStruct -> SomeStruct SomeStruct / pkg.SomeStruct -> SomeStruct anything else -> unknown
Types ¶
type ActionFunc ¶
type ActionFunc struct {
Name string // function name, e.g. "CreateUser"
Package string // declaring package name, e.g. "actions"
Params []ActionParam // function parameters, in declaration order
Returns []string // TypeScript-mapped return types, excluding a trailing error
HasError bool // true if the function's last return value is error
FilePath string // path to the source file the function was found in
}
ActionFunc describes a Go function annotated with "// +zyraaction", along with the metadata needed to generate a matching TypeScript client binding.
func ScanActions ¶
func ScanActions(dir string) ([]ActionFunc, error)
ScanActions recursively scans every .go file under dir (skipping _test.go files, vendor, node_modules, and .git) and returns metadata for each top-level function annotated with the "// +zyraaction" directive on the comment block directly above its declaration. If dir does not exist, ScanActions returns an empty slice and no error.
type ActionParam ¶
type ActionParam struct {
Name string // parameter name, e.g. "userID"
Type string // TypeScript-mapped type, e.g. "string"
GoType string // original Go type, e.g. "string" or "*models.User"
}
ActionParam describes a single parameter of a scanned action function.
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator produces TypeScript artifacts (route manifests and type declarations) derived from the discovered file-based page routes.
func (*Generator) GenerateClientTypes ¶
GenerateClientTypes writes a TypeScript declaration file exposing strongly typed page route paths for use in the client runtime.
type StreamFunc ¶ added in v1.1.0
type StreamFunc struct {
Name string // e.g. "GetLiveStats"
Package string // e.g. "actions"
Params []ActionParam // function parameters (same type as actions)
ElemType string // TypeScript type of the channel element, e.g. "ServerStats"
HasError bool // true if the last return is error
FilePath string
}
StreamFunc describes a Go function annotated with "// +zyrastream". The function must return a receive-only channel (or bidirectional channel) plus an optional error:
func GetLiveStats(ctx context.Context) (<-chan ServerStats, error) func WatchNotifications(userID string) (<-chan Notification, error)
func ScanStreams ¶ added in v1.1.0
func ScanStreams(dir string) ([]StreamFunc, error)
ScanStreams recursively scans every .go file under dir and returns metadata for each top-level function annotated with "// +zyrastream". Functions that do not return a channel type are skipped with a warning.
type StructDef ¶
type StructDef struct {
Name string
Fields []StructField
}
StructDef describes a Go struct that GenerateTypeInterfaces turns into a matching TypeScript interface.
type StructField ¶
type StructField struct {
Name string // Go field name, e.g. "ID"
GoType string // Go type, e.g. "string" or "*User"
JSONTag string // raw json tag value (without the `json:` prefix or quotes), e.g. "id,omitempty" or "-"
}
StructField describes a single field of a Go struct.