language

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToType

func ConvertToType[T any](data any) (*T, error)

ConvertToType converts data to a typed struct. If data is already the target type, returns it directly. If data is a map (from YAML deserialization), converts via JSON roundtrip.

Types

type EcosystemUtils

type EcosystemUtils interface {
	NormalizeName(name string) string
	CompareVersions(a, b string) (int, error)
}

EcosystemUtils defines shared utilities for ecosystem-specific operations. Used by consumers that only need name normalization or version comparison.

func MustGetEcosystemUtils

func MustGetEcosystemUtils(utils map[string]EcosystemUtils, ecosystem string) EcosystemUtils

type Language

type Language interface {
	FetchPackageFromRegistry(ctx context.Context, pkg models.PackageInfo) (*RegistryResponse, error)
	ExtractPackageMetadata(ctx context.Context, pkg models.PackageInfo, registryData any) (*models.PackageMetadata, *string, *string, error)
	ExtractVersionHistory(ctx context.Context, pkg models.PackageInfo, registryData any) (*models.VersionMetadata, error)

	// NormalizeName normalizes a package name according to ecosystem-specific rules.
	// For npm: case-sensitive (trim whitespace only)
	// For pypi: PEP 503 normalization (lowercase, [-_.] -> -)
	NormalizeName(name string) string

	// Metadata returns the static metadata for this language ecosystem
	Metadata() *metadata.Metadata

	DependencyFilePatterns() []string

	CompareVersions(a, b string) (int, error)
	ExtractPackageArchive(artifactPath, destDir string) error
	ExtractInstallScriptsFromFiles(files map[string]string) ([]string, error)
}

type RegistryResponse

type RegistryResponse struct {
	// Data is the parsed response from the registry API (e.g., NPMPackageData, PyPIPackageResponse).
	Data any `json:"data,omitempty"`

	// ReleaseData holds release/version history from the full package endpoint.
	// For PyPI with a version query, Data comes from /pypi/{name}/{version}/json
	// while ReleaseData comes from /pypi/{name}/json.
	// Nil when the full endpoint already provides both (npm, pypi without version).
	ReleaseData any `json:"release_data,omitempty"`

	// StatusCode is the HTTP status code from the registry API.
	StatusCode int `json:"status_code"`

	// Headers contains selected HTTP response headers.
	Headers map[string]string `json:"headers,omitempty"`
}

RegistryResponse contains the parsed API response and metadata from a package registry fetch.

Jump to

Keyboard shortcuts

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