Documentation
¶
Overview ¶
Package core analyzes Go AST contracts and generates SDK artifacts without parsing Flow source or embedded DSL manifests. Use AnalyzeGoAll to scan Go roots and GenerateTypeScriptSDK or GenerateTypeScriptAPISDK to emit artifacts.
Index ¶
- func ContentIsUnmodified(onDisk []byte) bool
- func CorrelateActionFields(report *Report)
- func GenerateTypeScriptAPICompatibilityFacade(indexImportPath, endpointsImportPath string) []byte
- func HasValidatorRule(raw, expected string) bool
- func LocalDependencyRoots(root string) []string
- func RenderEnhancedReport(report *Report, actionFilter string) string
- func RenderSummaryTable(report *Report, actionFilter string) string
- func SDKMethodName(action ActionContract) string
- func StampContent(content []byte, path string) []byte
- type APIClientConfig
- type APIScalarAlias
- type APISurfaceType
- type ActionContract
- type Analyzer
- type DSLConfig
- type Diagnostic
- type DiagnosticSeverity
- type EnumDefinition
- type EnumValue
- type FieldContract
- type FlowHTTPRoute
- type GeneratedFile
- type PackageInfo
- type Report
- type ReportStats
- type StoreCluster
- type StructDefinition
- type StructKey
- type TransportBinding
- type TypeRef
- type ZodFieldConfig
- type ZodRefinement
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContentIsUnmodified ¶
ContentIsUnmodified reports whether an on-disk write-once file still matches the content that last produced it.
Algorithm:
- Find the marker. No marker → not ours → modified (preserve).
- Strip the marker line from the body.
- SHA-256 the remaining bytes and compare against the stored hash.
Returning true means "safe to overwrite with a new template". Returning false means "user edited this file — leave it alone" (unless --force).
func CorrelateActionFields ¶
func CorrelateActionFields(report *Report)
CorrelateActionFields refreshes request and response fields from the report's final generic type references.
func GenerateTypeScriptAPICompatibilityFacade ¶ added in v0.9.0
GenerateTypeScriptAPICompatibilityFacade emits a small, opt-in facade for applications that keep a stable single-file import path. The split API modules remain the source of truth; this file only re-exports them.
func HasValidatorRule ¶
HasValidatorRule reports whether raw contains a validation rule with the requested name.
func LocalDependencyRoots ¶
LocalDependencyRoots returns local replacement directories discovered from a root's go.mod, matching the source roots used by AnalyzeGoAll.
func RenderEnhancedReport ¶
func RenderSummaryTable ¶
func SDKMethodName ¶ added in v0.9.0
func SDKMethodName(action ActionContract) string
SDKMethodName returns the configured client method name or the default camel-cased form of the action name.
func StampContent ¶
StampContent returns content with a nexssp:hash marker appended. The marker carries the SHA-256 of content itself, so ContentIsUnmodified can later verify the file hasn't been touched since we wrote it.
The path determines the comment style (markdown vs everything else).
Types ¶
type APIClientConfig ¶ added in v0.14.0
type APIClientConfig struct {
Transport string `json:"transport,omitempty"`
ErrorKinds []string `json:"error_kinds,omitempty"`
ScalarAliases []APIScalarAlias `json:"scalar_aliases,omitempty"`
EndpointMetadataFields []string `json:"endpoint_metadata_fields,omitempty"`
FieldMetadataFields []string `json:"field_metadata_fields,omitempty"`
FacadeExportName string `json:"facade_export_name,omitempty"`
FactoryExportName string `json:"factory_export_name,omitempty"`
EmptyStructSchema bool `json:"empty_struct_schema,omitempty"`
PathParameterEncoding string `json:"path_parameter_encoding,omitempty"`
}
type APIScalarAlias ¶ added in v0.14.0
type APISurfaceType ¶ added in v0.14.0
type APISurfaceType struct {
Name string `json:"name"`
Fields []FieldContract `json:"fields"`
}
type ActionContract ¶
type ActionContract struct {
Name string `json:"name"`
SDKMethodName string `json:"sdk_method_name,omitempty"`
Description string `json:"description"`
ReqTypeName string `json:"req_type"`
ResTypeName string `json:"res_type"`
// FlowSchemaDriven marks an NFlow route whose HTTP boundary is declared
// with request/response-schema modifiers. Missing modifiers remain absent
// instead of being inferred from the called Go action.
FlowSchemaDriven bool `json:"flow_schema_driven,omitempty"`
ReqSchemaName string `json:"request_schema,omitempty"`
ResSchemaName string `json:"response_schema,omitempty"`
ReqType TypeRef `json:"req_type_ref,omitempty"`
ResType TypeRef `json:"res_type_ref,omitempty"`
Method string `json:"method"`
Path string `json:"path"`
RouteSource string `json:"route_source,omitempty"`
TypeSource string `json:"type_source,omitempty"`
ContractSource string `json:"contract_source,omitempty"`
Transports []TransportBinding `json:"transports,omitempty"`
Tags []string `json:"tags"`
Node string `json:"node,omitempty"`
Scope string `json:"scope"`
Idempotent bool `json:"idempotent"`
Deduplicated bool `json:"deduplicated,omitempty"`
Coalesced bool `json:"coalesced,omitempty"`
Timeout time.Duration `json:"timeout"`
RetryMax int `json:"retry_max"`
CacheTTL time.Duration `json:"cache_ttl,omitempty"`
RateLimit string `json:"rate_limit,omitempty"`
ConcurrencyLimit int32 `json:"concurrency_limit,omitempty"`
Permissions []string `json:"permissions"`
Roles []string `json:"roles"`
Features []string `json:"features"`
ReqFields []FieldContract `json:"req_fields"`
ResFields []FieldContract `json:"res_fields"`
SourceFile string `json:"source_file"`
SourceLine int `json:"source_line"`
Streaming bool `json:"streaming,omitempty"`
Raw bool `json:"raw,omitempty"`
RequestOptional *bool `json:"request_optional,omitempty"`
ValidateMultipartRequest bool `json:"validate_multipart_request,omitempty"`
// Multipart is true when a request field has a `form:"..."` tag on a
// []byte or transport FormFile value, so the client uses multipart/form-data.
Multipart bool `json:"multipart,omitempty"`
// BlobResponse is true when the action's declared response type is
// `[]byte`. The generated client returns a Blob.
BlobResponse bool `json:"blob_response,omitempty"`
BudgetMicros int64 `json:"budget_micros,omitempty"`
RequiresAuth bool `json:"requires_auth,omitempty"`
RateLimitBurst int `json:"rate_limit_burst,omitempty"`
BreakerFailures int `json:"breaker_failures,omitempty"`
BreakerCooldown time.Duration `json:"breaker_cooldown,omitempty"`
HITLPrompt string `json:"hitl_prompt,omitempty"`
HITLOptions []string `json:"hitl_options,omitempty"`
HITLTriggers []string `json:"hitl_triggers,omitempty"`
SuccessStatus int `json:"success_status,omitempty"`
BackoffStrategy string `json:"backoff_strategy,omitempty"`
BackoffBase time.Duration `json:"backoff_base,omitempty"`
BackoffMax time.Duration `json:"backoff_max,omitempty"`
RetryPredicate string `json:"retry_predicate,omitempty"`
Priority string `json:"priority,omitempty"`
CacheKey string `json:"cache_key,omitempty"`
Audit bool `json:"audit,omitempty"`
IdempotencyHeader string `json:"idempotency_header,omitempty"`
Deprecated bool `json:"deprecated,omitempty"`
DeprecatedSince string `json:"deprecated_since,omitempty"`
DeprecatedUse string `json:"deprecated_use,omitempty"`
}
type Analyzer ¶
type Analyzer struct {
// contains filtered or unexported fields
}
func (*Analyzer) FindStruct ¶
func (a *Analyzer) FindStruct(nameOrQualified string) (StructDefinition, bool)
type Diagnostic ¶
type Diagnostic struct {
Severity DiagnosticSeverity `json:"severity"`
Rule string `json:"rule"`
Message string `json:"message"`
Suggestion string `json:"suggestion,omitempty"`
File string `json:"file,omitempty"`
Line int `json:"line,omitempty"`
Action string `json:"action,omitempty"`
}
func ValidatePublicAPI ¶
func ValidatePublicAPI(report *Report) []Diagnostic
ValidatePublicAPI reports contracts that the generated public SDK cannot type safely. It is intentionally separate from general analysis so generic OPS reports and non-SDK workflows keep their existing behavior.
type DiagnosticSeverity ¶
type DiagnosticSeverity string
const ( SeverityError DiagnosticSeverity = "ERROR" SeverityWarning DiagnosticSeverity = "WARNING" )
type EnumDefinition ¶
type EnumDefinition struct {
TypeName string
Package string
Domain string
Qualified string
SourceFile string
Values []EnumValue
}
EnumDefinition captures a Go string-backed enum type and its values.
Convention recognised by the analyzer:
type TaskStatus string
const (
StatusPending TaskStatus = "PENDING"
StatusRunning = "RUNNING" // inherits the type
)
Only exported type names and exported const names are captured. The captured TypeName is the Go type; ConstName is the identifier; Value is the literal string. Order of Values matches declaration order.
type FieldContract ¶
type FieldContract struct {
Name string `json:"name"`
Key string `json:"key"`
Type string `json:"type"`
Required bool `json:"required"`
Nullable bool `json:"nullable,omitempty"`
JSONOmitEmpty bool `json:"-"`
Validation string `json:"validation,omitempty"`
RawTags string `json:"raw_tags,omitempty"`
// Multipart marks a field transported as a file part in a multipart/form-data
// request. The analyzer sets it for form-tagged []byte or transport FormFile fields.
Multipart bool `json:"multipart,omitempty"`
PreserveMultipartType bool `json:"preserve_multipart_type,omitempty"`
Zod *ZodFieldConfig `json:"zod,omitempty"`
}
type FlowHTTPRoute ¶
type FlowHTTPRoute struct {
Pipeline string `json:"pipeline"`
Method string `json:"method"`
Path string `json:"path"`
SuccessStatus int `json:"success_status,omitempty"`
SourceFile string `json:"source_file,omitempty"`
SourceLine int `json:"source_line,omitempty"`
}
FlowHTTPRoute describes a route declared by an .nflow @pipeline modifier. Pipeline is the compiled Flow resolver name (for example, pipeline.agents_list).
type GeneratedFile ¶
func GenerateTypeScriptAPI ¶ added in v0.5.0
func GenerateTypeScriptAPI(report *Report) []GeneratedFile
GenerateTypeScriptAPI emits only the public API client files directly into the output directory. Unlike GenerateTypeScriptAPISDK, it does not include stores, app-level barrels, or scaffold files.
func GenerateTypeScriptAPISDK ¶
func GenerateTypeScriptAPISDK(report *Report) []GeneratedFile
GenerateTypeScriptAPISDK emits DTOs reachable from routed public actions only. It excludes unrelated structs that were exposed by package/file conventions.
func GenerateTypeScriptSDK ¶
func GenerateTypeScriptSDK(report *Report) []GeneratedFile
GenerateTypeScriptSDK produces the full generated tree for ui/src/lib/.
Three categories of output, distinguished by GeneratedFile.Overwrite:
Overwrite: true always regenerated Overwrite: false written once, then preserved (edit freely)
Ownership map (paths relative to ui/src/lib/):
_gen/api/* generated
_gen/stores/{entities,forms,streams,system}/* generated
_gen/stores/index.ts generated
_gen/index.ts generated
_gen/stores/runtime/* write-once
api.ts write-once (merge barrel)
custom/* write-once (extension points)
Anything outside these paths is yours — the generator never touches it.
type PackageInfo ¶
type Report ¶
type Report struct {
APISurfaceManifest bool `json:"-"`
APIClientConfig *APIClientConfig `json:"-"`
ScannedFiles int `json:"scanned_files"`
Actions []ActionContract `json:"actions"`
FlowHTTPRoutes []FlowHTTPRoute `json:"flow_http_routes,omitempty"`
FlowSchemas map[string]StructDefinition `json:"flow_schemas,omitempty"`
Structs map[string]StructDefinition `json:"structs"`
Enums map[string]EnumDefinition `json:"enums,omitempty"`
Diagnostics []Diagnostic `json:"diagnostics"`
Stats ReportStats `json:"stats"`
}
func AnalyzeAll ¶
AnalyzeAll is a multi-root alias for AnalyzeGoAll.
func AnalyzeGoAll ¶
AnalyzeGoAll scans Go source under one or more roots and their local `replace` dependencies. It never reads Flow files or embedded DSL strings.
func (*Report) FindStruct ¶
func (r *Report) FindStruct(nameOrQualified string) (StructDefinition, bool)
type ReportStats ¶
type ReportStats struct {
TotalActions int `json:"total_actions"`
PublicActions int `json:"public_actions"`
InternalActions int `json:"internal_actions"`
SystemActions int `json:"system_actions"`
TotalStructs int `json:"total_structs"`
TotalEnums int `json:"total_enums"`
ErrorCount int `json:"error_count"`
WarningCount int `json:"warning_count"`
}
type StoreCluster ¶
type StoreCluster struct {
Noun string
List *ActionContract
Get *ActionContract
Create *ActionContract
Update *ActionContract
Delete *ActionContract
EntityType string
EntityStruct StructDefinition
IDField string
}
type StructDefinition ¶
type StructDefinition struct {
Name string `json:"name"`
Package string `json:"package"`
Domain string `json:"domain"`
ImportPath string `json:"import_path,omitempty"`
Qualified string `json:"qualified"`
SourceFile string `json:"source_file"`
Fields []FieldContract `json:"fields"`
IsExposed bool `json:"is_exposed"`
IsIgnored bool `json:"is_ignored"`
CustomName string `json:"custom_name,omitempty"`
TargetFile string `json:"target_file,omitempty"`
}
type TransportBinding ¶
type TransportBinding = dsl.TransportBinding
type TypeRef ¶
type ZodFieldConfig ¶ added in v0.14.0
type ZodFieldConfig struct {
Base string `json:"base,omitempty"`
Nullable bool `json:"nullable,omitempty"`
AcceptEmptyString bool `json:"accept_empty_string,omitempty"`
Refinements []ZodRefinement `json:"refinements,omitempty"`
}
type ZodRefinement ¶ added in v0.14.0
Source Files
¶
- analyzer.go
- codegen.go
- codegen_api_client.go
- codegen_api_endpoints.go
- codegen_api_types.go
- codegen_api_validation.go
- codegen_custom.go
- codegen_marker.go
- codegen_stores.go
- codegen_stores_emit.go
- codegen_stores_runtime.go
- codegen_utils.go
- codegen_zod.go
- diagnose.go
- doc.go
- exctract_enums.go
- extract_actions.go
- extract_structs.go
- extract_transports.go
- packages.go
- render.go
- resolve.go
- types.go