@csaf-rs/vers-like-specifier 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -21,7 +21,7 @@ Add `vers-like-specifier` to your `Cargo.toml`. The package is published on http
21
21
 
22
22
  ```toml
23
23
  [dependencies]
24
- vers-like-specifier = "0.1"
24
+ vers-like-specifier = "0.2"
25
25
  ```
26
26
 
27
27
  ## Usage
@@ -35,9 +35,9 @@ assert_eq!(vls.to_string(), ">=1.0.0|<2.0.0");
35
35
 
36
36
 
37
37
  let constraints = vls.constraints();
38
- assert_eq!(constraints[0].comparator(), &Comparator::GreaterThanOrEqual);
38
+ assert_eq!(constraints[0].comparator(), Comparator::GreaterThanOrEqual);
39
39
  assert_eq!(constraints[0].version().to_string(), "1.0.0");
40
- assert_eq!(constraints[1].comparator(), &Comparator::LessThan);
40
+ assert_eq!(constraints[1].comparator(), Comparator::LessThan);
41
41
  assert_eq!(constraints[1].version().to_string(), "2.0.0");
42
42
 
43
43
  // Because the VERS type is unknown, `contains` can only resolve a definite
@@ -46,11 +46,13 @@ assert_eq!(vls.contains("1.0.0"), Containment::Contained);
46
46
  assert_eq!(vls.contains("2.0.0"), Containment::NotContained);
47
47
  assert_eq!(vls.contains("1.5.0"), Containment::Undetermined);
48
48
 
49
- // The one exception: a vls pinning a single version is always decidable, since
50
- // containment then reduces to a plain string comparison.
51
- let pinned: Vls = "1.0.0".parse().unwrap();
52
- assert_eq!(pinned.contains("1.0.0"), Containment::Contained);
53
- assert_eq!(pinned.contains("2.0.0"), Containment::NotContained);
49
+ // The one exception: a vls containing only exact-match comparators (equal, not equal) is always decidable, since
50
+ // containment then reduces to a plain string comparison if there is a constraint with that version. If there isn't a
51
+ // constraint with the version, it is not contained by default.
52
+ let exact_only: Vls = "1.0.0|!=2.0.0".parse().unwrap();
53
+ assert_eq!(exact_only.contains("1.0.0"), Containment::Contained);
54
+ assert_eq!(exact_only.contains("2.0.0"), Containment::NotContained);
55
+ assert_eq!(exact_only.contains("3.0.0"), Containment::NotContained);
54
56
  ```
55
57
 
56
58
  ### JavaScript / WASM Usage
@@ -61,8 +63,6 @@ import init, { Vls, Constraint, Comparator, Containment } from "@csaf-rs/vers-li
61
63
  await init();
62
64
 
63
65
  const vls = Vls.parse(">=1.0.0|<2.0.0");
64
- console.log(vls.isSingleVersion()); // false
65
-
66
66
  const constraint = new Constraint(Comparator.GreaterThanOrEqual, "1.0.0");
67
67
  console.log(constraint.version); // "1.0.0"
68
68
 
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@csaf-rs/vers-like-specifier",
3
3
  "type": "module",
4
- "description": "vls (vers-like specifier) parser",
5
- "version": "0.1.3",
4
+ "description": "vls (VERS-like specifier) parser",
5
+ "version": "0.2.0",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
8
8
  "type": "git",
@@ -9,14 +9,14 @@
9
9
  export type VersionString = string;
10
10
 
11
11
  /**
12
- * Errors specific to a single constraint within a VLS string.
12
+ * Errors specific to a single constraint within a vls string.
13
13
  */
14
14
  export type ConstraintError = "EmptyConstraint" | "EmptyConstraintVersion" | { InvalidConstraintVersionCharacters: string[] };
15
15
 
16
16
  /**
17
17
  * Errors that can occur when parsing a vls string.
18
18
  */
19
- export type VlsError = "EmptyInput" | "ForbiddenAnyUsed" | { InvalidCharacters: string[] } | { InvalidConstraints: ConstraintError[] } | { DuplicateConstraintVersions: string[] } | { Serialization: string };
19
+ export type VlsError = "EmptyInput" | "ForbiddenAnyUsed" | { SingleVersionNotAllowed: string } | { InvalidCharacters: string[] } | { InvalidConstraints: ConstraintError[] } | { DuplicateConstraintVersions: string[] } | { Serialization: string };
20
20
 
21
21
 
22
22
  /**
@@ -61,7 +61,7 @@ export class Constraint {
61
61
  [Symbol.dispose](): void;
62
62
  /**
63
63
  * Construct a new [`Constraint`] from a [`Comparator`] and a version string, validating
64
- * the version string against the VLS grammar. Exposed as `new Constraint(comparator, version)`
64
+ * the version string against the vls grammar. Exposed as `new Constraint(comparator, version)`
65
65
  * in JS.
66
66
  *
67
67
  * # Errors
@@ -93,11 +93,12 @@ export class Constraint {
93
93
  * * No constraint's version matches exactly: containment cannot be resolved, as the VERS
94
94
  * type is unknown / unspecified → [`Containment::Undetermined`].
95
95
  *
96
- * The one exception is a [`Vls`] that pins a single version (see [`Vls::is_single_version`]):
97
- * since it has exactly one [`Comparator::Equal`] constraint, containment reduces to a plain
98
- * string comparison and is always decidable, regardless of VERS type. In that case,
99
- * *any* queried version resolves to either [`Containment::Contained`] or
100
- * [`Containment::NotContained`], never [`Containment::Undetermined`].
96
+ * The one exception is a [`Vls`] that uses only exact-match comparators (i.e.
97
+ * [`Comparator::Equal`] and/or [`Comparator::NotEqual`]).
98
+ * Here, containment is reduced to a plain string comparison and is always decidable,
99
+ * regardless of VERS type. In that case, *any* queried version resolves to either [`Containment::Contained`] or
100
+ * [`Containment::NotContained`] depending on the exact-match comparator if there is a constraint with
101
+ * the queried version, and always to [`Containment::NotContained`] if there is no constraint with that version.
101
102
  */
102
103
  export enum Containment {
103
104
  /**
@@ -162,11 +163,6 @@ export class Vls {
162
163
  * instance method `vls.contains(version)` in JS.
163
164
  */
164
165
  contains(version: string): Containment;
165
- /**
166
- * Return `true` if this specifier pins exactly one version, exposed as the
167
- * instance method `vls.isSingleVersion()` in JS.
168
- */
169
- isSingleVersion(): boolean;
170
166
  /**
171
167
  * Parse a `vls` as a [`Vls`] string, exposed as the static `Vls.parse(vls)` in JS.
172
168
  *
@@ -188,7 +184,6 @@ export interface InitOutput {
188
184
  readonly init: () => void;
189
185
  readonly __wbg_vls_free: (a: number, b: number) => void;
190
186
  readonly vls_contains: (a: number, b: number, c: number) => number;
191
- readonly vls_isSingleVersion: (a: number) => number;
192
187
  readonly vls_parse: (a: number, b: number) => [number, number, number];
193
188
  readonly __wbg_constraint_free: (a: number, b: number) => void;
194
189
  readonly constraint_comparator: (a: number) => number;
@@ -75,7 +75,7 @@ export class Constraint {
75
75
  }
76
76
  /**
77
77
  * Construct a new [`Constraint`] from a [`Comparator`] and a version string, validating
78
- * the version string against the VLS grammar. Exposed as `new Constraint(comparator, version)`
78
+ * the version string against the vls grammar. Exposed as `new Constraint(comparator, version)`
79
79
  * in JS.
80
80
  *
81
81
  * # Errors
@@ -112,11 +112,12 @@ if (Symbol.dispose) Constraint.prototype[Symbol.dispose] = Constraint.prototype.
112
112
  * * No constraint's version matches exactly: containment cannot be resolved, as the VERS
113
113
  * type is unknown / unspecified → [`Containment::Undetermined`].
114
114
  *
115
- * The one exception is a [`Vls`] that pins a single version (see [`Vls::is_single_version`]):
116
- * since it has exactly one [`Comparator::Equal`] constraint, containment reduces to a plain
117
- * string comparison and is always decidable, regardless of VERS type. In that case,
118
- * *any* queried version resolves to either [`Containment::Contained`] or
119
- * [`Containment::NotContained`], never [`Containment::Undetermined`].
115
+ * The one exception is a [`Vls`] that uses only exact-match comparators (i.e.
116
+ * [`Comparator::Equal`] and/or [`Comparator::NotEqual`]).
117
+ * Here, containment is reduced to a plain string comparison and is always decidable,
118
+ * regardless of VERS type. In that case, *any* queried version resolves to either [`Containment::Contained`] or
119
+ * [`Containment::NotContained`] depending on the exact-match comparator if there is a constraint with
120
+ * the queried version, and always to [`Containment::NotContained`] if there is no constraint with that version.
120
121
  * @enum {0 | 1 | 2}
121
122
  */
122
123
  export const Containment = Object.freeze({
@@ -203,15 +204,6 @@ export class Vls {
203
204
  const ret = wasm.vls_contains(this.__wbg_ptr, ptr0, len0);
204
205
  return ret;
205
206
  }
206
- /**
207
- * Return `true` if this specifier pins exactly one version, exposed as the
208
- * instance method `vls.isSingleVersion()` in JS.
209
- * @returns {boolean}
210
- */
211
- isSingleVersion() {
212
- const ret = wasm.vls_isSingleVersion(this.__wbg_ptr);
213
- return ret !== 0;
214
- }
215
207
  /**
216
208
  * Parse a `vls` as a [`Vls`] string, exposed as the static `Vls.parse(vls)` in JS.
217
209
  *
Binary file