Documentation
¶
Overview ¶
Package clientgen provides a registry of language-specific client code generators.
The generator interface supports pluggable, language-specific code generators that produce type-safe client code from authorization schemas. Generators return a file map to support languages that need multiple output files (e.g., TypeScript with separate types.ts, client.ts, index.ts).
This is an internal package used by the melange CLI. For programmatic code generation, use pkg/clientgen which provides a stable public API.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Register ¶
func Register(g Generator)
Register adds a generator to the global registry. Generators should call this from their init() function.
Panics if a generator with the same name is already registered.
func Registered ¶
Registered returns true if a generator is registered for the given name.
Types ¶
type Config ¶
type Config struct {
// Package is the package/module name for generated code.
// For Go: package name (e.g., "authz")
// For TypeScript: not typically used (uses exports)
Package string
// RelationFilter limits which relations get constants generated.
// If empty, all relations are included.
// Example: "can_" generates only permission relations, omitting roles.
RelationFilter string
// IDType specifies the type to use for object IDs in constructors.
// For Go: "string", "int64", "uuid.UUID", etc.
// Other languages may ignore this or use their own type mappings.
IDType string
// Version is the melange version used for generation.
// Included in the generated file header for traceability.
// Example: "v0.4.3"
Version string
// SourcePath is the path to the source schema file.
// Included in the generated file header for traceability.
// Example: "schemas/schema.fga"
SourcePath string
// Options holds language-specific configuration.
// Each generator documents its supported options.
Options map[string]any
}
Config holds language-agnostic generation options.
Each generator may interpret these options differently based on language conventions. Language-specific options can be passed via the Options map.
type Generator ¶
type Generator interface {
// Name returns the runtime identifier ("go", "typescript").
// This is used as the value for --runtime in the CLI.
Name() string
// Generate returns a map of filename -> content for all generated files.
// For single-file outputs (like Go), returns a single entry.
// For multi-file outputs (like TypeScript), returns multiple entries.
//
// The filenames are relative paths (e.g., "schema_gen.go" or "types.ts").
// The caller is responsible for writing these to the appropriate location.
Generate(types []schema.TypeDefinition, cfg *Config) (map[string][]byte, error)
// DefaultConfig returns the default configuration for this generator.
// This is used when the user doesn't provide explicit configuration.
DefaultConfig() *Config
}
Generator produces language-specific client code from a schema.
Implementations should be registered via Register() in their init() function. The CLI uses the registry to dispatch generation based on the --runtime flag.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package gogen implements the Go client code generator for melange.
|
Package gogen implements the Go client code generator for melange. |
|
Package typescript implements the TypeScript client code generator for melange.
|
Package typescript implements the TypeScript client code generator for melange. |