contract

package
v0.0.0-...-c671013 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package contract resolves a method's overload and renders a JSON skeleton the agent can populate before calling sofarpc_invoke. It is the only package that joins facadesemantic (raw class data) with javatype (type classification) — handlers should not import either directly when the decision is "which overload + what payload shape".

The Store interface is the single seam the rest of the system plugs into. Tests use InMemoryStore; production code can materialise contract data from any source without changing the resolver.

Index

Constants

View Source
const DefaultServiceNameSuffix = "Facade"

Variables

This section is empty.

Functions

func BuildSkeleton

func BuildSkeleton(paramTypes []string, store Store) []json.RawMessage

BuildSkeleton renders one JSON value per paramType. UserType classes get an object with a leading "@type" key so Hessian2 on the remote side can pick the correct Java class; containers render with their declared element / value type expanded; arrays wrap the element skeleton in `[...]`; primitives/strings/dates render via javatype.RenderPlaceholder.

The store is consulted to walk user-type field types recursively. A cycle guard (seen[fqn]) collapses recursive references to a minimal {"@type":"..."} stub.

func ClassLookup

func ClassLookup(store Store) javatype.ClassLookup

ClassLookup adapts a Store to javatype.ClassLookup so javatype.Classify can walk facadesemantic data without importing this package.

func ListMethods

func ListMethods(store Store, service string) (javamodel.Class, []javamodel.Method, error)

ListMethods returns every method callable on a service, including methods inherited from superinterfaces and superclasses with type parameters substituted. Results are deduplicated by signature and sorted by name then signature so listings are stable across runs.

func NormalizeArgs

func NormalizeArgs(paramTypes []string, args []any, store Store) ([]any, error)

NormalizeArgs performs contract-aware semantic normalization. Its output is still replayable JSON-like data; sofarpcwire owns the later Hessian adapter preparation step.

func NormalizeJSONArgs

func NormalizeJSONArgs(paramTypes []string, args []any, store Store) ([]any, error)

NormalizeJSONArgs normalizes args for a provider that binds JSON to the declared parameter types, as SOFARPC's Jackson serializer does. The result carries no "@type" on objects and renders an enum as its constant name, because that provider cannot be told which Java class to build: an explicit "@type" naming a subtype of the declared type is rejected rather than silently dropped. Exact-number wrappers (Long, BigDecimal, BigInteger) stay in the plan and are folded into number literals when the request is encoded.

func NormalizeServiceNameSuffixes

func NormalizeServiceNameSuffixes(raw []string) []string

func PlainJSONArgs

func PlainJSONArgs(args []any) ([]any, error)

PlainJSONArgs is NormalizeJSONArgs without a contract: every value is read by its own shape, so it applies when the caller supplied the tuple directly. With no class index an enum cannot be told from an object, so the caller passes an enum as its constant name.

func ResolvedFields

func ResolvedFields(store Store, fqn string) []javamodel.Field

func RewriteWireTypeNames

func RewriteWireTypeNames(args []any, store Store) []any

RewriteWireTypeNames walks a JSON-like args tree and rewrites every "@type" string to its wire form via one shared resolver. It validates nothing and never fails: unknown classes keep their original spelling. This is the rescue pass for paths that bypass NormalizeArgs — the skeleton-as-args branch and replayed plans captured before type names were fixed.

func ValidateJSONNumberSafety

func ValidateJSONNumberSafety(raw any) error

ValidateJSONNumberSafety rejects bare integer JSON numbers that cannot cross a JavaScript MCP client's numeric boundary without losing identity. Callers must use a decimal string or an explicit boxed Long wrapper for those values.

func WireParamTypes

func WireParamTypes(paramTypes []string, store Store) []string

WireParamTypes produces erased JVM class names for SofaRequest.methodArgSigs. The caller supplies the declaring method types, before generic inheritance substitutes its type arguments.

Types

type DiagnosticStore

type DiagnosticStore interface {
	Store
	Diagnostics() Diagnostics
}

type Diagnostics

type Diagnostics struct {
	IndexedClasses       int                 `json:"indexedClasses"`
	IndexedFiles         int                 `json:"indexedFiles"`
	ParsedClasses        int                 `json:"parsedClasses"`
	IndexFailureCount    int                 `json:"indexFailureCount,omitempty"`
	ParseFailureCount    int                 `json:"parseFailureCount,omitempty"`
	ResolutionIssueCount int                 `json:"resolutionIssueCount,omitempty"`
	IndexFailures        map[string]string   `json:"indexFailures,omitempty"`
	ParseFailures        map[string]string   `json:"parseFailures,omitempty"`
	ResolutionIssues     map[string][]string `json:"resolutionIssues,omitempty"`
	DuplicateClasses     map[string][]string `json:"duplicateClasses,omitempty"`
	SkippedDirs          map[string]int      `json:"skippedDirs,omitempty"`
	GeneratedSourceFiles int                 `json:"generatedSourceFiles,omitempty"`
	ModuleRoots          int                 `json:"moduleRoots,omitempty"`
	Hints                []string            `json:"hints,omitempty"`
}

type InMemoryStore

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

InMemoryStore is the test / scaffolding implementation.

func NewInMemoryStore

func NewInMemoryStore(classes ...javamodel.Class) *InMemoryStore

NewInMemoryStore seeds a store with the supplied classes.

func (*InMemoryStore) Class

func (s *InMemoryStore) Class(fqn string) (javamodel.Class, bool)

Class implements Store.

func (*InMemoryStore) IndexedClasses

func (s *InMemoryStore) IndexedClasses() []string

IndexedClasses implements IndexedClassStore with the stored FQNs sorted, so service discovery and listings behave the same on the in-memory store as on the production source-contract store.

func (*InMemoryStore) Put

func (s *InMemoryStore) Put(class javamodel.Class)

Put adds or replaces a class. Keyed on FQN.

type IndexedClassStore

type IndexedClassStore interface {
	Store
	IndexedClasses() []string
}

type Result

type Result struct {
	Service   javamodel.Class
	Method    javamodel.Method
	Overloads []javamodel.Method
	Selected  int
}

Result is what ResolveMethod returns on success. Overloads lists every method with the matching name (useful for describe output); Selected is the index into Overloads of the disambiguated overload.

func ResolveMethod

func ResolveMethod(store Store, service, method string, paramTypes []string) (Result, error)

ResolveMethod looks up a method on a service and disambiguates overloads.

Rules:

  • service and method are required; empty values return *errcode.Error with input.service-missing / input.method-missing.
  • service not in store → contract.unresolvable with hint to doctor.
  • no method with name → contract.method-not-found.
  • one overload → returned directly, Selected=0.
  • many overloads + no paramTypes → contract.method-ambiguous.
  • many overloads + paramTypes → exact match first, then assignable match (caller type can be passed to declared type) if exact did not match. Non-unique matches return contract.method-ambiguous.

paramTypes are expected to be fully qualified names (e.g. "java.lang.String").

type ServiceDiscovery

type ServiceDiscovery struct {
	Source            string
	Suffixes          []string
	CandidateServices []string
	SelectedServices  []string
}

func DiscoverServiceInterfaces

func DiscoverServiceInterfaces(store Store, opts ServiceDiscoveryOptions) ServiceDiscovery

type ServiceDiscoveryOptions

type ServiceDiscoveryOptions struct {
	Suffixes      []string
	IndexedSource string
	StoreSource   string
}

type Store

type Store interface {
	Class(fqn string) (javamodel.Class, bool)
}

Store returns class metadata by FQN. It MUST return ok=false for unknown types rather than a zero-valued Class — callers rely on the flag to decide whether to fall back to another source.

type TypeSpec

type TypeSpec struct {
	Base       string
	Args       []TypeSpec
	ArrayDepth int
	Wildcard   WildcardKind
}

TypeSpec is the parsed form of a Java type expression used by both skeleton rendering and invoke-time argument normalization.

func ParseTypeSpec

func ParseTypeSpec(s string) TypeSpec

func (TypeSpec) Effective

func (t TypeSpec) Effective() TypeSpec

func (TypeSpec) Element

func (t TypeSpec) Element() TypeSpec

func (TypeSpec) IsZero

func (t TypeSpec) IsZero() bool

type WildcardKind

type WildcardKind int
const (
	WildcardNone WildcardKind = iota
	WildcardAny
	WildcardExtends
	WildcardSuper
)

Jump to

Keyboard shortcuts

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