@protobase/schema 0.46.14 → 0.47.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.
@@ -1,7 +1,7 @@
1
1
  //#region src/plugin-version.d.ts
2
2
  /**
3
3
  * Whether `version` is in `range`: comparators such as `>=0.12.0 <1.0.0`, separated by spaces, all of which must hold.
4
- * Undefined when the range is not one of those, or the version is no x.y.z version.
4
+ * Undefined when the range is not one of those, or the version is no semver version.
5
5
  */
6
6
  export declare const inRange: (version: string, range: string) => boolean | undefined;
7
7
  /** What a plugin's plugin.json says it is built for: a plugin API, and the Protobase versions it runs on. */
@@ -1,38 +1,22 @@
1
+ import semver from "semver";
1
2
  //#region src/plugin-version.ts
2
- const versionPattern = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
3
- const parseVersion = (text) => {
4
- const match = versionPattern.exec(text);
5
- return match ? [
6
- Number(match[1]),
7
- Number(match[2]),
8
- Number(match[3])
9
- ] : void 0;
10
- };
11
- const compare = (a, b) => a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
12
- const comparatorPattern = /^(>=|<=|>|<|=)?(.+)$/;
13
- const holds = {
14
- ">=": (order) => order >= 0,
15
- "<=": (order) => order <= 0,
16
- ">": (order) => order > 0,
17
- "<": (order) => order < 0,
18
- "=": (order) => order === 0
3
+ const isComparator = (text) => {
4
+ try {
5
+ new semver.Comparator(text);
6
+ return true;
7
+ } catch (error) {
8
+ if (error instanceof TypeError) return false;
9
+ throw error;
10
+ }
19
11
  };
20
12
  /**
21
13
  * Whether `version` is in `range`: comparators such as `>=0.12.0 <1.0.0`, separated by spaces, all of which must hold.
22
- * Undefined when the range is not one of those, or the version is no x.y.z version.
14
+ * Undefined when the range is not one of those, or the version is no semver version.
23
15
  */
24
16
  const inRange = (version, range) => {
25
- const own = parseVersion(version);
26
17
  const comparators = range.trim().split(/\s+/);
27
- if (!own || range.trim() === "") return void 0;
28
- let result = true;
29
- for (const comparator of comparators) {
30
- const [, operator = "=", text = ""] = comparatorPattern.exec(comparator) ?? [];
31
- const bound = parseVersion(text);
32
- if (!bound) return void 0;
33
- result &&= holds[operator](compare(own, bound));
34
- }
35
- return result;
18
+ if (semver.valid(version) === null || range.trim() === "" || !comparators.every(isComparator)) return void 0;
19
+ return semver.satisfies(version, range);
36
20
  };
37
21
  /**
38
22
  * Why an app does not load a plugin built for `requirement`, or undefined when it does: the plugin API must be the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/schema",
3
- "version": "0.46.14",
3
+ "version": "0.47.0",
4
4
  "description": "Resource, field, view and access definitions for Protobase configs.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -31,6 +31,10 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "aip-parsers": "^1.0.0",
34
+ "semver": "^7.8.5",
34
35
  "zod": "^4.6.5"
36
+ },
37
+ "devDependencies": {
38
+ "@types/semver": "^7.8.0"
35
39
  }
36
40
  }