@csaf-rs/vers-like-specifier 0.0.0-stage → 0.1.2

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,69 @@
1
- # Temporary Holding Version
1
+ # vers-like-specifier
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![crates.io](https://img.shields.io/crates/v/vers-like-specifier.svg)](https://crates.io/crates/vers-like-specifier)
4
+ [![npm](https://img.shields.io/npm/v/%40csaf-rs%2Fvers-like-specifier.svg)](https://www.npmjs.com/package/@csaf-rs/vers-like-specifier)
5
+
6
+ A Rust library for parsing and validating **Vers-like Specifiers** (vls) as defined in [CSAF 2.0](https://docs.oasis-open.org/csaf/csaf/v2.0/os/csaf-v2.0-os.html#31232-branches-type---name-under-product-version-range) and [CSAF 2.1](https://docs.oasis-open.org/csaf/csaf/v2.1/csaf-v2.1.html#branches-type---name-under-product-version-range).
7
+
8
+ vers-like-specifier is the `<constraints>` portion of a [vers](https://github.com/package-url/vers-spec) URL **without** the `vers:<type>/` prefix.
9
+
10
+ It represents a `|`-separated list of constraints each consisting of an implicit or explicit comparator and a version string.
11
+
12
+ **Due to the undefined / unknown schema, it is nearly impossible for tools to reliably determine whether a given version is in the range or not. vls is a fallback option and SHOULD NOT be used unless really necessary.**
13
+
14
+ ## Minimum Supported Rust Version (MSRV)
15
+
16
+ 1.88.0
17
+
18
+ ## Installation
19
+
20
+ Add `vers-like-specifier` to your `Cargo.toml`. The package is published on https://crates.io/crates/vers-like-specifier:
21
+
22
+ ```toml
23
+ [dependencies]
24
+ vers-like-specifier = "0.1"
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ```rust
30
+ use vers_like_specifier::{Vls, Comparator};
31
+
32
+ let vls: Vls = ">=1.0.0|<2.0.0".parse().unwrap();
33
+ assert_eq!(vls.constraints().len(), 2);
34
+ assert_eq!(vls.to_string(), ">=1.0.0|<2.0.0");
35
+
36
+
37
+ let constraints = vls.constraints();
38
+ assert_eq!(constraints[0].comparator(), &Comparator::GreaterThanOrEqual);
39
+ assert_eq!(constraints[0].version().to_string(), "1.0.0");
40
+ assert_eq!(constraints[1].comparator(), &Comparator::LessThan);
41
+ assert_eq!(constraints[1].version().to_string(), "2.0.0");
42
+ ```
43
+
44
+ ### JavaScript / WASM Usage
45
+
46
+ ```js
47
+ import init, { Vls, Constraint, Comparator } from "@csaf-rs/vers-like-specifier";
48
+
49
+ await init();
50
+
51
+ const vls = Vls.parse(">=1.0.0|<2.0.0");
52
+ console.log(vls.isSingleVersion()); // false
53
+
54
+ const single = Vls.parse("=1.0.0");
55
+ console.log(single.isSingleVersion()); // true
56
+
57
+ const constraint = new Constraint(Comparator.GreaterThanOrEqual, "1.0.0");
58
+ console.log(constraint.version); // "1.0.0"
59
+
60
+ try {
61
+ Vls.parse("*");
62
+ } catch (e) {
63
+ console.error(e); // Error: '*' (vers syntax for matching all versions) is not allowed as a vls string
64
+ }
65
+ ```
66
+
67
+ ## License
68
+
69
+ Licensed under the [Apache License, Version 2.0](LICENSE).
package/package.json CHANGED
@@ -1,6 +1,28 @@
1
1
  {
2
2
  "name": "@csaf-rs/vers-like-specifier",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "type": "module",
4
+ "description": "vls (vers-like specifier) parser",
5
+ "version": "0.1.2",
6
+ "license": "Apache-2.0",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/csaf-rs/vers-like-specifier"
10
+ },
11
+ "files": [
12
+ "vers_like_specifier_bg.wasm",
13
+ "vers_like_specifier.js",
14
+ "vers_like_specifier.d.ts"
15
+ ],
16
+ "main": "vers_like_specifier.js",
17
+ "types": "vers_like_specifier.d.ts",
18
+ "sideEffects": [
19
+ "./snippets/*"
20
+ ],
21
+ "keywords": [
22
+ "vls",
23
+ "vers-like",
24
+ "purl",
25
+ "vers",
26
+ "parser"
27
+ ]
28
+ }
@@ -0,0 +1,197 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * A validated version string.
5
+ *
6
+ * A `VersionString` is guaranteed to be non-empty and to contain only characters
7
+ * allowed by the version-string grammar. See [`Vls`](crate::Vls) for more details on the grammar.
8
+ */
9
+ export type VersionString = string;
10
+
11
+ /**
12
+ * Errors specific to a single constraint within a VLS string.
13
+ */
14
+ export type ConstraintError = "EmptyConstraint" | "EmptyConstraintVersion" | { InvalidConstraintVersionCharacters: string[] };
15
+
16
+ /**
17
+ * Errors that can occur when parsing a vls string.
18
+ */
19
+ export type VlsError = "EmptyInput" | "ForbiddenAnyUsed" | { InvalidCharacters: string[] } | "ContainsVersPrefix" | "ContainsVersType" | { InvalidConstraints: ConstraintError[] } | { DuplicateConstraintVersions: string[] } | { Serialization: string };
20
+
21
+
22
+ /**
23
+ * Comparator for constraints.
24
+ *
25
+ * This enum represents the different types of comparators that can be used
26
+ * in constraints. Each comparator defines how a version is compared
27
+ * to the constraint version.
28
+ */
29
+ export enum Comparator {
30
+ /**
31
+ * Equal (implicit) - The version must be exactly equal to the constraint version.
32
+ */
33
+ Equal = 0,
34
+ /**
35
+ * Not equal (!=) - The version must not be equal to the constraint version.
36
+ */
37
+ NotEqual = 1,
38
+ /**
39
+ * Less than (<) - The version must be less than the constraint version.
40
+ */
41
+ LessThan = 2,
42
+ /**
43
+ * Less than or equal (<=) - The version must be less than or equal to the constraint version.
44
+ */
45
+ LessThanOrEqual = 3,
46
+ /**
47
+ * Greater than (>) - The version must be greater than the constraint version.
48
+ */
49
+ GreaterThan = 4,
50
+ /**
51
+ * Greater than or equal (>=) - The version must be greater than or equal to the constraint version.
52
+ */
53
+ GreaterThanOrEqual = 5,
54
+ }
55
+
56
+ /**
57
+ * A single constraint pairing a [`Comparator`] with a validated [`VersionString`].
58
+ */
59
+ export class Constraint {
60
+ free(): void;
61
+ [Symbol.dispose](): void;
62
+ /**
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)`
65
+ * in JS.
66
+ *
67
+ * # Errors
68
+ * Throws a JS `Error` if `version` is empty or contains characters outside the grammar.
69
+ */
70
+ constructor(comparator: Comparator, version: string);
71
+ /**
72
+ * Returns the comparator of this constraint, exposed as `constraint.comparator` in JS.
73
+ */
74
+ readonly comparator: Comparator;
75
+ /**
76
+ * Returns the version string of this constraint, exposed as `constraint.version` in JS.
77
+ */
78
+ readonly version: string;
79
+ }
80
+
81
+ /**
82
+ * A **Vers-like Specifier** (VLS).
83
+ *
84
+ * VLS is the `<constraints>` part of a [vers](https://github.com/package-url/vers-spec)
85
+ * URL *without* the `vers:<type>/` prefix.
86
+ *
87
+ * It is an ordered, `|`-separated list of [`Constraint`] values.
88
+ *
89
+ * Due to the unspecified format of the versions, only exact matching is possible and range containment checks are not supported.
90
+ *
91
+ * Be aware that when parsing of a string into [`Vls`], the parser returns the first [`VlsError`] encountered in the parsing process.
92
+ * This will obfuscate other errors that might appear further into the parsing process.
93
+ *
94
+ * # Syntax
95
+ *
96
+ * Derived from the [vers specification](https://www.packageurl.org/docs/vers/how-to-parse) and
97
+ * its comments in
98
+ * [CSAF 2.0](https://docs.oasis-open.org/csaf/csaf/v2.0/os/csaf-v2.0-os.html#31232-branches-type---name-under-product-version-range)
99
+ * and
100
+ * [CSAF 2.1](https://docs.oasis-open.org/csaf/csaf/v2.1/csaf-v2.1.html#branches-type---name-under-product-version-range).
101
+ *
102
+ * There currently is no "official" grammar for vers-like specifier / the `<constraints>` part of
103
+ * vers. This is a best-effort attempt used for this library.
104
+ *
105
+ * **Note:** This grammar may need to be updated once vers has been ratified through ECMA / following changes
106
+ * to / clarifications of CSAF 2.0 or CSAF 2.1.
107
+ *
108
+ * ```text
109
+ * vls = constraint *( "|" constraint )
110
+ * constraint = comparator version-string / version-string
111
+ * comparator = "!=" / "<=" / ">=" / "<" / ">"
112
+ * version-string = 1*( ALPHA / DIGIT / "-" / "." / "_" / "+" / "~" )
113
+ * ```
114
+ *
115
+ * For validation, this leads to two sets of characters allowed in the context of the grammar.
116
+ *
117
+ * For `constraints`: `ALPHA / DIGIT / "-" / "." / "_" / "+" / "~" / "=" / "!" / "<" / ">" / "|"`
118
+ *
119
+ * For `version-string`: `ALPHA / DIGIT / "-" / "." / "_" / "+" / "~"`
120
+ *
121
+ * # Examples
122
+ *
123
+ * ```
124
+ * use vers_like_specifier::Vls;
125
+ *
126
+ * let vls: Vls = "<=2".parse().unwrap();
127
+ * assert_eq!(vls.constraints().len(), 1);
128
+ *
129
+ * let vls: Vls = ">10.9a|!=10.9c|!=10.9f|<=10.9k".parse().unwrap();
130
+ * assert_eq!(vls.constraints().len(), 4);
131
+ * assert_eq!(vls.to_string(), ">10.9a|!=10.9c|!=10.9f|<=10.9k");
132
+ * ```
133
+ */
134
+ export class Vls {
135
+ private constructor();
136
+ free(): void;
137
+ [Symbol.dispose](): void;
138
+ /**
139
+ * Return `true` if this specifier pins exactly one version, exposed as the
140
+ * instance method `vls.isSingleVersion()` in JS.
141
+ */
142
+ isSingleVersion(): boolean;
143
+ /**
144
+ * Parse a `vls` as a [`Vls`] string, exposed as the static `Vls.parse(vls)` in JS.
145
+ *
146
+ * # Errors
147
+ * Throws a JS `Error` if `vls` is not a valid vers-like specifier.
148
+ */
149
+ static parse(vls: string): Vls;
150
+ }
151
+
152
+ /**
153
+ * Initialize panic hook for better error messages in the browser console
154
+ */
155
+ export function init(): void;
156
+
157
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
158
+
159
+ export interface InitOutput {
160
+ readonly memory: WebAssembly.Memory;
161
+ readonly __wbg_constraint_free: (a: number, b: number) => void;
162
+ readonly __wbg_vls_free: (a: number, b: number) => void;
163
+ readonly constraint_comparator: (a: number) => number;
164
+ readonly constraint_version: (a: number) => [number, number];
165
+ readonly constraint_wasm_new: (a: number, b: number, c: number) => [number, number, number];
166
+ readonly vls_isSingleVersion: (a: number) => number;
167
+ readonly vls_parse: (a: number, b: number) => [number, number, number];
168
+ readonly init: () => void;
169
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
170
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
171
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
172
+ readonly __wbindgen_externrefs: WebAssembly.Table;
173
+ readonly __externref_table_dealloc: (a: number) => void;
174
+ readonly __wbindgen_start: () => void;
175
+ }
176
+
177
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
178
+
179
+ /**
180
+ * Instantiates the given `module`, which can either be bytes or
181
+ * a precompiled `WebAssembly.Module`.
182
+ *
183
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
184
+ *
185
+ * @returns {InitOutput}
186
+ */
187
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
188
+
189
+ /**
190
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
191
+ * for everything else, calls `WebAssembly.instantiate` directly.
192
+ *
193
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
194
+ *
195
+ * @returns {Promise<InitOutput>}
196
+ */
197
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,445 @@
1
+ /* @ts-self-types="./vers_like_specifier.d.ts" */
2
+
3
+ /**
4
+ * Comparator for constraints.
5
+ *
6
+ * This enum represents the different types of comparators that can be used
7
+ * in constraints. Each comparator defines how a version is compared
8
+ * to the constraint version.
9
+ * @enum {0 | 1 | 2 | 3 | 4 | 5}
10
+ */
11
+ export const Comparator = Object.freeze({
12
+ /**
13
+ * Equal (implicit) - The version must be exactly equal to the constraint version.
14
+ */
15
+ Equal: 0, "0": "Equal",
16
+ /**
17
+ * Not equal (!=) - The version must not be equal to the constraint version.
18
+ */
19
+ NotEqual: 1, "1": "NotEqual",
20
+ /**
21
+ * Less than (<) - The version must be less than the constraint version.
22
+ */
23
+ LessThan: 2, "2": "LessThan",
24
+ /**
25
+ * Less than or equal (<=) - The version must be less than or equal to the constraint version.
26
+ */
27
+ LessThanOrEqual: 3, "3": "LessThanOrEqual",
28
+ /**
29
+ * Greater than (>) - The version must be greater than the constraint version.
30
+ */
31
+ GreaterThan: 4, "4": "GreaterThan",
32
+ /**
33
+ * Greater than or equal (>=) - The version must be greater than or equal to the constraint version.
34
+ */
35
+ GreaterThanOrEqual: 5, "5": "GreaterThanOrEqual",
36
+ });
37
+
38
+ /**
39
+ * A single constraint pairing a [`Comparator`] with a validated [`VersionString`].
40
+ */
41
+ export class Constraint {
42
+ __destroy_into_raw() {
43
+ const ptr = this.__wbg_ptr;
44
+ this.__wbg_ptr = 0;
45
+ ConstraintFinalization.unregister(this);
46
+ return ptr;
47
+ }
48
+ free() {
49
+ const ptr = this.__destroy_into_raw();
50
+ wasm.__wbg_constraint_free(ptr, 0);
51
+ }
52
+ /**
53
+ * Returns the comparator of this constraint, exposed as `constraint.comparator` in JS.
54
+ * @returns {Comparator}
55
+ */
56
+ get comparator() {
57
+ const ret = wasm.constraint_comparator(this.__wbg_ptr);
58
+ return ret;
59
+ }
60
+ /**
61
+ * Returns the version string of this constraint, exposed as `constraint.version` in JS.
62
+ * @returns {string}
63
+ */
64
+ get version() {
65
+ let deferred1_0;
66
+ let deferred1_1;
67
+ try {
68
+ const ret = wasm.constraint_version(this.__wbg_ptr);
69
+ deferred1_0 = ret[0];
70
+ deferred1_1 = ret[1];
71
+ return getStringFromWasm0(ret[0], ret[1]);
72
+ } finally {
73
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
74
+ }
75
+ }
76
+ /**
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)`
79
+ * in JS.
80
+ *
81
+ * # Errors
82
+ * Throws a JS `Error` if `version` is empty or contains characters outside the grammar.
83
+ * @param {Comparator} comparator
84
+ * @param {string} version
85
+ */
86
+ constructor(comparator, version) {
87
+ const ptr0 = passStringToWasm0(version, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
88
+ const len0 = WASM_VECTOR_LEN;
89
+ const ret = wasm.constraint_wasm_new(comparator, ptr0, len0);
90
+ if (ret[2]) {
91
+ throw takeFromExternrefTable0(ret[1]);
92
+ }
93
+ this.__wbg_ptr = ret[0] >>> 0;
94
+ ConstraintFinalization.register(this, this.__wbg_ptr, this);
95
+ return this;
96
+ }
97
+ }
98
+ if (Symbol.dispose) Constraint.prototype[Symbol.dispose] = Constraint.prototype.free;
99
+
100
+ /**
101
+ * A **Vers-like Specifier** (VLS).
102
+ *
103
+ * VLS is the `<constraints>` part of a [vers](https://github.com/package-url/vers-spec)
104
+ * URL *without* the `vers:<type>/` prefix.
105
+ *
106
+ * It is an ordered, `|`-separated list of [`Constraint`] values.
107
+ *
108
+ * Due to the unspecified format of the versions, only exact matching is possible and range containment checks are not supported.
109
+ *
110
+ * Be aware that when parsing of a string into [`Vls`], the parser returns the first [`VlsError`] encountered in the parsing process.
111
+ * This will obfuscate other errors that might appear further into the parsing process.
112
+ *
113
+ * # Syntax
114
+ *
115
+ * Derived from the [vers specification](https://www.packageurl.org/docs/vers/how-to-parse) and
116
+ * its comments in
117
+ * [CSAF 2.0](https://docs.oasis-open.org/csaf/csaf/v2.0/os/csaf-v2.0-os.html#31232-branches-type---name-under-product-version-range)
118
+ * and
119
+ * [CSAF 2.1](https://docs.oasis-open.org/csaf/csaf/v2.1/csaf-v2.1.html#branches-type---name-under-product-version-range).
120
+ *
121
+ * There currently is no "official" grammar for vers-like specifier / the `<constraints>` part of
122
+ * vers. This is a best-effort attempt used for this library.
123
+ *
124
+ * **Note:** This grammar may need to be updated once vers has been ratified through ECMA / following changes
125
+ * to / clarifications of CSAF 2.0 or CSAF 2.1.
126
+ *
127
+ * ```text
128
+ * vls = constraint *( "|" constraint )
129
+ * constraint = comparator version-string / version-string
130
+ * comparator = "!=" / "<=" / ">=" / "<" / ">"
131
+ * version-string = 1*( ALPHA / DIGIT / "-" / "." / "_" / "+" / "~" )
132
+ * ```
133
+ *
134
+ * For validation, this leads to two sets of characters allowed in the context of the grammar.
135
+ *
136
+ * For `constraints`: `ALPHA / DIGIT / "-" / "." / "_" / "+" / "~" / "=" / "!" / "<" / ">" / "|"`
137
+ *
138
+ * For `version-string`: `ALPHA / DIGIT / "-" / "." / "_" / "+" / "~"`
139
+ *
140
+ * # Examples
141
+ *
142
+ * ```
143
+ * use vers_like_specifier::Vls;
144
+ *
145
+ * let vls: Vls = "<=2".parse().unwrap();
146
+ * assert_eq!(vls.constraints().len(), 1);
147
+ *
148
+ * let vls: Vls = ">10.9a|!=10.9c|!=10.9f|<=10.9k".parse().unwrap();
149
+ * assert_eq!(vls.constraints().len(), 4);
150
+ * assert_eq!(vls.to_string(), ">10.9a|!=10.9c|!=10.9f|<=10.9k");
151
+ * ```
152
+ */
153
+ export class Vls {
154
+ static __wrap(ptr) {
155
+ ptr = ptr >>> 0;
156
+ const obj = Object.create(Vls.prototype);
157
+ obj.__wbg_ptr = ptr;
158
+ VlsFinalization.register(obj, obj.__wbg_ptr, obj);
159
+ return obj;
160
+ }
161
+ __destroy_into_raw() {
162
+ const ptr = this.__wbg_ptr;
163
+ this.__wbg_ptr = 0;
164
+ VlsFinalization.unregister(this);
165
+ return ptr;
166
+ }
167
+ free() {
168
+ const ptr = this.__destroy_into_raw();
169
+ wasm.__wbg_vls_free(ptr, 0);
170
+ }
171
+ /**
172
+ * Return `true` if this specifier pins exactly one version, exposed as the
173
+ * instance method `vls.isSingleVersion()` in JS.
174
+ * @returns {boolean}
175
+ */
176
+ isSingleVersion() {
177
+ const ret = wasm.vls_isSingleVersion(this.__wbg_ptr);
178
+ return ret !== 0;
179
+ }
180
+ /**
181
+ * Parse a `vls` as a [`Vls`] string, exposed as the static `Vls.parse(vls)` in JS.
182
+ *
183
+ * # Errors
184
+ * Throws a JS `Error` if `vls` is not a valid vers-like specifier.
185
+ * @param {string} vls
186
+ * @returns {Vls}
187
+ */
188
+ static parse(vls) {
189
+ const ptr0 = passStringToWasm0(vls, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
190
+ const len0 = WASM_VECTOR_LEN;
191
+ const ret = wasm.vls_parse(ptr0, len0);
192
+ if (ret[2]) {
193
+ throw takeFromExternrefTable0(ret[1]);
194
+ }
195
+ return Vls.__wrap(ret[0]);
196
+ }
197
+ }
198
+ if (Symbol.dispose) Vls.prototype[Symbol.dispose] = Vls.prototype.free;
199
+
200
+ /**
201
+ * Initialize panic hook for better error messages in the browser console
202
+ */
203
+ export function init() {
204
+ wasm.init();
205
+ }
206
+ function __wbg_get_imports() {
207
+ const import0 = {
208
+ __proto__: null,
209
+ __wbg___wbindgen_throw_6b64449b9b9ed33c: function(arg0, arg1) {
210
+ throw new Error(getStringFromWasm0(arg0, arg1));
211
+ },
212
+ __wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
213
+ let deferred0_0;
214
+ let deferred0_1;
215
+ try {
216
+ deferred0_0 = arg0;
217
+ deferred0_1 = arg1;
218
+ console.error(getStringFromWasm0(arg0, arg1));
219
+ } finally {
220
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
221
+ }
222
+ },
223
+ __wbg_new_227d7c05414eb861: function() {
224
+ const ret = new Error();
225
+ return ret;
226
+ },
227
+ __wbg_new_5e360d2ff7b9e1c3: function(arg0, arg1) {
228
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
229
+ return ret;
230
+ },
231
+ __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
232
+ const ret = arg1.stack;
233
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
234
+ const len1 = WASM_VECTOR_LEN;
235
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
236
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
237
+ },
238
+ __wbindgen_init_externref_table: function() {
239
+ const table = wasm.__wbindgen_externrefs;
240
+ const offset = table.grow(4);
241
+ table.set(0, undefined);
242
+ table.set(offset + 0, undefined);
243
+ table.set(offset + 1, null);
244
+ table.set(offset + 2, true);
245
+ table.set(offset + 3, false);
246
+ },
247
+ };
248
+ return {
249
+ __proto__: null,
250
+ "./vers_like_specifier_bg.js": import0,
251
+ };
252
+ }
253
+
254
+ const ConstraintFinalization = (typeof FinalizationRegistry === 'undefined')
255
+ ? { register: () => {}, unregister: () => {} }
256
+ : new FinalizationRegistry(ptr => wasm.__wbg_constraint_free(ptr >>> 0, 1));
257
+ const VlsFinalization = (typeof FinalizationRegistry === 'undefined')
258
+ ? { register: () => {}, unregister: () => {} }
259
+ : new FinalizationRegistry(ptr => wasm.__wbg_vls_free(ptr >>> 0, 1));
260
+
261
+ let cachedDataViewMemory0 = null;
262
+ function getDataViewMemory0() {
263
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
264
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
265
+ }
266
+ return cachedDataViewMemory0;
267
+ }
268
+
269
+ function getStringFromWasm0(ptr, len) {
270
+ ptr = ptr >>> 0;
271
+ return decodeText(ptr, len);
272
+ }
273
+
274
+ let cachedUint8ArrayMemory0 = null;
275
+ function getUint8ArrayMemory0() {
276
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
277
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
278
+ }
279
+ return cachedUint8ArrayMemory0;
280
+ }
281
+
282
+ function passStringToWasm0(arg, malloc, realloc) {
283
+ if (realloc === undefined) {
284
+ const buf = cachedTextEncoder.encode(arg);
285
+ const ptr = malloc(buf.length, 1) >>> 0;
286
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
287
+ WASM_VECTOR_LEN = buf.length;
288
+ return ptr;
289
+ }
290
+
291
+ let len = arg.length;
292
+ let ptr = malloc(len, 1) >>> 0;
293
+
294
+ const mem = getUint8ArrayMemory0();
295
+
296
+ let offset = 0;
297
+
298
+ for (; offset < len; offset++) {
299
+ const code = arg.charCodeAt(offset);
300
+ if (code > 0x7F) break;
301
+ mem[ptr + offset] = code;
302
+ }
303
+ if (offset !== len) {
304
+ if (offset !== 0) {
305
+ arg = arg.slice(offset);
306
+ }
307
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
308
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
309
+ const ret = cachedTextEncoder.encodeInto(arg, view);
310
+
311
+ offset += ret.written;
312
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
313
+ }
314
+
315
+ WASM_VECTOR_LEN = offset;
316
+ return ptr;
317
+ }
318
+
319
+ function takeFromExternrefTable0(idx) {
320
+ const value = wasm.__wbindgen_externrefs.get(idx);
321
+ wasm.__externref_table_dealloc(idx);
322
+ return value;
323
+ }
324
+
325
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
326
+ cachedTextDecoder.decode();
327
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
328
+ let numBytesDecoded = 0;
329
+ function decodeText(ptr, len) {
330
+ numBytesDecoded += len;
331
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
332
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
333
+ cachedTextDecoder.decode();
334
+ numBytesDecoded = len;
335
+ }
336
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
337
+ }
338
+
339
+ const cachedTextEncoder = new TextEncoder();
340
+
341
+ if (!('encodeInto' in cachedTextEncoder)) {
342
+ cachedTextEncoder.encodeInto = function (arg, view) {
343
+ const buf = cachedTextEncoder.encode(arg);
344
+ view.set(buf);
345
+ return {
346
+ read: arg.length,
347
+ written: buf.length
348
+ };
349
+ };
350
+ }
351
+
352
+ let WASM_VECTOR_LEN = 0;
353
+
354
+ let wasmModule, wasm;
355
+ function __wbg_finalize_init(instance, module) {
356
+ wasm = instance.exports;
357
+ wasmModule = module;
358
+ cachedDataViewMemory0 = null;
359
+ cachedUint8ArrayMemory0 = null;
360
+ wasm.__wbindgen_start();
361
+ return wasm;
362
+ }
363
+
364
+ async function __wbg_load(module, imports) {
365
+ if (typeof Response === 'function' && module instanceof Response) {
366
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
367
+ try {
368
+ return await WebAssembly.instantiateStreaming(module, imports);
369
+ } catch (e) {
370
+ const validResponse = module.ok && expectedResponseType(module.type);
371
+
372
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
373
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
374
+
375
+ } else { throw e; }
376
+ }
377
+ }
378
+
379
+ const bytes = await module.arrayBuffer();
380
+ return await WebAssembly.instantiate(bytes, imports);
381
+ } else {
382
+ const instance = await WebAssembly.instantiate(module, imports);
383
+
384
+ if (instance instanceof WebAssembly.Instance) {
385
+ return { instance, module };
386
+ } else {
387
+ return instance;
388
+ }
389
+ }
390
+
391
+ function expectedResponseType(type) {
392
+ switch (type) {
393
+ case 'basic': case 'cors': case 'default': return true;
394
+ }
395
+ return false;
396
+ }
397
+ }
398
+
399
+ function initSync(module) {
400
+ if (wasm !== undefined) return wasm;
401
+
402
+
403
+ if (module !== undefined) {
404
+ if (Object.getPrototypeOf(module) === Object.prototype) {
405
+ ({module} = module)
406
+ } else {
407
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
408
+ }
409
+ }
410
+
411
+ const imports = __wbg_get_imports();
412
+ if (!(module instanceof WebAssembly.Module)) {
413
+ module = new WebAssembly.Module(module);
414
+ }
415
+ const instance = new WebAssembly.Instance(module, imports);
416
+ return __wbg_finalize_init(instance, module);
417
+ }
418
+
419
+ async function __wbg_init(module_or_path) {
420
+ if (wasm !== undefined) return wasm;
421
+
422
+
423
+ if (module_or_path !== undefined) {
424
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
425
+ ({module_or_path} = module_or_path)
426
+ } else {
427
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
428
+ }
429
+ }
430
+
431
+ if (module_or_path === undefined) {
432
+ module_or_path = new URL('vers_like_specifier_bg.wasm', import.meta.url);
433
+ }
434
+ const imports = __wbg_get_imports();
435
+
436
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
437
+ module_or_path = fetch(module_or_path);
438
+ }
439
+
440
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
441
+
442
+ return __wbg_finalize_init(instance, module);
443
+ }
444
+
445
+ export { initSync, __wbg_init as default };
Binary file