High-level API Helpers
Relevant source files
The following files were used as context for generating this wiki page:
High-level API helpers in the regxa project provide a simplified, PURL-native interface for interacting with various package registries. These helpers act as a convenience layer over the core registry logic, allowing developers to fetch package metadata, versions, dependencies, and maintainers using a single string identifier (Package URL) without manually instantiating specific registry clients.
These utilities handle the internal routing from a PURL to the correct ecosystem adapter (e.g., npm, PyPI, Cargo) and normalize the returned data into consistent TypeScript types. This allows for ecosystem-agnostic package querying across the supported registries.
Sources: src/helpers.ts, README.md:16-24, skills/regxa/SKILL.md:43-55
PURL-Based Fetching Utilities
The primary helpers wrap the createFromPURL factory method to resolve a PURL into a registry instance and a package name, then execute the corresponding fetch operation.
Core Fetch Functions
| Function | Purpose | Requirements |
|---|---|---|
fetchPackageFromPURL | Fetches normalized metadata for a package. | Valid PURL |
fetchVersionsFromPURL | Retrieves all available versions for a package. | Valid PURL |
fetchDependenciesFromPURL | Retrieves dependencies for a specific version. | PURL must include a version |
fetchMaintainersFromPURL | Retrieves a list of package maintainers. | Valid PURL |
Sources: src/helpers.ts:6-42, skills/regxa/references/api-reference.md:58-62
Dependency Lookup Logic
Unlike other helpers, fetchDependenciesFromPURL enforces the presence of a version within the PURL. If a version is missing, it throws an InvalidPURLError.
The flow shows the validation requirement for dependency lookups.
Sources: src/helpers.ts:24-32, test/unit/helpers.test.ts:133-140
Bulk Operations and Concurrency
The bulkFetchPackages helper allows for concurrent metadata retrieval for multiple PURLs. It implements a worker-pool pattern to limit the number of simultaneous network requests.
- Concurrency: Defaults to 15 simultaneous workers but is configurable via options.
- Resilience: Failed lookups for individual packages are silently skipped; the resulting Map only contains successful fetches.
- Cancellation: Supports
AbortSignalto stop workers mid-flight.
Sources: src/helpers.ts:44-73, skills/regxa/references/api-reference.md:82-90
Diagram showing the worker-based concurrent fetch mechanism.
Sources: src/helpers.ts:54-70, test/unit/helpers.test.ts:182-205
Version and URL Resolution
Version Selection Logic
The selectVersion utility provides a deterministic way to pick the "best" version from a list of versions retrieved from a registry.
- Requested Match: If a specific version is requested and has a "clean" status (not yanked/deprecated), it is returned.
- Latest Match: If the registry's "latest" version is provided and clean, it is returned.
- Newest Clean: If no matches are found, it sorts all clean versions by
publishedAtdate and returns the most recent one.
Sources: src/helpers.ts:85-115, test/unit/helpers.test.ts:51-105
URL Resolution Helpers
These helpers resolve documentation and resource links using a fallback chain to ensure a valid URL is provided even if the registry response is incomplete.
- resolveDocsUrl:
package.documentationpackage.homepageURLBuilder.documentation()(Ecosystem default)
- resolveReadmeUrl: Uses the ecosystem-specific
URLBuilderto construct a README link (e.g., via JSDelivr for npm).
Sources: src/helpers.ts:125-142, test/unit/helpers.test.ts:107-131
Registry Factory Integration
The helpers rely on the internal registry.ts factory and the createFromPURL utility. The registry factory manages a map of ecosystem-specific implementations (npm, pypi, cargo, gem, composer, alpm).
Diagram illustrating the relationship between the high-level helpers and the underlying registry implementations.
Sources: src/core/registry.ts:4-53, README.md:95-105
High-level API helpers encapsulate the complexity of PURL parsing and registry-specific logic into a unified interface. By providing normalized data structures and consistent resolution logic (for versions and URLs), they enable developers to build multi-ecosystem tools with minimal boilerplate.