core

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package core provides core NuGet types for package identity and metadata.

It defines PackageIdentity for uniquely identifying packages and PackageMetadata for complete package information including dependencies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResetGlobalRepositoryCache

func ResetGlobalRepositoryCache()

ResetGlobalRepositoryCache clears the global repository cache (for testing only). WARNING: This should only be used in tests.

Types

type Client

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

Client provides high-level NuGet package operations

func NewClient

func NewClient(cfg ClientConfig) *Client

NewClient creates a new NuGet client

func (*Client) CreateDependencyWalker

func (c *Client) CreateDependencyWalker(sources []string, targetFramework string) (*resolver.DependencyWalker, error)

CreateDependencyWalker creates a DependencyWalker using the client's efficient metadata adapter. The adapter uses V3 registration API to fetch all versions in a single HTTP call.

func (*Client) CreateMetadataClient

func (c *Client) CreateMetadataClient(sources []string) (resolver.PackageMetadataClient, error)

CreateMetadataClient creates a PackageMetadataClient using the client's efficient adapter. The adapter uses V3 registration API to fetch all versions in a single HTTP call.

func (*Client) DownloadPackage

func (c *Client) DownloadPackage(ctx context.Context, packageID, versionStr string) (io.ReadCloser, error)

DownloadPackage downloads a package from the first repository that has it

func (*Client) FindBestVersion

func (c *Client) FindBestVersion(ctx context.Context, packageID string, versionRange *version.Range) (*version.NuGetVersion, error)

FindBestVersion finds the best matching version for a version range

func (*Client) GetCompatibleDependencies

func (c *Client) GetCompatibleDependencies(metadata *PackageMetadata) ([]PackageDependency, error)

GetCompatibleDependencies filters dependencies for the target framework

func (*Client) GetPackageMetadata

func (c *Client) GetPackageMetadata(ctx context.Context, packageID, versionStr string) (*ProtocolMetadata, error)

GetPackageMetadata retrieves metadata for a specific package version from the first repository that has it

func (*Client) GetRepositoryManager

func (c *Client) GetRepositoryManager() *RepositoryManager

GetRepositoryManager returns the repository manager

func (*Client) GetTargetFramework

func (c *Client) GetTargetFramework() *frameworks.NuGetFramework

GetTargetFramework returns the current target framework

func (*Client) ListVersions

func (c *Client) ListVersions(ctx context.Context, packageID string) ([]string, error)

ListVersions lists all versions from all repositories

func (*Client) ResolvePackageDependencies

func (c *Client) ResolvePackageDependencies(
	ctx context.Context,
	packageID string,
	versionStr string,
) (*resolver.ResolutionResult, error)

ResolvePackageDependencies resolves all dependencies for a package

func (*Client) ResolvePackageVersion

func (c *Client) ResolvePackageVersion(ctx context.Context, packageID, versionStr string, includePrerelease bool) (*version.NuGetVersion, error)

ResolvePackageVersion resolves a version string (exact or range) to a specific version

func (*Client) SearchPackages

func (c *Client) SearchPackages(ctx context.Context, query string, opts SearchOptions) (map[string][]SearchResult, error)

SearchPackages searches for packages across all repositories

func (*Client) SetTargetFramework

func (c *Client) SetTargetFramework(fw *frameworks.NuGetFramework)

SetTargetFramework sets the target framework for package operations

type ClientConfig

type ClientConfig struct {
	RepositoryManager *RepositoryManager
	TargetFramework   *frameworks.NuGetFramework
}

ClientConfig holds client configuration

type HTTPClient

type HTTPClient interface {
	Do(ctx context.Context, req *http.Request) (*http.Response, error)
	Get(ctx context.Context, url string) (*http.Response, error)
	DoWithRetry(ctx context.Context, req *http.Request) (*http.Response, error)
	SetUserAgent(ua string)
}

HTTPClient defines the interface for making HTTP requests

type InstallPackageRequest

type InstallPackageRequest struct {
	PackageID         string
	Version           string // Can be specific version or range
	TargetFramework   *frameworks.NuGetFramework
	IncludePrerelease bool
}

InstallPackageRequest represents a package installation request

type PackageDependency

type PackageDependency struct {
	// ID is the dependency package ID
	ID string

	// VersionRange is the accepted version range
	VersionRange *version.Range

	// Include specifies which assets to include (e.g., "All", "Runtime")
	Include []string

	// Exclude specifies which assets to exclude
	Exclude []string
}

PackageDependency represents a dependency on another package.

type PackageDependencyGroup

type PackageDependencyGroup struct {
	// TargetFramework is the framework these dependencies apply to
	TargetFramework *frameworks.NuGetFramework

	// Dependencies is the list of package dependencies
	Dependencies []PackageDependency
}

PackageDependencyGroup represents dependencies for a specific target framework.

type PackageIdentity

type PackageIdentity struct {
	// ID is the package identifier (case-insensitive)
	ID string

	// Version is the package version
	Version *version.NuGetVersion
}

PackageIdentity represents a unique package identifier.

func NewPackageIdentity

func NewPackageIdentity(id string, ver *version.NuGetVersion) PackageIdentity

NewPackageIdentity creates a new package identity.

func (PackageIdentity) Equals

func (p PackageIdentity) Equals(other PackageIdentity) bool

Equals checks if two package identities are equal. Package IDs are compared case-insensitively.

func (PackageIdentity) String

func (p PackageIdentity) String() string

String returns a string representation of the package identity.

type PackageMetadata

type PackageMetadata struct {
	// Identity is the package identity
	Identity PackageIdentity

	// Title is the human-friendly package title
	Title string

	// Authors are the package authors
	Authors []string

	// Owners are the package owners
	Owners []string

	// Description is the package description
	Description string

	// Summary is a short package summary
	Summary string

	// ProjectURL is the project website URL
	ProjectURL string

	// LicenseURL is the license URL
	LicenseURL string

	// IconURL is the icon URL
	IconURL string

	// Tags are package tags/keywords
	Tags []string

	// DependencyGroups contains dependencies organized by target framework
	DependencyGroups []PackageDependencyGroup

	// RequireLicenseAcceptance indicates if license acceptance is required
	RequireLicenseAcceptance bool

	// Listed indicates if the package is listed in search results
	Listed bool
}

PackageMetadata represents complete package metadata.

func (*PackageMetadata) GetDependenciesForFramework

func (m *PackageMetadata) GetDependenciesForFramework(target *frameworks.NuGetFramework) []PackageDependency

GetDependenciesForFramework returns dependencies for a specific target framework. Returns the most compatible dependency group, or nil if no compatible group found.

type ProtocolDependency

type ProtocolDependency struct {
	ID    string
	Range string
}

ProtocolDependency represents a single dependency (string-based)

type ProtocolDependencyGroup

type ProtocolDependencyGroup struct {
	TargetFramework string
	Dependencies    []ProtocolDependency
}

ProtocolDependencyGroup represents dependencies for a target framework (string-based)

type ProtocolMetadata

type ProtocolMetadata struct {
	ID                       string
	Version                  string
	Title                    string
	Description              string
	Summary                  string
	Authors                  []string
	Owners                   []string
	IconURL                  string
	LicenseURL               string
	LicenseExpression        string
	ProjectURL               string
	Tags                     []string
	Dependencies             []ProtocolDependencyGroup
	DownloadCount            int64
	IsPrerelease             bool
	Published                string
	RequireLicenseAcceptance bool
	DownloadURL              string
}

ProtocolMetadata represents package metadata from protocol (string-based, simple types)

type ProviderFactory

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

ProviderFactory creates resource providers based on protocol detection

func NewProviderFactory

func NewProviderFactory(httpClient HTTPClient, mtCache *cache.MultiTierCache) *ProviderFactory

NewProviderFactory creates a new provider factory cache can be nil if caching is not desired

func (*ProviderFactory) CreateProvider

func (f *ProviderFactory) CreateProvider(ctx context.Context, sourceURL string) (ResourceProvider, error)

CreateProvider creates a resource provider for the given source URL Automatically detects v2 vs v3 protocol

func (*ProviderFactory) CreateV2Provider

func (f *ProviderFactory) CreateV2Provider(sourceURL string) ResourceProvider

CreateV2Provider creates a v2 resource provider (no detection)

func (*ProviderFactory) CreateV3Provider

func (f *ProviderFactory) CreateV3Provider(sourceURL string) ResourceProvider

CreateV3Provider creates a v3 resource provider (no detection)

type RepositoryConfig

type RepositoryConfig struct {
	Name          string
	SourceURL     string
	Authenticator auth.Authenticator
	HTTPClient    *nugethttp.Client
	Cache         *cache.MultiTierCache // Optional cache (nil disables caching)
	Logger        observability.Logger  // Optional logger (nil uses NullLogger)
}

RepositoryConfig holds source repository configuration

type RepositoryManager

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

RepositoryManager manages multiple package sources

func NewRepositoryManager

func NewRepositoryManager() *RepositoryManager

NewRepositoryManager creates a new repository manager

func (*RepositoryManager) AddRepository

func (m *RepositoryManager) AddRepository(repo *SourceRepository) error

AddRepository adds a source repository

func (*RepositoryManager) GetRepository

func (m *RepositoryManager) GetRepository(name string) (*SourceRepository, error)

GetRepository returns a repository by name

func (*RepositoryManager) ListRepositories

func (m *RepositoryManager) ListRepositories() []*SourceRepository

ListRepositories returns all registered repositories

func (*RepositoryManager) RemoveRepository

func (m *RepositoryManager) RemoveRepository(name string) error

RemoveRepository removes a source repository by name

func (*RepositoryManager) SearchAll

func (m *RepositoryManager) SearchAll(ctx context.Context, cacheCtx *cache.SourceCacheContext, query string, opts SearchOptions) (map[string][]SearchResult, error)

SearchAll searches for packages across all repositories cacheCtx controls caching behavior (can be nil for default behavior)

type ResourceProvider

type ResourceProvider interface {
	// GetMetadata retrieves metadata for a specific package version
	// cacheCtx controls caching behavior (can be nil for default behavior)
	GetMetadata(ctx context.Context, cacheCtx *cache.SourceCacheContext, packageID, version string) (*ProtocolMetadata, error)

	// ListVersions lists all available versions for a package
	// cacheCtx controls caching behavior (can be nil for default behavior)
	ListVersions(ctx context.Context, cacheCtx *cache.SourceCacheContext, packageID string) ([]string, error)

	// Search searches for packages matching the query
	// cacheCtx controls caching behavior (can be nil for default behavior)
	Search(ctx context.Context, cacheCtx *cache.SourceCacheContext, query string, opts SearchOptions) ([]SearchResult, error)

	// DownloadPackage downloads a .nupkg file
	// cacheCtx controls caching behavior (can be nil for default behavior)
	DownloadPackage(ctx context.Context, cacheCtx *cache.SourceCacheContext, packageID, version string) (io.ReadCloser, error)

	// SourceURL returns the source URL for this provider
	SourceURL() string

	// ProtocolVersion returns the protocol version (v2 or v3)
	ProtocolVersion() string
}

ResourceProvider provides access to NuGet resources (search, metadata, download) Abstracts differences between v2 and v3 protocols

type SearchOptions

type SearchOptions struct {
	Skip              int
	Take              int
	IncludePrerelease bool
}

SearchOptions holds common search parameters

type SearchResult

type SearchResult struct {
	ID             string
	Version        string
	Description    string
	Authors        []string
	IconURL        string
	Tags           []string
	TotalDownloads int64
	Verified       bool
}

SearchResult represents a search result from any protocol version

type SourceRepository

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

SourceRepository represents a NuGet package source with authentication

func GetOrCreateRepository

func GetOrCreateRepository(sourceURL string) *SourceRepository

GetOrCreateRepository returns a cached SourceRepository for the given source URL, or creates a new one if it doesn't exist. This is critical for performance - it reuses HTTP clients and protocol providers across multiple restore operations.

func NewSourceRepository

func NewSourceRepository(cfg RepositoryConfig) *SourceRepository

NewSourceRepository creates a new source repository

func (*SourceRepository) DownloadPackage

func (r *SourceRepository) DownloadPackage(ctx context.Context, cacheCtx *cache.SourceCacheContext, packageID, version string) (io.ReadCloser, error)

DownloadPackage downloads a .nupkg file cacheCtx controls caching behavior (can be nil for default behavior)

func (*SourceRepository) GetMetadata

func (r *SourceRepository) GetMetadata(ctx context.Context, cacheCtx *cache.SourceCacheContext, packageID, version string) (*ProtocolMetadata, error)

GetMetadata retrieves metadata for a specific package version cacheCtx controls caching behavior (can be nil for default behavior)

func (*SourceRepository) GetProvider

func (r *SourceRepository) GetProvider(ctx context.Context) (ResourceProvider, error)

GetProvider returns the resource provider for this repository Lazily initializes and caches the provider

func (*SourceRepository) ListVersions

func (r *SourceRepository) ListVersions(ctx context.Context, cacheCtx *cache.SourceCacheContext, packageID string) ([]string, error)

ListVersions lists all available versions for a package cacheCtx controls caching behavior (can be nil for default behavior)

func (*SourceRepository) Name

func (r *SourceRepository) Name() string

Name returns the repository name

func (*SourceRepository) Search

func (r *SourceRepository) Search(ctx context.Context, cacheCtx *cache.SourceCacheContext, query string, opts SearchOptions) ([]SearchResult, error)

Search searches for packages matching the query cacheCtx controls caching behavior (can be nil for default behavior)

func (*SourceRepository) SourceURL

func (r *SourceRepository) SourceURL() string

SourceURL returns the source URL

type V2ResourceProvider

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

V2ResourceProvider implements ResourceProvider for NuGet v2 feeds

func NewV2ResourceProvider

func NewV2ResourceProvider(sourceURL string, httpClient HTTPClient, mtCache *cache.MultiTierCache) *V2ResourceProvider

NewV2ResourceProvider creates a new v2 resource provider mtCache can be nil if caching is not desired

func (*V2ResourceProvider) DownloadPackage

func (p *V2ResourceProvider) DownloadPackage(ctx context.Context, cacheCtx *cache.SourceCacheContext, packageID, version string) (io.ReadCloser, error)

DownloadPackage downloads a .nupkg file

func (*V2ResourceProvider) FindPackagesByID

func (p *V2ResourceProvider) FindPackagesByID(ctx context.Context, cacheCtx *cache.SourceCacheContext, packageID string) ([]*ProtocolMetadata, error)

FindPackagesByID retrieves all versions of a package with full metadata in a single call. This is the efficient V2 method matching NuGet.Client's DependencyInfoResourceV2Feed.

func (*V2ResourceProvider) GetMetadata

func (p *V2ResourceProvider) GetMetadata(ctx context.Context, cacheCtx *cache.SourceCacheContext, packageID, version string) (*ProtocolMetadata, error)

GetMetadata retrieves metadata for a specific package version. Uses V2 OData feed to fetch detailed package information.

func (*V2ResourceProvider) ListVersions

func (p *V2ResourceProvider) ListVersions(ctx context.Context, cacheCtx *cache.SourceCacheContext, packageID string) ([]string, error)

ListVersions lists all available versions for a package

func (*V2ResourceProvider) ProtocolVersion

func (p *V2ResourceProvider) ProtocolVersion() string

ProtocolVersion returns "v2"

func (*V2ResourceProvider) Search

func (p *V2ResourceProvider) Search(ctx context.Context, cacheCtx *cache.SourceCacheContext, query string, opts SearchOptions) ([]SearchResult, error)

Search searches for packages matching the query

func (*V2ResourceProvider) SourceURL

func (p *V2ResourceProvider) SourceURL() string

SourceURL returns the source URL

type V3ResourceProvider

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

V3ResourceProvider implements ResourceProvider for NuGet v3 feeds

func NewV3ResourceProvider

func NewV3ResourceProvider(sourceURL string, httpClient HTTPClient, mtCache *cache.MultiTierCache) *V3ResourceProvider

NewV3ResourceProvider creates a new v3 resource provider mtCache can be nil if caching is not desired For normal V3 feeds: sourceURL is the service index URL For fast-path: use NewV3ResourceProviderWithServiceIndex to specify different URLs

func NewV3ResourceProviderWithServiceIndex

func NewV3ResourceProviderWithServiceIndex(sourceURL, serviceIndexURL string, httpClient HTTPClient, mtCache *cache.MultiTierCache) *V3ResourceProvider

NewV3ResourceProviderWithServiceIndex creates a V3 provider with separate source and service index URLs sourceURL: Repository identifier (used for matching repositories) serviceIndexURL: Actual V3 service index endpoint Used for nuget.org fast-path: sourceURL="https://www.nuget.org/api/v2", serviceIndexURL="https://api.nuget.org/v3/index.json"

func (*V3ResourceProvider) DownloadPackage

func (p *V3ResourceProvider) DownloadPackage(ctx context.Context, cacheCtx *cache.SourceCacheContext, packageID, version string) (io.ReadCloser, error)

DownloadPackage downloads a .nupkg file

func (*V3ResourceProvider) GetMetadata

func (p *V3ResourceProvider) GetMetadata(ctx context.Context, cacheCtx *cache.SourceCacheContext, packageID, version string) (*ProtocolMetadata, error)

GetMetadata retrieves metadata for a specific package version

func (*V3ResourceProvider) ListVersions

func (p *V3ResourceProvider) ListVersions(ctx context.Context, cacheCtx *cache.SourceCacheContext, packageID string) ([]string, error)

ListVersions lists all available versions for a package

func (*V3ResourceProvider) ProtocolVersion

func (p *V3ResourceProvider) ProtocolVersion() string

ProtocolVersion returns "v3"

func (*V3ResourceProvider) Search

func (p *V3ResourceProvider) Search(ctx context.Context, cacheCtx *cache.SourceCacheContext, query string, opts SearchOptions) ([]SearchResult, error)

Search searches for packages matching the query

func (*V3ResourceProvider) ServiceIndexURL

func (p *V3ResourceProvider) ServiceIndexURL() string

ServiceIndexURL returns the V3 service index URL

func (*V3ResourceProvider) SourceURL

func (p *V3ResourceProvider) SourceURL() string

SourceURL returns the source URL

Directories

Path Synopsis
Package resolver implements NuGet dependency resolution algorithms.
Package resolver implements NuGet dependency resolution algorithms.

Jump to

Keyboard shortcuts

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