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
- func BuildSkeleton(paramTypes []string, store Store) []json.RawMessage
- func ClassLookup(store Store) javatype.ClassLookup
- func ListMethods(store Store, service string) (javamodel.Class, []javamodel.Method, error)
- func NormalizeArgs(paramTypes []string, args []any, store Store) ([]any, error)
- func NormalizeJSONArgs(paramTypes []string, args []any, store Store) ([]any, error)
- func NormalizeServiceNameSuffixes(raw []string) []string
- func PlainJSONArgs(args []any) ([]any, error)
- func ResolvedFields(store Store, fqn string) []javamodel.Field
- func RewriteWireTypeNames(args []any, store Store) []any
- func ValidateJSONNumberSafety(raw any) error
- func WireParamTypes(paramTypes []string, store Store) []string
- type DiagnosticStore
- type Diagnostics
- type InMemoryStore
- type IndexedClassStore
- type Result
- type ServiceDiscovery
- type ServiceDiscoveryOptions
- type Store
- type TypeSpec
- type WildcardKind
Constants ¶
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 ¶
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 ¶
NormalizeArgs performs contract-aware semantic normalization. Its output is still replayable JSON-like data; sofarpcwire owns the later Hessian adapter preparation step.
func NormalizeJSONArgs ¶
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 PlainJSONArgs ¶
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 RewriteWireTypeNames ¶
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 ¶
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 ¶
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 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 ¶
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 Store ¶
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 ¶
type WildcardKind ¶
type WildcardKind int
const ( WildcardNone WildcardKind = iota WildcardAny WildcardExtends WildcardSuper )