@floless/app 0.161.0 → 0.162.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.
@@ -0,0 +1,43 @@
1
+ // AWARE parses components as u64; past 2^53 JavaScript would silently round, so such a component is refused here.
2
+ const numeric = (s) => /^(0|[1-9]\d*)$/.test(s) && Number.isSafeInteger(Number(s));
3
+ const identifiers = (s, noLeadingZero) => s.length > 0 && s.split('.').every((id) =>
4
+ /^[0-9A-Za-z-]+$/.test(id) && !(noLeadingZero && /^0\d+$/.test(id)));
5
+
6
+ /** AWARE's `VersionPin::parse` (cli/src/validate.rs): exact (with prerelease), `M.m.x`, `M.x`, `M.m`. Null when unreadable. */
7
+ export function parsePin(spec) {
8
+ const [rest, build, ...more] = spec.split('+');
9
+ if (more.length || (build !== undefined && !identifiers(build, false))) return null;
10
+ const dash = rest.indexOf('-');
11
+ const core = dash < 0 ? rest : rest.slice(0, dash);
12
+ const pre = dash < 0 ? null : rest.slice(dash + 1);
13
+ if (pre !== null && !identifiers(pre, true)) return null;
14
+ const parts = core.split('.');
15
+ const wild = (s) => s === 'x' || s === 'X' || s === '*';
16
+ if (parts.slice(0, -1).some(wild)) return null;
17
+ if (parts.length === 3 && !wild(parts[2])) {
18
+ return parts.every(numeric) ? { kind: 'exact', v: parts.map(Number), pre } : null;
19
+ }
20
+ if (pre !== null || !numeric(parts[0]) || !(parts.length === 2 || parts.length === 3) || !numeric(parts[1]) && !wild(parts[1])) return null;
21
+ if (parts.length === 3) return { kind: 'minor', v: [Number(parts[0]), Number(parts[1])] };
22
+ return wild(parts[1]) ? { kind: 'major', v: [Number(parts[0])] } : { kind: 'at-least', v: [Number(parts[0]), Number(parts[1])] };
23
+ }
24
+
25
+ /** Whether an installed manifest version satisfies a pin, exactly as AWARE's `is_satisfied_by` decides it. */
26
+ export function satisfies(spec, version) {
27
+ const pin = parsePin(spec);
28
+ if (!pin) throw new Error(`unreadable pin ${JSON.stringify(spec)}`);
29
+ const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?(?:\+([0-9A-Za-z.-]+))?$/.exec(version);
30
+ if (!match || !match.slice(1, 4).every(numeric) || (match[4] !== undefined && !identifiers(match[4], true))
31
+ || (match[5] !== undefined && !identifiers(match[5], false))) {
32
+ throw new Error(`unreadable installed version ${JSON.stringify(version)}`);
33
+ }
34
+ const [maj, min, pat] = match.slice(1, 4).map(Number);
35
+ const pre = match[4] ?? null;
36
+ switch (pin.kind) {
37
+ case 'exact': return maj === pin.v[0] && min === pin.v[1] && pat === pin.v[2] && pre === pin.pre;
38
+ case 'minor': return maj === pin.v[0] && min === pin.v[1];
39
+ case 'major': return maj === pin.v[0];
40
+ default: return maj === pin.v[0] && min >= pin.v[1];
41
+ }
42
+ }
43
+