Skip to main content

Registry

Struct Registry 

Source
pub struct Registry {
    pub base_url: String,
    pub detail: PackumentDetail,
}
Expand description

An npm-compatible registry. Defaults to the public registry and the abbreviated packument.

Fields§

§base_url: String§detail: PackumentDetail

How much of each packument to fetch. Abbreviated by default (faster); Full includes per-version license.

Implementations§

Source§

impl Registry

Source

pub fn npm() -> Self

The public npm registry (https://registry.npmjs.org).

Source

pub fn with_base_url(base_url: impl Into<String>) -> Self

A registry at a custom base URL (e.g. a private mirror).

Source

pub fn with_detail(self, detail: PackumentDetail) -> Self

Set how much of each packument to fetch (e.g. PackumentDetail::Full to capture license).

Source

pub fn tarball_url(&self, name: &str, version: &str) -> String

Conventional tarball URL for an exact version. Handles scoped names: @scope/pkg<base>/@scope/pkg/-/pkg-<version>.tgz.

Source

pub fn packument( &self, name: &str, ) -> Result<Value, Box<dyn Error + Send + Sync>>

Fetch the package metadata document (“packument”).

Source

pub fn resolve( &self, name: &str, range: &Range, ) -> Result<Resolved, Box<dyn Error + Send + Sync>>

Resolve the newest published version of name matching the range.

Source

pub fn search( &self, query: &str, limit: usize, ) -> Result<Vec<SearchResult>, Box<dyn Error + Send + Sync>>

Search the registry for query, returning up to limit results ranked by the registry’s own relevance score (npm’s /-/v1/search endpoint). limit is clamped to the registry’s 1..=250 window. Each result carries the package’s latest version and indexed metadata, not a range resolution — follow up with resolve to pin a version.

Source

pub fn resolve_tree( &self, roots: &[(String, Range)], ) -> Result<Vec<Resolved>, Box<dyn Error + Send + Sync>>

Resolve the transitive dependency graph of roots into a flat set — one version per package name (the npm v3+ node_modules layout). Each package’s dependencies are read straight from the registry metadata (no tarball extraction), every child resolved to its newest matching version, and the set de-duplicated by name. Cyclic graphs terminate (a name is resolved once). Returns the packages sorted by name. Packuments are prefetched concurrently (bounded, level by level); resolution order, version selection, errors, and output are deterministic and identical to a sequential walk.

MVP limitation: a single version per package name. Two incompatible requirements on the same package — a genuine conflict npm would resolve by nesting — is reported as an error rather than silently mis-resolved; resolve_tree_nested is the conflict-tolerant sibling that keeps a version per disagreeing range instead.

Source

pub fn resolve_tree_nested( &self, roots: &[(String, Range)], ) -> Result<Vec<Resolved>, Box<dyn Error + Send + Sync>>

Resolve the transitive dependency graph of roots the way npm’s nested node_modules does: a requirement an already-resolved version satisfies reuses it (npm’s dedupe), and requirements that disagree keep one resolved version per range instead of erroring like resolve_tree. Returns the packages sorted by name, then version — possibly several versions of one name.

This is the resolution an audit wants — a nested-compatible package/version set, not npm’s placement algorithm: no hoisting, no peer-dependency handling, and no os/cpu filtering (every platform’s optional deps are included — their advisories matter regardless of the auditing machine). optionalDependencies are traversed alongside dependencies; non-registry specs (git / path / tarball / workspace: / link:) and optional deps that fail to resolve are skipped — this method drops the Omission records, the crate-internal observed variant returns them. Installs keep resolve_tree’s flat one-version-per-name guarantee. Packuments are prefetched concurrently (bounded, level by level); the result is deterministic and identical to a sequential walk.

Trait Implementations§

Source§

impl Default for Registry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.