@guandata/decidex 0.1.1 → 0.2.1
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 +173 -12
- package/package.json +2 -1
- package/src/cli.js +586 -67
- package/src/compatibility.js +51 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export const ADAPTED_SERVER_VERSION = "0.0.5";
|
|
2
|
+
export const ADAPTED_SERVER_COMMIT = "3e0ad67d9aa087b92cf6e60f9d501657ac4a625f";
|
|
3
|
+
|
|
4
|
+
// Version boundaries must be backed by release tags, not the current main version.
|
|
5
|
+
// /api/auth/context first appears between tags 0.0.4 and 0.0.5 (a860e97ad).
|
|
6
|
+
export const COMMAND_COMPATIBILITY = {
|
|
7
|
+
"auth whoami": { minVersion: "0.0.5", protocol: "identity-context" },
|
|
8
|
+
"auth status": { protocol: "identity-context", legacy: { before: "0.0.5", protocol: "agent-list" } },
|
|
9
|
+
"auth login": { protocol: "identity-context", legacy: { before: "0.0.5", protocol: "agent-list" } },
|
|
10
|
+
"context show": { protocol: "identity-context", legacy: { before: "0.0.5", protocol: "local-context" } },
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
function parseVersion(value) {
|
|
14
|
+
const match = typeof value === "string" && value.match(/^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/);
|
|
15
|
+
if (!match) throw new Error(`无法比较服务端版本:${JSON.stringify(value)};需要 SemVer 版本号`);
|
|
16
|
+
const release = match.slice(1, 4).map(Number);
|
|
17
|
+
const prerelease = match[4]?.split(".") ?? [];
|
|
18
|
+
if (release.some((n) => !Number.isSafeInteger(n)) || prerelease.some((part) => /^\d+$/.test(part) && /^0\d/.test(part))) {
|
|
19
|
+
throw new Error(`不合法的 SemVer 版本号:${value}`);
|
|
20
|
+
}
|
|
21
|
+
return { release, prerelease };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function compareVersions(left, right) {
|
|
25
|
+
const a = parseVersion(left), b = parseVersion(right);
|
|
26
|
+
for (let i = 0; i < 3; i++) {
|
|
27
|
+
if (a.release[i] !== b.release[i]) return a.release[i] > b.release[i] ? 1 : -1;
|
|
28
|
+
}
|
|
29
|
+
if (!a.prerelease.length || !b.prerelease.length) return a.prerelease.length === b.prerelease.length ? 0 : a.prerelease.length ? -1 : 1;
|
|
30
|
+
for (let i = 0; i < Math.max(a.prerelease.length, b.prerelease.length); i++) {
|
|
31
|
+
const x = a.prerelease[i], y = b.prerelease[i];
|
|
32
|
+
if (x === undefined || y === undefined) return x === undefined ? -1 : 1;
|
|
33
|
+
if (x === y) continue;
|
|
34
|
+
const nx = /^\d+$/.test(x), ny = /^\d+$/.test(y);
|
|
35
|
+
if (nx && ny) return BigInt(x) > BigInt(y) ? 1 : -1;
|
|
36
|
+
if (nx !== ny) return nx ? -1 : 1;
|
|
37
|
+
return x > y ? 1 : -1;
|
|
38
|
+
}
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function resolveCommandCompatibility(command, version, rules = COMMAND_COMPATIBILITY) {
|
|
43
|
+
const rule = rules[command];
|
|
44
|
+
if (!rule) return { command, supported: null, protocol: null, reason: "no_version_rule" };
|
|
45
|
+
parseVersion(version);
|
|
46
|
+
if (rule.minVersion && compareVersions(version, rule.minVersion) < 0) {
|
|
47
|
+
return { command, supported: false, minVersion: rule.minVersion, protocol: null, reason: "server_too_old" };
|
|
48
|
+
}
|
|
49
|
+
const legacy = Boolean(rule.legacy && compareVersions(version, rule.legacy.before) < 0);
|
|
50
|
+
return { command, supported: true, minVersion: rule.minVersion ?? null, protocol: legacy ? rule.legacy.protocol : rule.protocol ?? "current", legacy };
|
|
51
|
+
}
|