facts

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: Apache-2.0 Imports: 12 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 facts defines the canonical semantic facts every language produces.

TypeScript and Go resolve code with different engines and different vocabularies. This package is where both converge: after normalisation a fact carries no trace of the engine that produced it beyond its declared provenance, so the graph can store one model instead of two.

Index

Constants

View Source
const (
	CodeContainsPackage uint8 = iota + 1
	CodeContainsFile
	CodeDefines
	CodePackageDependsOn
	CodeModuleDependsOn
	CodeImportsSymbol
	CodeExports
	CodeReexports
	CodeReferences
	CodeCallsDirect
	CodePassesAsCallback
	CodeAssignsFunction
	CodeReturnsFunction
	CodeTypeUses
	CodeImplements
	CodeExtends
	CodeEmbeds
	CodeOverrides
)

Edge kind codes. Frozen: append only.

View Source
const (
	CodeExactTypechecked uint8 = iota + 1
	CodeExactDeclarationMapped
	CodeExactPackageMapped
	CodeStructuralCertain
	CodeCandidate
	CodeUnresolved
)

Confidence codes. Frozen: append only. The order matches the strength ordering of the model, strongest first, so a comparison on the code is a comparison on strength.

View Source
const (
	CodeTypeScriptChecker uint8 = iota + 1
	CodeTypeScriptModuleResolution
	CodeTypeScriptDeclarationMap
	CodeTypeScriptProjectReference
	CodeGoTypesDefinition
	CodeGoTypesUse
	CodeGoTypesSelection
	CodeGoASTCall
	CodeGoASTCallback
	CodeGoObjectPath
	CodeTreeSitterSyntax
	CodePackageManifest
	// Appended for Rust. Never inserted above: a snapshot stores these
	// numbers, and renumbering one rewrites the meaning of every edge that
	// carries it.
	CodeRustAnalyzerDefinition
	CodeRustAnalyzerUse
	CodeRustAnalyzerMoniker
	CodeRustSyntaxCall
	CodeRustSyntaxType
	CodeRustSyntaxImplementation
	CodeRustSyntaxCallback
)

Provenance codes. Frozen: append only.

View Source
const (
	// TypeScriptIdentityDeclarationMap marks a target the artifact's own
	// `.d.ts.map` placed inside the provider's source.
	TypeScriptIdentityDeclarationMap = "DECLARATION_MAP"
	// TypeScriptIdentityProviderExport marks a target the provider's own
	// checker named, as the export of a source file the provider's project
	// roots mapped its declaration artifact to. The position is exact and
	// comes from the compiler that owns the code, but the artifact-to-source
	// step rests on the provider's build configuration rather than on a map
	// it emitted, so the edge is graded ExactPackageMapped. See ADR 0038.
	TypeScriptIdentityProviderExport = "PROVIDER_EXPORT"
)
View Source
const CodeFormatVersion uint16 = 1

CodeFormatVersion is the version of the numbering below. The HotSnapshot stores kinds, confidences and provenances as bare uint8 codes and filters traversals by them, so a snapshot is only readable by code that agrees on this numbering. Reordering or reusing a code is a format break: bump this version instead, and never renumber an existing constant.

View Source
const RepositoryKeyPrefix = "repository:"

RepositoryKeyPrefix opens the durable key of a repository. It is exported because the read surface filters by that key, so a caller's value has to be read back as a name in one place rather than by matching the literal in several.

View Source
const TypeScriptWireVersion = 4

TypeScriptWireVersion is the version of the `ts-facts-v4` payload.

Variables

View Source
var ErrInvalidDelta = errors.New("invalid delta")

ErrInvalidDelta reports a delta that cannot be applied coherently.

View Source
var ErrInvalidFacts = errors.New("invalid fact set")

ErrInvalidFacts reports a fact set that cannot be stored.

View Source
var ErrUnknownCode = errors.New("unknown canonical code")

ErrUnknownCode reports a code outside the canonical numbering.

Functions

func EvidenceKey

func EvidenceKey(fileKey string, start, end int) string

EvidenceKey builds the durable key of one observation.

func FileKey

func FileKey(repository, path string) string

FileKey builds the durable key of a file, from its repository relative path.

func IsSyntheticRepository

func IsSyntheticRepository(name string) bool

IsSyntheticRepository reports whether a repository is one Kivgraph derives from the machine -- today the standard library of a Rust toolchain -- rather than one a user registered. The reserved namespace is enforced when a name is registered, so the name is the answer and no row carries a second copy of it.

func NormalizeGo

func NormalizeGo(ctx context.Context, input GoInput) (Set, GoReport, error)

NormalizeGo converts the facts of one Go load into the canonical model.

Only facts with a durable identity on both ends become edges. A reference whose target is not indexed is not downgraded to a name: it is dropped and counted, because a graph edge without identity is a wrong edge.

func NormalizeRust

func NormalizeRust(ctx context.Context, input RustInput) (Set, RustReport, error)

NormalizeRust converts the analysis of one Cargo workspace into the canonical model.

Only facts with a durable identity on both ends become edges. A target in another repository is named by the key its provider publishes, so this Set alone fails Validate with a dangling edge until the caller merges the provider's Set in -- the same contract the TypeScript and Go paths keep.

func NormalizeTypeScript

func NormalizeTypeScript(
	ctx context.Context,
	payload TypeScriptPayload,
	repository workspace.Repository,
) (Set, TypeScriptReport, error)

NormalizeTypeScript converts a worker payload into the canonical model.

repository is the registered repository the payload was produced from. The payload carries only repository-relative paths, and the worker cannot observe the git state of the tree it read: both come from the caller, the same way NormalizeGo and NormalizeRust take them.

func PackageKey

func PackageKey(language Language, repository, name string) string

PackageKey builds the durable key of a package or module.

func RepositoryKey

func RepositoryKey(name string) string

RepositoryKey builds the durable key of a repository.

func RepositoryNameFromKey

func RepositoryNameFromKey(value string) string

RepositoryNameFromKey reads the name out of a repository key, and returns its argument unchanged when it is already a name.

func UnresolvedKey

func UnresolvedKey(reference UnresolvedReference) string

UnresolvedKey derives the durable key of an unresolved reference from the same identity Merge deduplicates on.

The file key already carries the repository, so it is the scope whenever there is one. An entry without a file -- a class a provider declares, a module that would not load -- is scoped by the repository instead: two repositories declaring the same class are two facts, and sharing one key made them one row and then a duplicate primary key when they did not.

Types

type Confidence

type Confidence string

Confidence is the trust level of an edge, as defined by the plan.

const (
	// ExactTypechecked is backed by a type checker resolution.
	ExactTypechecked Confidence = "EXACT_TYPECHECKED"
	// ExactDeclarationMapped is backed by a declaration map.
	ExactDeclarationMapped Confidence = "EXACT_DECLARATION_MAPPED"
	// ExactPackageMapped is backed by a registered package provider.
	ExactPackageMapped Confidence = "EXACT_PACKAGE_MAPPED"
	// StructuralCertain is backed by an unambiguous structural rule.
	StructuralCertain Confidence = "STRUCTURAL_CERTAIN"
	// Candidate is plausible but not proven.
	Candidate Confidence = "CANDIDATE"
	// Unresolved carries no target identity.
	Unresolved Confidence = "UNRESOLVED"
)

func ConfidenceFromCode

func ConfidenceFromCode(code uint8) (Confidence, error)

ConfidenceFromCode decodes a stored confidence.

func (Confidence) Code

func (confidence Confidence) Code() (uint8, error)

Code returns the frozen numeric code of the confidence.

func (Confidence) Exact

func (confidence Confidence) Exact() bool

Exact reports whether a confidence level may take part in exact results.

type Delta

type Delta struct {
	// ReplacedFiles are durable file keys whose facts are fully restated by
	// Upsert. Everything anchored on them is withdrawn first.
	ReplacedFiles []string
	// RemovedFiles are durable file keys that disappeared entirely.
	RemovedFiles []string
	// Upsert is the state that must exist once the delta is applied.
	Upsert Set
}

Delta is a change to the canonical model, expressed in file units: an incremental index reacts to a file changing, so everything that file asserted is withdrawn and restated. See Diff for how one is computed and Delta.Validate for what makes one coherent.

func Diff

func Diff(previous, next Set) (Delta, error)

Diff computes the delta that turns previous into next.

Both sets must already be valid (Set.Validate passes). Upsert's contents come straight from next, so a next that is not itself a coherent graph — a dangling edge, an unknown package — would otherwise propagate silently into the delta instead of failing where the actual problem is.

Repository and Package records are monotonic membership metadata in this model: a Delta only ever adds or refreshes one (always alongside the file(s) that need it, per design decision 4), never withdraws one. That mirrors CanonicalMutationResult, which accounts for removed files, symbols, evidence and edges but has no notion of a removed package or repository. PACKAGE_DEPENDS_ON and MODULE_DEPENDS_ON — genuine package to package relationships, not containment — are outside what a file-grained Delta tracks at all; CONTAINS_PACKAGE is not (see addNeededContainers and edgeAnchor for the two halves of why).

func (Delta) Empty

func (delta Delta) Empty() bool

Empty reports whether the delta would change nothing.

func (Delta) Validate

func (delta Delta) Validate() error

Validate rejects a delta that cannot be applied coherently.

Upsert is a fragment, not a closed graph, so it is deliberately NOT checked with Set.Validate. A delta that replaces or adds one file legitimately carries edges whose other endpoint — a caller, a callee, an implementer — lives in the part of the graph the delta does not touch. Set.Validate demands every edge endpoint resolve inside the very set it is checking; applying that rule to Upsert in isolation would reject exactly the deltas this type exists to describe, so a dangling-looking edge is not, by itself, a defect here.

What must still hold for a fragment is narrower than for a closed graph:

  • every record has the fields Set.Validate would call required, so a malformed entry is never accepted;
  • no collection holds two entries with the same durable identity — Set.Merge silently keeps the first and drops the rest, which is the wrong behaviour for a delta about to be applied transactionally: a silent drop there would apply something other than what Diff computed;
  • the references a fragment is never allowed to omit — a package's repository, a file's repository and package, a symbol's file and package, evidence's file, an edge's evidence, an unresolved reference's repository/file/source symbol — resolve inside Upsert. These, unlike an edge's source or target, are never external: Diff always includes a file's repository and package alongside it (design decision 4), and a symbol, evidence entry or unresolved reference never travels without the file that anchors it (design decision 1).
  • a file is never named in both ReplacedFiles and RemovedFiles — that would ask an applier to both retire and restate the same file inside one transaction.

type Edge

type Edge struct {
	Kind       EdgeKind   `json:"kind"`
	SourceKey  string     `json:"source_key"`
	TargetKey  string     `json:"target_key"`
	Confidence Confidence `json:"confidence"`
	Provenance Provenance `json:"provenance"`
	// EvidenceKey links the edge to its observation, when it has one.
	EvidenceKey string `json:"evidence_key,omitempty"`
}

Edge is one relation between two symbols or containers.

type EdgeKind

type EdgeKind string

EdgeKind is the relation vocabulary of the graph.

const (
	ContainsPackage  EdgeKind = "CONTAINS_PACKAGE"
	ContainsFile     EdgeKind = "CONTAINS_FILE"
	Defines          EdgeKind = "DEFINES"
	PackageDependsOn EdgeKind = "PACKAGE_DEPENDS_ON"
	ModuleDependsOn  EdgeKind = "MODULE_DEPENDS_ON"

	ImportsSymbol EdgeKind = "IMPORTS_SYMBOL"
	Exports       EdgeKind = "EXPORTS"
	Reexports     EdgeKind = "REEXPORTS"

	References       EdgeKind = "REFERENCES"
	CallsDirect      EdgeKind = "CALLS_DIRECT"
	PassesAsCallback EdgeKind = "PASSES_AS_CALLBACK"
	AssignsFunction  EdgeKind = "ASSIGNS_FUNCTION"
	ReturnsFunction  EdgeKind = "RETURNS_FUNCTION"

	TypeUses   EdgeKind = "TYPE_USES"
	Implements EdgeKind = "IMPLEMENTS"
	Extends    EdgeKind = "EXTENDS"
	Embeds     EdgeKind = "EMBEDS"
	Overrides  EdgeKind = "OVERRIDES"
)

func EdgeKindFromCode

func EdgeKindFromCode(code uint8) (EdgeKind, error)

EdgeKindFromCode decodes a stored edge kind.

func (EdgeKind) Code

func (kind EdgeKind) Code() (uint8, error)

Code returns the frozen numeric code of the kind.

func (EdgeKind) Valid

func (kind EdgeKind) Valid() bool

Valid reports whether the kind belongs to the graph vocabulary.

type Evidence

type Evidence struct {
	Key           string   `json:"key"`
	RepositoryKey string   `json:"repository_key"`
	FileKey       string   `json:"file_key"`
	Start         Position `json:"start"`
	End           Position `json:"end"`
	// Text is the source excerpt when it is small enough to retain.
	Text string `json:"text,omitempty"`
}

Evidence is the observation that supports one edge.

type File

type File struct {
	Key           string   `json:"key"`
	RepositoryKey string   `json:"repository_key"`
	PackageKey    string   `json:"package_key,omitempty"`
	Path          string   `json:"path"`
	Language      Language `json:"language"`
	ContentHash   string   `json:"content_hash,omitempty"`
	Generated     bool     `json:"generated,omitempty"`
}

File is one indexed source file.

type GoInput

type GoInput struct {
	Repository workspace.Repository
	// Definitions carry the durable identity assigned by LUQUE-0804.
	Definitions []goloader.KeyedDefinition
	// References are the classified uses of LUQUE-0806, 0807 and 0814.
	References []goloader.Reference
	// CrossRepository attributes targets to their provider repository.
	CrossRepository []goloader.CrossRepositoryReference
	// PackageDependencies are the deduplicated (source, target) package
	// pairs a package-boundary use belongs to. Each one may become
	// PACKAGE_DEPENDS_ON and, when it also crosses a Go module boundary,
	// MODULE_DEPENDS_ON.
	PackageDependencies []goloader.PackageDependency
	// TypeRelations are the IMPLEMENTS, EMBEDS and OVERRIDES facts: structural
	// relations the type checker decides on its own, with no source
	// occurrence of their own to anchor them.
	TypeRelations []goloader.TypeRelation
	// Unresolved are the classified failures of LUQUE-0810.
	Unresolved []goloader.UnresolvedReference
}

GoInput is one normalisation request: the facts of a single Go load.

type GoReport

type GoReport struct {
	// EdgesWithoutSource counts references, type relations and package
	// dependencies whose source has no durable identity in this pass,
	// typically a use at file scope or a package with no definitions.
	EdgesWithoutSource int
	// EdgesWithoutTarget counts references, type relations and package
	// dependencies whose target is not indexed in this pass and was not
	// attributed to a provider repository.
	EdgesWithoutTarget int
	// UnresolvedWithoutFile counts module-level failures with no file.
	UnresolvedWithoutFile int
}

GoReport records what normalisation could not keep, so a dropped fact is visible instead of silently missing.

type Language

type Language string

Language identifies the engine domain a fact belongs to.

const (
	// LanguageTypeScript marks facts produced by the TypeScript worker.
	LanguageTypeScript Language = "typescript"
	// LanguageGo marks facts produced by the Go loader.
	LanguageGo Language = "go"
	// LanguageRust marks facts produced by the Rust loader over the index
	// rust-analyzer emits.
	LanguageRust Language = "rust"
)

type Package

type Package struct {
	Key           string   `json:"key"`
	RepositoryKey string   `json:"repository_key"`
	Language      Language `json:"language"`
	Name          string   `json:"name"`
	Version       string   `json:"version,omitempty"`
	RootPath      string   `json:"root_path"`
	ManifestPath  string   `json:"manifest_path,omitempty"`
	// Container is the module a Go package belongs to, empty otherwise.
	Container string `json:"container,omitempty"`
}

Package is one package or module of a repository.

type Position

type Position struct {
	Line   int `json:"line"`
	Column int `json:"column"`
	Offset int `json:"offset"`
}

Position is a source location. Lines are one based, columns zero based.

type Provenance

type Provenance string

Provenance names the mechanism that produced a fact.

const (
	TypeScriptChecker          Provenance = "TYPESCRIPT_CHECKER"
	TypeScriptModuleResolution Provenance = "TYPESCRIPT_MODULE_RESOLUTION"
	TypeScriptDeclarationMap   Provenance = "TYPESCRIPT_DECLARATION_MAP"
	TypeScriptProjectReference Provenance = "TYPESCRIPT_PROJECT_REFERENCE"

	GoTypesDefinition Provenance = "GO_TYPES_DEF"
	GoTypesUse        Provenance = "GO_TYPES_USE"
	GoTypesSelection  Provenance = "GO_TYPES_SELECTION"
	GoASTCall         Provenance = "GO_AST_CALL"
	GoASTCallback     Provenance = "GO_AST_CALLBACK"
	GoObjectPath      Provenance = "GO_OBJECT_PATH"

	// RustAnalyzerDefinition marks a declaration the analyzer indexed.
	RustAnalyzerDefinition Provenance = "RUST_ANALYZER_DEF"
	// RustAnalyzerUse marks a use the analyzer resolved to a symbol.
	RustAnalyzerUse Provenance = "RUST_ANALYZER_USE"
	// RustAnalyzerMoniker marks a target reached through the crate registry,
	// where consumer and provider carry the same analyzer symbol.
	RustAnalyzerMoniker Provenance = "RUST_ANALYZER_MONIKER"
	// RustSyntaxCall and RustSyntaxType mark relations whose ends the
	// analyzer resolved and whose class the grammar decided, exactly as
	// GoASTCall does over a go/types resolution.
	RustSyntaxCall Provenance = "RUST_SYNTAX_CALL"
	RustSyntaxType Provenance = "RUST_SYNTAX_TYPE"
	// RustSyntaxImplementation marks an implementation, a supertrait or an
	// override: the grammar says which token of the header is the trait and
	// which is the type, and the analyzer resolved both.
	RustSyntaxImplementation Provenance = "RUST_SYNTAX_IMPL"
	// RustSyntaxCallback marks a function named as the argument of a call,
	// the Rust half of GoASTCallback. Binding a function to a name or
	// returning it carries no provenance of its own: the class is in the
	// edge kind and the target came from the analyzer, as Go does.
	RustSyntaxCallback Provenance = "RUST_SYNTAX_CALLBACK"

	TreeSitterSyntax Provenance = "TREE_SITTER_SYNTAX"
	PackageManifest  Provenance = "PACKAGE_MANIFEST"
)

func ProvenanceFromCode

func ProvenanceFromCode(code uint8) (Provenance, error)

ProvenanceFromCode decodes a stored provenance.

func (Provenance) Code

func (provenance Provenance) Code() (uint8, error)

Code returns the frozen numeric code of the provenance.

func (Provenance) Exact

func (provenance Provenance) Exact() bool

Exact reports whether a provenance can support an exact edge. A relation produced only by Tree-sitter never is, as the plan requires.

type Repository

type Repository struct {
	Key       string     `json:"key"`
	Name      string     `json:"name"`
	RootPath  string     `json:"root_path"`
	Commit    string     `json:"commit,omitempty"`
	Branch    string     `json:"branch,omitempty"`
	Dirty     bool       `json:"dirty,omitempty"`
	Languages []Language `json:"languages,omitempty"`
}

Repository is one indexed repository.

type RustInput

type RustInput struct {
	Repository workspace.Repository
	Analysis   rustloader.Analysis
}

RustInput is one normalisation request: the facts of a single Cargo workspace, as the analyzer indexed it.

type RustReport

type RustReport struct {
	// EdgesWithoutSource counts uses with no enclosing declaration.
	EdgesWithoutSource int
	// EdgesWithoutTarget counts edges this Set could not close: an end it
	// could not place in a file or a crate of its own, or a target of this
	// repository that the pass decided not to publish. No merge resolves
	// either, so the edge is dropped here instead of dangling in the graph.
	EdgesWithoutTarget int
	// FilesWithoutPackage counts indexed files whose crate no manifest of this
	// workspace declares. They are dropped: a file belongs to exactly one
	// package, and a row without one is rejected when the generation is built.
	FilesWithoutPackage int
	// DefinitionsWithoutCrate counts symbols whose crate no manifest of this
	// workspace declares, which is a discovery and an index that disagree.
	DefinitionsWithoutCrate int
	// UnresolvedWithoutFile counts workspace level failures with no file.
	UnresolvedWithoutFile int
}

RustReport records what normalisation could not keep, so a dropped fact is visible instead of silently missing.

type Set

type Set struct {
	Repositories []Repository          `json:"repositories"`
	Packages     []Package             `json:"packages"`
	Files        []File                `json:"files"`
	Symbols      []Symbol              `json:"symbols"`
	Evidence     []Evidence            `json:"evidence"`
	Edges        []Edge                `json:"edges"`
	Unresolved   []UnresolvedReference `json:"unresolved"`
}

Set is the normalised output of one indexing pass.

func MergeAll

func MergeAll(sets []Set) Set

MergeAll merges every set at once, deduplicated by durable key and sorted a single time.

Merging pairwise costs the whole accumulated set on every step: a thirty-three unit pass rebuilt and re-sorted two hundred thousand edges thirty-three times, which is quadratic in the size of the graph and was the largest single source of garbage in a full index.

func (*Set) Merge

func (set *Set) Merge(other Set)

Merge appends another set, keeping the result deduplicated by durable key.

Two repositories indexed in the same pass share provider symbols; merging by key is what keeps one symbol from becoming two nodes.

func (*Set) Sort

func (set *Set) Sort()

Sort orders every collection by its durable key, so two runs over the same sources produce byte identical output.

func (Set) Validate

func (set Set) Validate() error

Validate rejects a fact set that would corrupt the graph.

Every reference must resolve inside the set: a dangling edge is not a partial fact, it is a wrong one.

type Symbol

type Symbol struct {
	// Key is the durable stable key of LUQUE-0303.
	Key string `json:"key"`
	// CanonicalIdentity is the auditable text the key derives from.
	CanonicalIdentity string   `json:"canonical_identity"`
	RepositoryKey     string   `json:"repository_key"`
	PackageKey        string   `json:"package_key"`
	FileKey           string   `json:"file_key"`
	Language          Language `json:"language"`
	Name              string   `json:"name"`
	QualifiedName     string   `json:"qualified_name"`
	Kind              string   `json:"kind"`
	Exported          bool     `json:"exported"`
	Signature         string   `json:"signature,omitempty"`
	Start             Position `json:"start"`
	End               Position `json:"end"`
}

Symbol is one addressable declaration.

type TypeScriptDependency

type TypeScriptDependency struct {
	// Repository and Package name the provider exactly as PackageKey derives
	// it: the repository Kivgraph indexes it under, and its own package name.
	Repository string `json:"repository"`
	Package    string `json:"package"`
	// File, Specifier, Start, End and StartLine are one deterministic import
	// occurrence proving the dependency — never every occurrence, since a
	// single edge needs only one witness.
	File      string `json:"file"`
	Specifier string `json:"specifier"`
	Start     int    `json:"start"`
	End       int    `json:"end"`
	StartLine int    `json:"startLine"`
}

TypeScriptDependency is one real dependency from this repository's own package to another package the checker proved this repository imports from — never a nominal `package.json` entry, which may list a package nothing actually imports. TypeScript has no module concept distinct from its package, so this alone never becomes MODULE_DEPENDS_ON; only a Go package crossing a module boundary does.

type TypeScriptExport

type TypeScriptExport struct {
	File                string                  `json:"file"`
	Kind                string                  `json:"kind"`
	QualifiedName       string                  `json:"qualifiedName"`
	Start               int                     `json:"start"`
	End                 int                     `json:"end"`
	StartLine           int                     `json:"startLine"`
	Text                string                  `json:"text"`
	TargetQualifiedName string                  `json:"targetQualifiedName"`
	TargetFile          string                  `json:"targetFile"`
	Target              *TypeScriptImportTarget `json:"target"`
	RequestedPackage    string                  `json:"requestedPackage"`
	RequestedSymbol     string                  `json:"requestedSymbol"`
	Reason              string                  `json:"reason"`
	Detail              string                  `json:"detail"`
}

TypeScriptExport is one export or re-export binding of the file: the worker turns the public name itself into an "export" kind TypeScriptSymbol, so QualifiedName here names an entry already present in Symbols. It resolves exactly one of two ways:

  • TargetQualifiedName/TargetFile name a declaration already present in this same payload's Symbols — a direct export, or a re-export whose `from` clause stays inside this repository.
  • Target carries the provider-source identity of a declaration in another repository — a re-export whose `from` clause names a package. Target is nil when that identity is not exactly known, exactly like an import without one: the binding still becomes an UnresolvedReference, never a guessed edge.

type TypeScriptExtends

type TypeScriptExtends struct {
	File                string                  `json:"file"`
	QualifiedName       string                  `json:"qualifiedName"`
	Start               int                     `json:"start"`
	End                 int                     `json:"end"`
	StartLine           int                     `json:"startLine"`
	Text                string                  `json:"text"`
	TargetQualifiedName string                  `json:"targetQualifiedName"`
	TargetFile          string                  `json:"targetFile"`
	Target              *TypeScriptImportTarget `json:"target"`
	RequestedPackage    string                  `json:"requestedPackage"`
	RequestedSymbol     string                  `json:"requestedSymbol"`
	Reason              string                  `json:"reason"`
	Detail              string                  `json:"detail"`
}

TypeScriptExtends is one base of a `class ... extends` or `interface ... extends` clause: QualifiedName names the class or interface declaring the clause, already present in Symbols — a heritage clause introduces no binding of its own, unlike an import or an export. It resolves exactly one of two ways, exactly like TypeScriptExport:

  • TargetQualifiedName/TargetFile name a declaration already present in this same payload's Symbols — a base declared in this repository.
  • Target carries the provider-source identity of a declaration in another repository — a base introduced by an import whose module specifier names a package. Target is nil when that identity is not exactly known, exactly like an import without one: the base still becomes an UnresolvedReference, never a guessed edge.

TypeScript's `implements` never produces one of these: see the worker's extends-resolver.ts for why.

type TypeScriptImport

type TypeScriptImport struct {
	File             string                  `json:"file"`
	QualifiedName    string                  `json:"qualifiedName"`
	Start            int                     `json:"start"`
	End              int                     `json:"end"`
	StartLine        int                     `json:"startLine"`
	Text             string                  `json:"text"`
	RequestedPackage string                  `json:"requestedPackage"`
	RequestedSymbol  string                  `json:"requestedSymbol"`
	Target           *TypeScriptImportTarget `json:"target"`
	Reason           string                  `json:"reason"`
	Detail           string                  `json:"detail"`
}

TypeScriptImport is one import binding of the consumer. The worker already turns the binding itself into an "import" kind TypeScriptSymbol, so QualifiedName here names an entry already present in Symbols; Target is the provider declaration it reaches, or nil when that declaration is not exactly known.

type TypeScriptImportTarget

type TypeScriptImportTarget struct {
	Repository    string `json:"repository"`
	Package       string `json:"package"`
	QualifiedName string `json:"qualifiedName"`
	Kind          string `json:"kind"`
	Signature     string `json:"signature"`
	File          string `json:"file"`
	StartLine     int    `json:"startLine"`
	// Source names how the provider source position was reached. An empty
	// value means a declaration map, which is what every payload recorded
	// before the provider-export path existed carries.
	Source string `json:"source,omitempty"`
}

TypeScriptImportTarget is the provider declaration an import binding reaches, described exactly as the provider indexes it when it normalises itself: computed from the provider's own source, at the position the provider-source bridge resolved. Never derived from the consumer's `.d.ts` text, which is not guaranteed to restate the source.

A `TypeScriptExport` that crosses into another repository reuses this exact shape: a re-exported symbol needs the same provider-source proof an imported one does.

type TypeScriptPackage

type TypeScriptPackage struct {
	Name         string `json:"name"`
	Version      string `json:"version"`
	RootPath     string `json:"rootPath"`
	ManifestPath string `json:"manifestPath"`
}

TypeScriptPackage is the npm package of the repository, with repository relative paths so a recorded payload stays portable.

type TypeScriptPayload

type TypeScriptPayload struct {
	Version      int                    `json:"version"`
	Repository   TypeScriptRepository   `json:"repository"`
	Package      *TypeScriptPackage     `json:"package"`
	Files        []string               `json:"files"`
	Symbols      []TypeScriptSymbol     `json:"symbols"`
	References   []TypeScriptReference  `json:"references"`
	Imports      []TypeScriptImport     `json:"imports"`
	Exports      []TypeScriptExport     `json:"exports"`
	Extends      []TypeScriptExtends    `json:"extends"`
	Dependencies []TypeScriptDependency `json:"dependencies"`
	Unresolved   []TypeScriptUnresolved `json:"unresolved"`
}

TypeScriptPayload is the fact payload the worker emits for one repository.

The worker reports identity components and positions; it never computes a key. Deriving keys on a single side is what keeps one symbol from getting two identities when a consumer and its provider are indexed separately.

func DecodeTypeScriptPayload

func DecodeTypeScriptPayload(data []byte) (TypeScriptPayload, error)

DecodeTypeScriptPayload parses a `ts-facts-v4` document.

type TypeScriptReference

type TypeScriptReference struct {
	File                string `json:"file"`
	Kind                string `json:"kind"`
	SourceQualifiedName string `json:"sourceQualifiedName"`
	TargetQualifiedName string `json:"targetQualifiedName"`
	TargetFile          string `json:"targetFile"`
	StartLine           int    `json:"startLine"`
	Start               int    `json:"start"`
	End                 int    `json:"end"`
	Text                string `json:"text"`
}

TypeScriptReference is one classified local use.

type TypeScriptReport

type TypeScriptReport struct {
	// EdgesWithoutSource counts uses at file scope, with no enclosing symbol.
	EdgesWithoutSource int
	// EdgesWithoutTarget counts uses whose target is not in this payload.
	EdgesWithoutTarget int
	// ImportsWithoutTarget counts import bindings whose provider declaration
	// is not exactly known: no declaration map reached it, or the reached
	// declaration carries no class or no signature.
	ImportsWithoutTarget int
	// ExportsWithoutTarget counts export/re-export bindings whose declaration
	// is not exactly known: neither a local declaration in this payload nor a
	// provider declaration reached with a class and a signature.
	ExportsWithoutTarget int
	// ExtendsWithoutTarget counts extends bases whose declaration is not
	// exactly known: neither a local declaration in this payload nor a
	// provider declaration reached with a class and a signature.
	ExtendsWithoutTarget int
}

TypeScriptReport records what normalisation could not keep.

type TypeScriptRepository

type TypeScriptRepository struct {
	Name string `json:"name"`
}

TypeScriptRepository names the repository the payload belongs to.

type TypeScriptSymbol

type TypeScriptSymbol struct {
	File          string `json:"file"`
	Name          string `json:"name"`
	QualifiedName string `json:"qualifiedName"`
	Kind          string `json:"kind"`
	Exported      bool   `json:"exported"`
	Signature     string `json:"signature"`
	StartLine     int    `json:"startLine"`
	EndLine       int    `json:"endLine"`
	Start         int    `json:"start"`
	End           int    `json:"end"`
}

TypeScriptSymbol is one local declaration reported by the worker.

type TypeScriptUnresolved

type TypeScriptUnresolved struct {
	File             string `json:"file"`
	Reason           string `json:"reason"`
	RequestedPackage string `json:"requestedPackage"`
	RequestedSymbol  string `json:"requestedSymbol"`
	Detail           string `json:"detail"`
	Start            int    `json:"start"`
}

TypeScriptUnresolved is one classified failure of the worker.

type UnresolvedReference

type UnresolvedReference struct {
	RepositoryKey string   `json:"repository_key"`
	FileKey       string   `json:"file_key,omitempty"`
	Language      Language `json:"language"`
	// SourceSymbolKey is the declaration that contains the reference.
	SourceSymbolKey  string   `json:"source_symbol_key,omitempty"`
	RequestedPackage string   `json:"requested_package,omitempty"`
	RequestedSymbol  string   `json:"requested_symbol,omitempty"`
	Reason           string   `json:"reason"`
	Detail           string   `json:"detail,omitempty"`
	Start            Position `json:"start"`
}

UnresolvedReference is a fact that could not become an exact edge.

Jump to

Keyboard shortcuts

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