transcribe

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: Apache-2.0 Imports: 66 Imported by: 7

Documentation

Overview

Package transcribe owns authored source parsing, canonical component assembly, component-graph SQL resource traversal, and generated package production. Typed per-source SQL expansion belongs to package sql.

Index

Constants

View Source
const (
	WritePost  = handlerast.OperationPost
	WritePut   = handlerast.OperationPut
	WritePatch = handlerast.OperationPatch
)

Variables

View Source
var ErrNilSource = errors.New("transcribe: nil source")

Functions

This section is empty.

Types

type CompileError

type CompileError struct {
	Cause       error
	Diagnostics []*Diagnostic
}

CompileError carries compiler diagnostics while preserving the parser error for errors.Is/errors.As classification.

func (*CompileError) Error

func (e *CompileError) Error() string

func (*CompileError) Unwrap

func (e *CompileError) Unwrap() error

type Compiler

type Compiler struct{}

Compiler is the single authored-source orchestration entrypoint. Its body is intentionally narrow while the original preprocess and plan stages are ported behind this stable boundary.

func NewCompiler

func NewCompiler() *Compiler

func (*Compiler) Compile

func (c *Compiler) Compile(ctx context.Context, source *Source) (*Result, error)

func (*Compiler) RuntimeContracts

func (c *Compiler) RuntimeContracts(ctx context.Context, rootDir string, source *Source) (*RuntimeContract, error)

RuntimeContracts compiles authored DQL and materializes generated input and output reflect types for an ephemeral reader execution. rootDir must be a module root so #package destination authority is resolved consistently with ordinary transcription.

func (*Compiler) Transcribe

func (c *Compiler) Transcribe(ctx context.Context, request Request) (*GeneratedPackage, error)

Transcribe compiles one authored source under normalized options, emits its package artifacts, and loads the generated package.

type ContractOptions

type ContractOptions string

ContractOptions controls contract ownership for one transcription.

const (
	ContractsAuto      ContractOptions = "auto"
	ContractsGenerated ContractOptions = "generated"
	ContractsLinked    ContractOptions = "linked"
)

type ContractTypeOverrides

type ContractTypeOverrides struct {
	Input  string
	Output string
}

ContractTypeOverrides records only type names explicitly authored by DQL. Package-inherited settings are intentionally excluded so ownership decisions never need to infer provenance from equal strings.

type CurrentBinding

type CurrentBinding = handlercompiler.CurrentBinding

type Diagnostic

type Diagnostic struct {
	Code     string   `json:"code"`
	Severity Severity `json:"severity"`
	Message  string   `json:"message"`
	Hint     string   `json:"hint,omitempty"`
	Path     string   `json:"path,omitempty"`
	Span     Span     `json:"span"`
}

Diagnostic is transcribe compile feedback. It remains outside canonical spec because source spans and compiler hints are pipeline products.

func (*Diagnostic) Error

func (d *Diagnostic) Error() string

func (*Diagnostic) IsError

func (d *Diagnostic) IsError() bool

type Discovery

type Discovery struct {
	Const *constant.Values
	// Workspace fixes source selection to a Go build when supplied.
	Workspace  *xmodule.Workspace
	BaseDir    string
	ModuleDirs []string
	Include    []string
	// TypeInclude loads package-level type authority without selecting those
	// packages for component discovery or resource loading.
	TypeInclude   []string
	Exclude       []string
	Connector     string
	Types         *typecatalog.Catalog
	ColumnRefiner *column.Refiner
	// Registry is trusted compiled package authority. Selected source descriptors
	// retain linked types so lifecycle methods and typed factories remain executable.
	Registry *x.Registry
	// Holders are build-linked component declarations for the packages selected
	// by Include. They supply concrete Go contracts and factories without init
	// registration; source scanning remains the discovery authority.
	Holders []any
	// RequireLinked rejects source-declared component holders that were not
	// selected by the host's default-import package. Runtime hosts enable it;
	// authoring/transcription may intentionally inspect unlinked source.
	RequireLinked bool
}

Discovery compiles authored component sources selected by module-qualified package patterns into one canonical project. It is the local-filesystem frontend corresponding to the original transcribe command's source loop.

func (*Discovery) Compile

func (d *Discovery) Compile(ctx context.Context) (*ProjectGeneration, error)

Compile discovers and compiles each component source exactly once. Plain SQL files without a route directive are resources rather than components and are ignored; every other compile failure is returned with its source path.

func (*Discovery) CompileSource

func (d *Discovery) CompileSource(ctx context.Context, source *Source) (*Result, error)

CompileSource compiles one in-memory authored source with the same configured workspace/import authority used by Discovery. It is intended for bounded MCP authoring surfaces where clients may provide source text but not filesystem roots, compiler options, schema refiners, or package selections.

func (*Discovery) Generate

func (d *Discovery) Generate(ctx context.Context, rootDir string) (*GeneratedProject, error)

Generate compiles the discovered project and delegates all validation and persistence to ProjectGeneration.

type GeneratedPackage

type GeneratedPackage struct {
	Result  *gen.Result
	Package *smodel.Package
	Types   *typecatalog.Catalog
}

GeneratedPackage holds transcribed package artifacts for package bootstrap.

type GeneratedProject

type GeneratedProject struct {
	Manifest   *ProjectManifest
	Components []*GeneratedPackage
}

type GenerationOptions

type GenerationOptions struct {
	Operation string
	Language  HandlerTarget
}

GenerationOptions opts a configured authoring target into the high-level Generator path. Source and Destination remain owned by Request so operator configuration has one source/destination owner.

func (GenerationOptions) Enabled

func (o GenerationOptions) Enabled() bool

func (GenerationOptions) Normalize

func (o GenerationOptions) Normalize() (GenerationOptions, error)

type GenerationRequest

type GenerationRequest struct {
	Source *Source
	// Compiled accepts the canonical discovery product, including package authority.
	Compiled    *Result
	Destination string
}

type Generator

type Generator struct {
	Operation          string
	Language           HandlerTarget
	EphemeralOwnership bool
	GenerationPolicy   gen.GenerationPolicy
}

Generator derives request contracts and mutation state before lowering a canonical handler. Transcribe remains the lower-level authored-contract path. Destination is only the project root; DQL and package metadata own artifacts.

func (Generator) Generate

func (g Generator) Generate(ctx context.Context, request GenerationRequest) (*GeneratedPackage, error)

type GoExecution

type GoExecution string

GoExecution selects generated orchestration without changing the Go target or the canonical invocation engine. Direct preserves authored control flow.

const (
	GoExecutionDirect   GoExecution = "direct"
	GoExecutionMutation GoExecution = "mutation"
)

type GoHandlerOptions

type GoHandlerOptions struct {
	Execution   GoExecution
	Factory     string
	Handler     string
	Destination string
}

type HandlerOptions

type HandlerOptions struct {
	Target    HandlerTarget
	Operation WriteOperation
	Input     string
	Output    string
	RootView  string
	Current   string
	Currents  []CurrentBinding
	Table     string
	Key       string
	Hooks     HookOptions
	Go        GoHandlerOptions
	Velty     VeltyHandlerOptions
}

HandlerOptions selects one generated product over the canonical handler plan. It never selects behavior from an HTTP method.

type HandlerTarget

type HandlerTarget string

HandlerTarget selects a generated handler target. The zero value preserves package, supplied, or authored handler authority.

const (
	HandlerNone  HandlerTarget = "none"
	HandlerVelty HandlerTarget = "velty"
	HandlerGo    HandlerTarget = "go"
)

type HookOptions

type HookOptions struct {
	Scaffold    bool
	Destination string
}

HookOptions opts into a create-once user-owned file. Direct Go execution scaffolds input/output lifecycle methods; mutation execution scaffolds typed EntityHooks for roles without an authored hook declaration.

type Options

type Options struct {
	Contracts ContractOptions
	Handler   HandlerOptions
}

Options contains target-independent transcription choices.

type PackageCompilation

type PackageCompilation struct {
	Source     *Source
	Component  *bootstrap.RouteSource
	InputType  reflect.Type
	OutputType reflect.Type
	Types      *typecatalog.Catalog
	Options    Options
}

PackageCompilation joins an explicitly selected package component with an authored DQL source. Package tags establish the base contract; DQL overlays that contract through Compiler's canonical load stage.

func (*PackageCompilation) Compile

func (c *PackageCompilation) Compile(ctx context.Context) (*Result, error)

Compile registers linked contract types under package authority and compiles the DQL source with package metadata as its canonical base.

func (*PackageCompilation) Transcribe

func (c *PackageCompilation) Transcribe(ctx context.Context, rootDir string) (*GeneratedPackage, error)

Transcribe compiles package/DQL authority under normalized options and emits only products selected by the resulting canonical ownership decisions.

type Position

type Position struct {
	Offset int `json:"offset"`
	Line   int `json:"line"`
	Char   int `json:"char"`
}

Position identifies a byte offset and its rune-aware source location.

type ProjectComponent

type ProjectComponent struct {
	Key          spec.Key               `json:"key"`
	Source       string                 `json:"source,omitempty"`
	Package      string                 `json:"package"`
	OutputType   string                 `json:"outputType,omitempty"`
	OutputOrigin typecatalog.TypeOrigin `json:"outputOrigin,omitempty"`
	IR           string                 `json:"ir"`
	Diagnostics  string                 `json:"diagnostics"`
	Artifacts    []string               `json:"artifacts"`
	Routes       []ProjectRoute         `json:"routes,omitempty"`
	Dependencies []string               `json:"dependencies,omitempty"`
}

type ProjectGeneration

type ProjectGeneration struct {
	Components []*Result
	// Resources is the staged named authority shared by all component sources.
	Resources *resource.Store
}

ProjectGeneration persists a coherent project from already compiled canonical components. Compilation remains owned by Compiler and PackageCompilation; this type owns only cross-component validation and project-level output.

func (*ProjectGeneration) Generate

func (g *ProjectGeneration) Generate(ctx context.Context, rootDir string) (*GeneratedProject, error)

type ProjectManifest

type ProjectManifest struct {
	Version      int                    `json:"version"`
	Components   []ProjectComponent     `json:"components"`
	Dependencies []string               `json:"dependencies,omitempty"`
	Analysis     ProjectMigrationReport `json:"analysis"`
}

type ProjectMigrationComponent

type ProjectMigrationComponent struct {
	Key             spec.Key `json:"key"`
	InputOwnership  string   `json:"inputOwnership"`
	OutputOwnership string   `json:"outputOwnership"`
	GeneratedViews  int      `json:"generatedViews"`
	LinkedViews     int      `json:"linkedViews"`
	Handler         string   `json:"handler"`
}

type ProjectMigrationReport

type ProjectMigrationReport struct {
	Components []ProjectMigrationComponent `json:"components"`
}

type ProjectRoute

type ProjectRoute struct {
	Method string `json:"method"`
	Path   string `json:"path"`
}

type Request

type Request struct {
	Component   *bootstrap.RouteSource
	InputType   reflect.Type
	OutputType  reflect.Type
	Source      *Source
	Destination string
	Options     Options
	Generation  GenerationOptions
}

Request is the sole public authored-source-to-package transcription request.

func (Request) GeneratorRequest

func (r Request) GeneratorRequest() (Generator, GenerationRequest, error)

func (Request) NormalizeGeneration

func (r Request) NormalizeGeneration() (Request, error)

type Result

type Result struct {
	Source                *Source
	Component             *spec.Component
	PreparedSQL           string
	Statements            statement.Statements
	SourceMap             *SourceMap
	TypeContext           *typecatalog.ResolutionContext
	TypeResolver          *typecatalog.Resolver
	TypeAuthority         typecatalog.Authority
	Declarations          gen.Declarations
	Contracts             gen.ContractReferences
	Views                 gen.ViewReferences
	ViewBindings          gen.ViewBindings
	GeneratedTypes        []gen.GeneratedTypeReference
	GoHandler             *gen.GoHandlerAsset
	VeltyHandler          *gen.VeltyHandlerAsset
	ContractTypeOverrides ContractTypeOverrides
	Diagnostics           []*Diagnostic
}

Result is the compile-time product passed to later plan, type-resolution, generation, and persistence stages. Runtime artifacts are intentionally not part of this model.

type RuntimeContract

type RuntimeContract struct {
	Result     *Result
	Component  *spec.Component
	InputType  reflect.Type
	OutputType reflect.Type
	Resources  *resource.Store
	Types      *typecatalog.Catalog
	Plan       *gen.Plan
}

RuntimeContract is the dynamic-reader contract compiled from DQL without emitting or loading a persistent generated Go package.

type SchemaInspection

type SchemaInspection struct {
	Component string   `json:"component"`
	View      string   `json:"view"`
	Connector string   `json:"connector"`
	Table     string   `json:"table,omitempty"`
	Completed []string `json:"completed"`
}

SchemaInspection records guaranteed stages of successful compiler refinement. It is not validation of a runtime payload or of every SQL template branch.

type Severity

type Severity string
const (
	SeverityError   Severity = "error"
	SeverityWarning Severity = "warning"
	SeverityInfo    Severity = "info"
)

type Source

type Source struct {
	Const     *constant.Values
	Scope     string
	Name      string
	Path      string
	Text      string
	Connector string
	// Resources is the Bindly-owned resource authority shared by source
	// expansion, column discovery, and generated-package planning.
	Resources *resource.Store
	Docs      xdocs.Service
	Types     *typecatalog.Catalog
	// ColumnRefiner explicitly enables compile-time SQLX column discovery.
	// A nil refiner keeps ordinary transcription DB-free.
	ColumnRefiner *column.Refiner
	// PackageComponent is optional package-authority canonical metadata used as
	// the base for DQL+package transcription. Authored DQL overlays this graph;
	// ordinary package-only bootstrap does not enter transcribe.
	PackageComponent *spec.Component
	LinkedInputType  reflect.Type
	LinkedOutputType reflect.Type
	LinkedHandler    func() (rhandler.TypedHandler, error)
	// GoHandler is an explicitly accepted custom handler source asset. It is
	// generation input only; canonical metadata retains just its handler name.
	GoHandler *gen.GoHandlerAsset
	// VeltyHandler optionally supplies an accepted template asset. When absent,
	// explicit DQL service programs are transcribed into the same artifact.
	// Runtime state and capabilities remain owned by runtime/handler/velty.
	VeltyHandler *gen.VeltyHandlerAsset
}

Source is the transcribe-owned authored source/config model used to assemble canonical components and generated package artifacts for package bootstrap.

func (*Source) BaseDir

func (s *Source) BaseDir() string

type SourceMap

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

SourceMap maps offsets in preprocessed SQL or Velty text back to authored DQL. This is ported from the newer original shape preprocessor.

func (*SourceMap) MapOffset

func (m *SourceMap) MapOffset(offset int) int

func (*SourceMap) Position

func (m *SourceMap) Position(offset int) Position

func (*SourceMap) Remap

func (m *SourceMap) Remap(diagnostics []*Diagnostic)

type Span

type Span struct {
	Start Position `json:"start"`
	End   Position `json:"end"`
}

type ValidationReport

type ValidationReport struct {
	Valid       bool               `json:"valid"`
	Components  []string           `json:"components"`
	Completed   []string           `json:"completed"`
	Skipped     []string           `json:"skipped"`
	Diagnostics []*Diagnostic      `json:"diagnostics,omitempty"`
	Schema      []SchemaInspection `json:"schema,omitempty"`
}

type Validator

type Validator struct {
	Const      *constant.Values
	BaseDir    string
	ModuleDirs []string
	Include    []string
	Exclude    []string
	// ColumnRefiner explicitly enables database discovery through the existing
	// compiler owner. Nil keeps validation static. Connections remain caller-owned.
	ColumnRefiner *column.Refiner
	Connector     string
}

Validator is the non-persisting authoring validation entry point for CLI and developer tooling. It reuses discovery and generation planning; it never registers components or executes application code.

func (*Validator) Validate

func (v *Validator) Validate(ctx context.Context) (*ValidationReport, error)

Validate checks the selected source and prospective generated artifacts in memory. Valid means the reported stages passed, not runtime readiness.

type VeltyHandlerOptions

type VeltyHandlerOptions struct {
	Factory             string
	GoDestination       string
	ResourceDestination string
}

type WriteOperation

type WriteOperation = handlerast.Operation

Directories

Path Synopsis
Package column refines canonical view columns during explicit transcription.
Package column refines canonical view columns during explicit transcription.
Package compile lowers prepared DQL into normalized transcribe plans.
Package compile lowers prepared DQL into normalized transcribe plans.
dql
Package dql implements focused DQL syntax parsing for the transcribe pipeline.
Package dql implements focused DQL syntax parsing for the transcribe pipeline.
statement
Package statement segments preprocessed DQL into top-level SQL and Velty operations.
Package statement segments preprocessed DQL into top-level SQL and Velty operations.
Package generate emits Go package artifacts from resolved transcribe products and type authority.
Package generate emits Go package artifacts from resolved transcribe products and type authority.
handler
ast
Package ast defines the target-neutral semantic tree used to generate Go and Velty handlers.
Package ast defines the target-neutral semantic tree used to generate Go and Velty handlers.
compiler
Package compiler validates canonical component metadata and produces the target-neutral handler AST.
Package compiler validates canonical component metadata and produces the target-neutral handler AST.
golang
Package golang lowers semantic handler transcription plans into Go AST.
Package golang lowers semantic handler transcription plans into Go AST.
velty
Package velty lowers target-neutral handler transcription plans into Velty.
Package velty lowers target-neutral handler transcription plans into Velty.

Jump to

Keyboard shortcuts

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