types

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ScopeProd     = "prod"
	ScopeDev      = "dev"
	ScopeTest     = "test"
	ScopeBuild    = "build"
	ScopeOptional = "optional"
	ScopePeer     = "peer"
	// Maven-specific scopes
	ScopeSystem = "system"
	ScopeImport = "import"
)

Dependency scope constants

Variables

This section is empty.

Functions

func CalculateRelativePath

func CalculateRelativePath(fileName, currentPath, basePath string) string

CalculateRelativePath calculates the relative file path from basePath, normalizing it to start with "/" or return "/" for root. This eliminates the repeated pattern across all detectors.

func GenerateComponentID

func GenerateComponentID(rootID, name, relativePath string) string

GenerateComponentID generates a deterministic 20-character ID for child components. It combines the root ID, component name, and relative path to create unique, reproducible IDs within a scan context. Components with different names at the same path will have different IDs.

func GenerateRootID

func GenerateRootID() string

GenerateRootID generates a unique 12-character random ID for root/main components. Each scan gets a unique root ID, ensuring all component IDs within that scan are unique.

func LanguageTypeToString

func LanguageTypeToString(t enry.Type) string

LanguageTypeToString converts enry.Type to string (programming, data, markup, prose)

func NewMetadata

func NewMetadata(source string) map[string]interface{}

NewMetadata creates a new metadata map with the source field set This helper eliminates code duplication across parsers

Types

type CategoriesConfig

type CategoriesConfig struct {
	Categories map[string]CategoryDefinition `yaml:"categories" json:"categories"`
}

CategoriesConfig represents the categories.yaml configuration file

type CategoryDefinition

type CategoryDefinition struct {
	IsComponent bool   `yaml:"is_component" json:"is_component"`
	CreateEdges *bool  `yaml:"create_edges,omitempty" json:"create_edges,omitempty"`
	Description string `yaml:"description,omitempty" json:"description,omitempty"`
}

CategoryDefinition represents a technology category configuration

type CategoryInfo

type CategoryInfo struct {
	Name        string `json:"name"`
	IsComponent bool   `json:"is_component"`
	Description string `json:"description"`
}

CategoryInfo represents a single category entry

type CompiledDependency

type CompiledDependency struct {
	Regex *regexp.Regexp
	Tech  string
	Name  string
	Type  string
}

CompiledDependency is a pre-compiled dependency for performance

func (*CompiledDependency) Match

func (cd *CompiledDependency) Match(s string) bool

Match checks if the dependency matches the given string

type ComponentRef

type ComponentRef struct {
	TargetID    string `json:"target_id"`    // Component ID being depended on
	PackageName string `json:"package_name"` // Package name that created the link
}

ComponentRef represents a reference to another component in the same project

type ContentRule

type ContentRule struct {
	Type       string   `yaml:"type,omitempty" json:"type,omitempty"`             // Match type: "regex" (default), "json-path", "json-schema", "yaml-path"
	Pattern    string   `yaml:"pattern,omitempty" json:"pattern,omitempty"`       // Regex pattern (for type=regex) or expected value (for path types)
	Path       string   `yaml:"path,omitempty" json:"path,omitempty"`             // JSON/YAML path (e.g., "$.$schema", "$.name")
	Value      string   `yaml:"value,omitempty" json:"value,omitempty"`           // Expected value for path matching (exact match or regex if starts/ends with /)
	Extensions []string `yaml:"extensions,omitempty" json:"extensions,omitempty"` // Optional: limit pattern to specific extensions
	Files      []string `yaml:"files,omitempty" json:"files,omitempty"`           // Optional: limit pattern to specific filenames
}

ContentRule represents a content-based detection pattern

func (*ContentRule) GetType

func (c *ContentRule) GetType() string

GetType returns the content rule type, defaulting to "regex" if not specified

type Dependency

type Dependency struct {
	Type       string                 `yaml:"type" json:"type"`
	Name       string                 `yaml:"name" json:"name"`
	Version    string                 `yaml:"version,omitempty" json:"version,omitempty"`
	Scope      string                 `yaml:"scope,omitempty" json:"scope,omitempty"`
	Direct     bool                   `yaml:"direct" json:"direct"`                               // Direct (true) vs transitive (false) dependency
	SourceFile string                 `yaml:"source_file,omitempty" json:"source_file,omitempty"` // Deprecated: use metadata.source instead
	Metadata   map[string]interface{} `yaml:"metadata,omitempty" json:"metadata,omitempty"`       // Package-specific metadata (source, type, classifier, optional, exclusions, peer, etc.)
}

Dependency represents a dependency pattern (struct for YAML, but marshals as array for JSON)

func (*Dependency) Compile

func (d *Dependency) Compile() (*CompiledDependency, error)

Compile compiles a dependency pattern to regex for performance

func (Dependency) MarshalJSON

func (d Dependency) MarshalJSON() ([]byte, error)

MarshalJSON converts Dependency struct to array format [type, name, version, scope, direct, {metadata}] Format: 6 elements (always consistent) - [type, name, version, scope, direct, {metadata}] - scope: "prod", "dev", "test", "build", "optional", "peer", etc. (empty string if unknown) - direct: true (declared in manifest) or false (transitive) - metadata: optional object with source, type, classifier, exclusions, peer, optional, bundled, etc.

type Edge

type Edge struct {
	Target *Payload `json:"target"`
}

Edge represents a relationship between components and technologies

func (Edge) MarshalJSON

func (e Edge) MarshalJSON() ([]byte, error)

MarshalJSON customizes Edge JSON serialization (target as ID string)

type File

type File struct {
	Name     string `json:"name"`
	Path     string `json:"path"`
	Type     string `json:"type"` // "file" or "dir"
	Size     int64  `json:"size"`
	Modified int64  `json:"modified"`
}

File represents a file or directory entry

type FileReader

type FileReader interface {
	io.Reader
	io.Seeker
	io.Closer
}

FileReader defines an interface for reading file content

type License

type License struct {
	LicenseName     string  `json:"license_name"`               // Primary SPDX identifier (e.g., "MIT", "Apache-2.0")
	DetectionType   string  `json:"detection_type"`             // "direct", "normalized", "toml_parsed", "file_based"
	SourceFile      string  `json:"source_file"`                // Where detected (e.g., "package.json", "pyproject.toml")
	Confidence      float64 `json:"confidence"`                 // Detection confidence (0.0-1.0)
	OriginalLicense string  `json:"original_license,omitempty"` // Original license before normalization
}

License represents a structured license entity for knowledge graph integration

type Payload

type Payload struct {
	Metadata         interface{}            `json:"metadata,omitempty"`
	Git              *git.GitInfo           `json:"git,omitempty"`
	ID               string                 `json:"id"`
	Name             string                 `json:"name"`
	Path             []string               `json:"path"`
	ComponentType    string                 `json:"type,omitempty"` // Type of component (e.g., "maven", "nodejs", "python")
	Tech             []string               `json:"tech"`           // Changed from *string to []string to support multiple primary technologies
	Techs            []string               `json:"techs"`
	Languages        map[string]int         `json:"languages"`
	PrimaryLanguages []PrimaryLanguage      `json:"primary_languages,omitempty"` // Top programming languages (from code_stats)
	Licenses         []License              `json:"licenses"`                    // Changed to structured License objects
	Reason           map[string][]string    `json:"reason"`                      // Maps technology to detection reasons, "_" for non-tech reasons
	Dependencies     []Dependency           `json:"dependencies"`
	Properties       map[string]interface{} `json:"properties,omitempty"`
	Childs           []*Payload             `json:"childs"` // Changed from Children to Childs
	Edges            []Edge                 `json:"edges"`
	ComponentRefs    []ComponentRef         `json:"component_refs,omitempty"` // Inter-component references (outgoing - components this component depends on)
	CodeStats        interface{}            `json:"code_stats,omitempty"`
}

Payload represents the analysis result for a directory or component

func NewComponentPayload

func NewComponentPayload(name, fileName, currentPath, basePath, componentType string) *Payload

NewComponentPayload creates a payload for a component with common initialization pattern: - Calculates relative file path - Sets component type - Adds primary tech This eliminates the repetitive pattern found in all detectors.

func NewPayload

func NewPayload(name string, paths []string) *Payload

NewPayload creates a new payload with a temporary ID (will be finalized by AssignIDs)

func NewPayloadWithPath

func NewPayloadWithPath(name, path string) *Payload

NewPayloadWithPath creates a new payload with a single path (convenience function)

func (*Payload) AddChild

func (p *Payload) AddChild(service *Payload) *Payload

AddChild adds a child payload with deduplication

func (*Payload) AddDependency

func (p *Payload) AddDependency(dep Dependency)

AddDependency adds a dependency with deduplication

func (*Payload) AddDockerReason

func (p *Payload) AddDockerReason(reason string)

AddDockerReason adds a Docker-related reason to the "_docker" key

func (*Payload) AddEdges

func (p *Payload) AddEdges(target *Payload)

AddEdges adds an edge to another payload

func (*Payload) AddLanguage

func (p *Payload) AddLanguage(language string)

AddLanguage increments the count for a language

func (*Payload) AddLanguageWithCount

func (p *Payload) AddLanguageWithCount(language string, count int)

AddLanguageWithCount increments the count for a language

func (*Payload) AddLicense

func (p *Payload) AddLicense(license License)

AddLicense adds a license to the payload, deduplicating by name

func (*Payload) AddLicenseReason

func (p *Payload) AddLicenseReason(reason string)

AddLicenseReason adds a license-related reason to the "_license" key

func (*Payload) AddPath

func (p *Payload) AddPath(path string)

AddPath adds a path to the payload, deduplicating entries

func (*Payload) AddPrimaryTech

func (p *Payload) AddPrimaryTech(tech string)

AddPrimaryTech adds a technology to the primary tech array (avoiding duplicates)

func (*Payload) AddReason

func (p *Payload) AddReason(reason string)

AddReason adds a non-tech reason to the "_" key

func (*Payload) AddTech

func (p *Payload) AddTech(tech string, reason string)

AddTech adds a technology to the payload

func (*Payload) AddTechs

func (p *Payload) AddTechs(techs map[string][]string)

AddTechs adds multiple technologies

func (*Payload) AssignIDs

func (p *Payload) AssignIDs(rootID string)

AssignIDs assigns unique IDs to the entire payload tree. The root gets the provided ID (or generates random if empty), and all children get deterministic IDs based on the root ID + their relative path. This should be called once after the entire tree is built.

func (*Payload) Combine

func (p *Payload) Combine(other *Payload)

Combine merges another payload into this one

func (*Payload) DetectLanguage

func (p *Payload) DetectLanguage(filename string, content []byte)

DetectLanguage detects the language from a file name using a LanguageDetector This is a convenience method that delegates to the language detector Deprecated: Use LanguageDetector directly for better modularity

func (*Payload) GetFullPath

func (p *Payload) GetFullPath() string

GetFullPath returns the full path as a string

func (*Payload) HasPrimaryTech

func (p *Payload) HasPrimaryTech(tech string) bool

HasPrimaryTech checks if a technology is in the primary tech array

func (*Payload) SetComponentProperties

func (p *Payload) SetComponentProperties(techKey string, properties map[string]interface{})

SetComponentProperties sets multiple properties for a component technology. Example: payload.SetComponentProperties("python", map[string]interface{}{"package_name": "myapp", "version": "1.0"})

func (*Payload) SetComponentProperty

func (p *Payload) SetComponentProperty(techKey, propertyKey string, value interface{})

SetComponentProperty sets a property for a component technology. Standardizes on map[string]interface{} for flexibility while providing a clean API. Example: payload.SetComponentProperty("nodejs", "package_name", "@org/package")

func (*Payload) SetComponentType

func (p *Payload) SetComponentType(componentType string)

SetComponentType sets the component type (e.g., "maven", "nodejs", "python") This should be called by detectors to identify what kind of component this is

func (*Payload) String

func (p *Payload) String() string

String returns a string representation

type PrimaryLanguage

type PrimaryLanguage struct {
	Language string  `json:"language"`
	Pct      float64 `json:"pct"`
}

PrimaryLanguage represents a primary programming language (top languages by lines of code)

type Provider

type Provider interface {
	// ListDir returns the contents of a directory
	ListDir(path string) ([]File, error)

	// Open returns the content of a file
	Open(path string) (string, error)

	// Exists checks if a file or directory exists
	Exists(path string) (bool, error)

	// IsDir checks if a path is a directory
	IsDir(path string) (bool, error)

	// ReadFile reads file content as bytes
	ReadFile(path string) ([]byte, error)

	// GetBasePath returns the base path for this provider
	GetBasePath() string
}

Provider defines the interface for file system operations

type Rule

type Rule struct {
	Tech          string                 `yaml:"tech" json:"tech"`
	Name          string                 `yaml:"name" json:"name"`
	Type          string                 `yaml:"type" json:"type"`
	Description   string                 `yaml:"description,omitempty" json:"description,omitempty"`
	Properties    map[string]interface{} `yaml:"properties,omitempty" json:"properties,omitempty"`
	IsComponent   *bool                  `yaml:"is_component,omitempty" json:"is_component,omitempty"`       // nil = auto (use type-based logic)
	IsPrimaryTech *bool                  `yaml:"is_primary_tech,omitempty" json:"is_primary_tech,omitempty"` // nil = use current logic (component = primary tech)
	DotEnv        []string               `yaml:"dotenv,omitempty" json:"dotenv,omitempty"`
	Dependencies  []Dependency           `yaml:"dependencies,omitempty" json:"dependencies,omitempty"`
	Files         []string               `yaml:"files,omitempty" json:"files,omitempty"`
	Extensions    []string               `yaml:"extensions,omitempty" json:"extensions,omitempty"`
	Content       []ContentRule          `yaml:"content,omitempty" json:"content,omitempty"`
}

Rule represents a technology detection rule

type TechInfo

type TechInfo struct {
	Name          string                 `json:"name"`
	Tech          string                 `json:"tech"`
	Category      string                 `json:"category"`
	Description   string                 `json:"description,omitempty"`
	IsPrimaryTech *bool                  `json:"is_primary_tech,omitempty"`
	Properties    map[string]interface{} `json:"properties,omitempty"`
}

TechInfo holds information about a technology

Jump to

Keyboard shortcuts

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