Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion crates/spk-proto/schema/spk.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,44 @@ table PkgRequestOptionValue {
is_complete: bool;
}

enum VersionRangeOperator: uint8 {
// From: VersionRange enum in spk
Compat = 0,
DoubleEquals,
DoubleNotEquals,
Equals,
// Note, Filter (or VersionFilter) is not actually supported in an
// index. This operator is flattened out into other operators before
// the index is generated. It has an entry here for completeness.
Filter,
GreaterThan,
GreaterThanOrEqualTo,
LessThan,
LessThanOrEqualTo,
LowestSpecified,
NotEquals,
Semver,
Wildcard,
}


// A single rule in a VersionFilter
table VersionFilterRule {
filter_op: VersionRangeOperator;
// Used for: Compat, DoubleEqualsVersion, DoubleNotEqualsVersion,
// EqualsVersion, GreaterThanOrEqualToRange, GreaterThanRange,
// LessThanOrEqualToRange, LessThanRange, LowestSpecifiedRange,
// NotEqualsVersion, SemverRange WildCardRange
version: Version;
// Used for: Compat
required: LoneCompatRule;
// WildCardRange - ::MAX means *, aka None, and <::MAX means Some(number)
parts: [uint32];
// Some VersionRange(objects) have a 'specified' field. This is
// not stored here because it can be regenerated in the
// constructor when extracting the object from the index.
}

// A package request with options
table PkgRequestWithOptions {
// from pkg_request: PkgRequest. In spk, a PkgRequest contains a
Expand All @@ -174,7 +212,7 @@ table PkgRequestWithOptions {
// string, e.g. '>=1.2.3,<4,5,6' and parsed when needed.
// TODO: this will likely change in a future version because
// processing this is showing up in current profiling.
version_filter: string;
version_filter: [VersionFilterRule];
build: Build;
prerelease_policy: PreReleasePolicy;
inclusion_policy: InclusionPolicy;
Expand Down
6 changes: 0 additions & 6 deletions crates/spk-schema/crates/foundation/src/version/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,6 @@ impl Version {
}
}

/// Make a new Version from a string without checking it.
///
pub fn new_from_version_str(version_str: &str) -> Result<Self> {
Version::try_from(version_str)
}

/// The major version number (first component)
pub fn major(&self) -> u32 {
self.parts.first().copied().unwrap_or_default()
Expand Down
66 changes: 53 additions & 13 deletions crates/spk-schema/crates/foundation/src/version_range/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
// https://github.com/spkenv/spk

use std::borrow::Cow;
use std::collections::BTreeSet;
use std::convert::{TryFrom, TryInto};
use std::fmt::{Display, Write};
Expand Down Expand Up @@ -393,6 +394,10 @@ impl SemverRange {
minimum: minimum.try_into()?,
}))
}

pub fn version(&self) -> Cow<'_, Version> {
Cow::Borrowed(&self.minimum)
}
}

impl Ranged for SemverRange {
Expand Down Expand Up @@ -478,6 +483,10 @@ impl WildcardRange {
}
Ok(VersionRange::Wildcard(range))
}

pub fn parts(&self) -> Cow<'_, Vec<Option<u32>>> {
Cow::Borrowed(&self.parts)
}
}

impl Ranged for WildcardRange {
Expand Down Expand Up @@ -585,6 +594,10 @@ impl LowestSpecifiedRange {
base,
}
}

pub fn version(&self) -> Cow<'_, Version> {
Cow::Borrowed(&self.base)
}
}

impl TryFrom<Version> for LowestSpecifiedRange {
Expand Down Expand Up @@ -647,6 +660,10 @@ impl GreaterThanRange {
bound: boundary.try_into()?,
}))
}

pub fn version(&self) -> Cow<'_, Version> {
Cow::Borrowed(&self.bound)
}
}

impl Ranged for GreaterThanRange {
Expand Down Expand Up @@ -695,6 +712,10 @@ impl LessThanRange {
bound: boundary.try_into()?,
}))
}

pub fn version(&self) -> Cow<'_, Version> {
Cow::Borrowed(&self.bound)
}
}

impl Ranged for LessThanRange {
Expand Down Expand Up @@ -743,6 +764,10 @@ impl GreaterThanOrEqualToRange {
bound: boundary.try_into()?,
}))
}

pub fn version(&self) -> Cow<'_, Version> {
Cow::Borrowed(&self.bound)
}
}

impl Ranged for GreaterThanOrEqualToRange {
Expand Down Expand Up @@ -791,6 +816,10 @@ impl LessThanOrEqualToRange {
bound: boundary.try_into()?,
}))
}

pub fn version(&self) -> Cow<'_, Version> {
Cow::Borrowed(&self.bound)
}
}

impl Ranged for LessThanOrEqualToRange {
Expand Down Expand Up @@ -835,6 +864,10 @@ impl EqualsVersion {
pub fn version_range(version: Version) -> VersionRange {
VersionRange::Equals(Self { version })
}

pub fn version(&self) -> Cow<'_, Version> {
Cow::Borrowed(&self.version)
}
}

impl From<Version> for EqualsVersion {
Expand Down Expand Up @@ -904,6 +937,10 @@ impl NotEqualsVersion {
pub fn new(specified: usize, base: Version) -> Self {
Self { specified, base }
}

pub fn version(&self) -> Cow<'_, Version> {
Cow::Borrowed(&self.base)
}
}

impl From<Version> for NotEqualsVersion {
Expand Down Expand Up @@ -977,6 +1014,10 @@ impl DoubleEqualsVersion {
pub fn version_range(version: Version) -> VersionRange {
VersionRange::DoubleEquals(Self { version })
}

pub fn version(&self) -> Cow<'_, Version> {
Cow::Borrowed(&self.version)
}
}

impl From<Version> for DoubleEqualsVersion {
Expand Down Expand Up @@ -1043,6 +1084,10 @@ impl DoubleNotEqualsVersion {
pub fn new(specified: usize, base: Version) -> Self {
Self { specified, base }
}

pub fn version(&self) -> Cow<'_, Version> {
Cow::Borrowed(&self.base)
}
}

impl From<Version> for DoubleNotEqualsVersion {
Expand Down Expand Up @@ -1131,6 +1176,14 @@ impl CompatRange {
};
Ok(VersionRange::Compat(compat_range))
}

pub fn version(&self) -> Cow<'_, Version> {
Cow::Borrowed(&self.base)
}

pub fn required(&self) -> Option<CompatRule> {
self.required
}
}

impl Ranged for CompatRange {
Expand Down Expand Up @@ -1208,19 +1261,6 @@ impl VersionFilter {
}
}

/// Makes a VersionFilter from the given string, without checking
/// that it is valid. This is used by indexing.
///
/// # Safety
///
/// The caller must make sure the string parses ad a valid
/// VersionFilter.
pub unsafe fn new_unchecked(filter_string: &str) -> Self {
VersionFilter::from_str(filter_string).expect(
"A filter string given to VersionFilter::new_unchecked() should be a valid VersionFilter when parsed",
)
}

pub fn single(item: VersionRange) -> Self {
let mut filter = Self::default();
filter.rules.insert(item);
Expand Down
Loading
Loading