@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 +10 -10
- package/package.json +2 -2
- package/vers_like_specifier.d.ts +9 -14
- package/vers_like_specifier.js +7 -15
- package/vers_like_specifier_bg.wasm +0 -0
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.
|
|
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(),
|
|
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(),
|
|
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
|
|
50
|
-
// containment then reduces to a plain string comparison.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
assert_eq!(
|
|
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 (
|
|
5
|
-
"version": "0.
|
|
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",
|
package/vers_like_specifier.d.ts
CHANGED
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
export type VersionString = string;
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* Errors specific to a single constraint within a
|
|
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
|
|
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
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* *any* queried version resolves to either [`Containment::Contained`] or
|
|
100
|
-
* [`Containment::NotContained`]
|
|
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;
|
package/vers_like_specifier.js
CHANGED
|
@@ -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
|
|
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
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
* *any* queried version resolves to either [`Containment::Contained`] or
|
|
119
|
-
* [`Containment::NotContained`]
|
|
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
|