@vltpkg/query 0.0.0-8 → 1.0.0-rc.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 +38 -249
- package/dist/esm/attribute.d.ts +1 -1
- package/dist/esm/attribute.d.ts.map +1 -1
- package/dist/esm/attribute.js +5 -12
- package/dist/esm/attribute.js.map +1 -1
- package/dist/esm/combinator.d.ts.map +1 -1
- package/dist/esm/combinator.js +1 -1
- package/dist/esm/combinator.js.map +1 -1
- package/dist/esm/id.d.ts.map +1 -1
- package/dist/esm/id.js +23 -7
- package/dist/esm/id.js.map +1 -1
- package/dist/esm/index.d.ts +29 -7
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +247 -21
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/parser.d.ts +15 -0
- package/dist/esm/parser.d.ts.map +1 -0
- package/dist/esm/parser.js +93 -0
- package/dist/esm/parser.js.map +1 -0
- package/dist/esm/pseudo/attr.d.ts +2 -1
- package/dist/esm/pseudo/attr.d.ts.map +1 -1
- package/dist/esm/pseudo/attr.js +10 -2
- package/dist/esm/pseudo/attr.js.map +1 -1
- package/dist/esm/pseudo/built.d.ts +8 -0
- package/dist/esm/pseudo/built.d.ts.map +1 -0
- package/dist/esm/pseudo/built.js +16 -0
- package/dist/esm/pseudo/built.js.map +1 -0
- package/dist/esm/pseudo/confused.d.ts +4 -2
- package/dist/esm/pseudo/confused.d.ts.map +1 -1
- package/dist/esm/pseudo/confused.js +15 -2
- package/dist/esm/pseudo/confused.js.map +1 -1
- package/dist/esm/pseudo/cve.d.ts +2 -1
- package/dist/esm/pseudo/cve.d.ts.map +1 -1
- package/dist/esm/pseudo/cve.js +2 -2
- package/dist/esm/pseudo/cve.js.map +1 -1
- package/dist/esm/pseudo/cwe.d.ts +2 -1
- package/dist/esm/pseudo/cwe.d.ts.map +1 -1
- package/dist/esm/pseudo/cwe.js +2 -2
- package/dist/esm/pseudo/cwe.js.map +1 -1
- package/dist/esm/pseudo/dev.d.ts +6 -0
- package/dist/esm/pseudo/dev.d.ts.map +1 -0
- package/dist/esm/pseudo/dev.js +15 -0
- package/dist/esm/pseudo/dev.js.map +1 -0
- package/dist/esm/pseudo/empty.d.ts +7 -0
- package/dist/esm/pseudo/empty.d.ts.map +1 -0
- package/dist/esm/pseudo/empty.js +14 -0
- package/dist/esm/pseudo/empty.js.map +1 -0
- package/dist/esm/pseudo/helpers.d.ts +13 -1
- package/dist/esm/pseudo/helpers.d.ts.map +1 -1
- package/dist/esm/pseudo/helpers.js +27 -0
- package/dist/esm/pseudo/helpers.js.map +1 -1
- package/dist/esm/pseudo/host.d.ts +20 -0
- package/dist/esm/pseudo/host.d.ts.map +1 -0
- package/dist/esm/pseudo/host.js +80 -0
- package/dist/esm/pseudo/host.js.map +1 -0
- package/dist/esm/pseudo/license.d.ts +2 -1
- package/dist/esm/pseudo/license.d.ts.map +1 -1
- package/dist/esm/pseudo/license.js +19 -2
- package/dist/esm/pseudo/license.js.map +1 -1
- package/dist/esm/pseudo/link.d.ts +9 -0
- package/dist/esm/pseudo/link.d.ts.map +1 -0
- package/dist/esm/pseudo/link.js +25 -0
- package/dist/esm/pseudo/link.js.map +1 -0
- package/dist/esm/pseudo/malware.d.ts +13 -1
- package/dist/esm/pseudo/malware.d.ts.map +1 -1
- package/dist/esm/pseudo/malware.js +140 -10
- package/dist/esm/pseudo/malware.js.map +1 -1
- package/dist/esm/pseudo/missing.d.ts +8 -0
- package/dist/esm/pseudo/missing.d.ts.map +1 -0
- package/dist/esm/pseudo/missing.js +15 -0
- package/dist/esm/pseudo/missing.js.map +1 -0
- package/dist/esm/pseudo/optional.d.ts +6 -0
- package/dist/esm/pseudo/optional.d.ts.map +1 -0
- package/dist/esm/pseudo/optional.js +15 -0
- package/dist/esm/pseudo/optional.js.map +1 -0
- package/dist/esm/pseudo/outdated.d.ts +4 -4
- package/dist/esm/pseudo/outdated.d.ts.map +1 -1
- package/dist/esm/pseudo/outdated.js +44 -33
- package/dist/esm/pseudo/outdated.js.map +1 -1
- package/dist/esm/pseudo/overridden.d.ts +8 -0
- package/dist/esm/pseudo/overridden.d.ts.map +1 -0
- package/dist/esm/pseudo/overridden.js +17 -0
- package/dist/esm/pseudo/overridden.js.map +1 -0
- package/dist/esm/pseudo/path.d.ts +19 -0
- package/dist/esm/pseudo/path.d.ts.map +1 -0
- package/dist/esm/pseudo/path.js +113 -0
- package/dist/esm/pseudo/path.js.map +1 -0
- package/dist/esm/pseudo/peer.d.ts +6 -0
- package/dist/esm/pseudo/peer.d.ts.map +1 -0
- package/dist/esm/pseudo/peer.js +15 -0
- package/dist/esm/pseudo/peer.js.map +1 -0
- package/dist/esm/pseudo/prerelease.d.ts +18 -0
- package/dist/esm/pseudo/prerelease.d.ts.map +1 -0
- package/dist/esm/pseudo/prerelease.js +41 -0
- package/dist/esm/pseudo/prerelease.js.map +1 -0
- package/dist/esm/pseudo/private.d.ts +7 -0
- package/dist/esm/pseudo/private.d.ts.map +1 -0
- package/dist/esm/pseudo/private.js +16 -0
- package/dist/esm/pseudo/private.js.map +1 -0
- package/dist/esm/pseudo/prod.d.ts +6 -0
- package/dist/esm/pseudo/prod.d.ts.map +1 -0
- package/dist/esm/pseudo/prod.js +15 -0
- package/dist/esm/pseudo/prod.js.map +1 -0
- package/dist/esm/pseudo/published.d.ts +40 -0
- package/dist/esm/pseudo/published.d.ts.map +1 -0
- package/dist/esm/pseudo/published.js +180 -0
- package/dist/esm/pseudo/published.js.map +1 -0
- package/dist/esm/pseudo/root.d.ts +7 -0
- package/dist/esm/pseudo/root.d.ts.map +1 -0
- package/dist/esm/pseudo/root.js +18 -0
- package/dist/esm/pseudo/root.js.map +1 -0
- package/dist/esm/pseudo/scanned.d.ts +4 -2
- package/dist/esm/pseudo/scanned.d.ts.map +1 -1
- package/dist/esm/pseudo/scanned.js +10 -5
- package/dist/esm/pseudo/scanned.js.map +1 -1
- package/dist/esm/pseudo/score.d.ts +16 -0
- package/dist/esm/pseudo/score.d.ts.map +1 -0
- package/dist/esm/pseudo/score.js +133 -0
- package/dist/esm/pseudo/score.js.map +1 -0
- package/dist/esm/pseudo/scripts.d.ts +7 -4
- package/dist/esm/pseudo/scripts.d.ts.map +1 -1
- package/dist/esm/pseudo/scripts.js +41 -3
- package/dist/esm/pseudo/scripts.js.map +1 -1
- package/dist/esm/pseudo/semver.d.ts +2 -1
- package/dist/esm/pseudo/semver.d.ts.map +1 -1
- package/dist/esm/pseudo/semver.js +11 -24
- package/dist/esm/pseudo/semver.js.map +1 -1
- package/dist/esm/pseudo/severity.d.ts +4 -1
- package/dist/esm/pseudo/severity.d.ts.map +1 -1
- package/dist/esm/pseudo/severity.js +111 -8
- package/dist/esm/pseudo/severity.js.map +1 -1
- package/dist/esm/pseudo/spec.d.ts +17 -0
- package/dist/esm/pseudo/spec.d.ts.map +1 -0
- package/dist/esm/pseudo/spec.js +102 -0
- package/dist/esm/pseudo/spec.js.map +1 -0
- package/dist/esm/pseudo/squat.d.ts +4 -1
- package/dist/esm/pseudo/squat.d.ts.map +1 -1
- package/dist/esm/pseudo/squat.js +127 -9
- package/dist/esm/pseudo/squat.js.map +1 -1
- package/dist/esm/pseudo/type.d.ts +8 -0
- package/dist/esm/pseudo/type.d.ts.map +1 -0
- package/dist/esm/pseudo/type.js +22 -0
- package/dist/esm/pseudo/type.js.map +1 -0
- package/dist/esm/pseudo/workspace.d.ts +6 -0
- package/dist/esm/pseudo/workspace.d.ts.map +1 -0
- package/dist/esm/pseudo/workspace.js +20 -0
- package/dist/esm/pseudo/workspace.js.map +1 -0
- package/dist/esm/pseudo.d.ts.map +1 -1
- package/dist/esm/pseudo.js +81 -105
- package/dist/esm/pseudo.js.map +1 -1
- package/dist/esm/types.d.ts +97 -27
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +1 -106
- package/dist/esm/types.js.map +1 -1
- package/package.json +20 -16
- package/dist/esm/class.d.ts +0 -6
- package/dist/esm/class.d.ts.map +0 -1
- package/dist/esm/class.js +0 -131
- package/dist/esm/class.js.map +0 -1
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { removeDanglingEdges, removeNode } from "./helpers.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* :scanned pseudo selector.
|
|
4
|
+
*
|
|
5
|
+
* Remove all nodes that do not have available metadata
|
|
6
|
+
* in the security archive.
|
|
5
7
|
*/
|
|
6
8
|
export const scanned = async (state) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
for (const node of state.partial.nodes) {
|
|
10
|
+
if (!state.securityArchive?.has(node.id)) {
|
|
11
|
+
removeNode(state, node);
|
|
12
|
+
}
|
|
9
13
|
}
|
|
14
|
+
removeDanglingEdges(state);
|
|
10
15
|
return state;
|
|
11
16
|
};
|
|
12
17
|
//# sourceMappingURL=scanned.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanned.js","sourceRoot":"","sources":["../../../src/pseudo/scanned.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"scanned.js","sourceRoot":"","sources":["../../../src/pseudo/scanned.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAG9D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,EAAE,KAAkB,EAAE,EAAE;IAClD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACvC,IAAI,CAAC,KAAK,CAAC,eAAe,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;YACzC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;QACzB,CAAC;IACH,CAAC;IAED,mBAAmB,CAAC,KAAK,CAAC,CAAA;IAE1B,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { removeDanglingEdges, removeNode } from './helpers.ts'\nimport type { ParserState } from '../types.ts'\n\n/**\n * :scanned pseudo selector.\n *\n * Remove all nodes that do not have available metadata\n * in the security archive.\n */\nexport const scanned = async (state: ParserState) => {\n for (const node of state.partial.nodes) {\n if (!state.securityArchive?.has(node.id)) {\n removeNode(state, node)\n }\n }\n\n removeDanglingEdges(state)\n\n return state\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { PackageScore } from '@vltpkg/security-archive';
|
|
2
|
+
import type { ParserState } from '../types.ts';
|
|
3
|
+
import type { PostcssNode } from '@vltpkg/dss-parser';
|
|
4
|
+
export type ScoreKinds = keyof PackageScore;
|
|
5
|
+
export type ScoreComparator = '>' | '<' | '>=' | '<=' | '=' | undefined;
|
|
6
|
+
export declare const isScoreKind: (value?: string) => value is ScoreKinds;
|
|
7
|
+
export declare const asScoreKind: (value?: string) => ScoreKinds;
|
|
8
|
+
export declare const parseInternals: (nodes: PostcssNode[]) => {
|
|
9
|
+
comparator: ScoreComparator;
|
|
10
|
+
rate: number;
|
|
11
|
+
kind: ScoreKinds;
|
|
12
|
+
};
|
|
13
|
+
export declare const score: (state: ParserState) => Promise<ParserState & {
|
|
14
|
+
securityArchive: NonNullable<ParserState["securityArchive"]>;
|
|
15
|
+
}>;
|
|
16
|
+
//# sourceMappingURL=score.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"score.d.ts","sourceRoot":"","sources":["../../../src/pseudo/score.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAErD,MAAM,MAAM,UAAU,GAAG,MAAM,YAAY,CAAA;AAE3C,MAAM,MAAM,eAAe,GACvB,GAAG,GACH,GAAG,GACH,IAAI,GACJ,IAAI,GACJ,GAAG,GACH,SAAS,CAAA;AAYb,eAAO,MAAM,WAAW,WAAY,MAAM,KAAG,KAAK,IAAI,UACtB,CAAA;AAEhC,eAAO,MAAM,WAAW,WAAY,MAAM,KAAG,UAQ5C,CAAA;AAED,eAAO,MAAM,cAAc,UAClB,WAAW,EAAE,KACnB;IACD,UAAU,EAAE,eAAe,CAAA;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,UAAU,CAAA;CAsEjB,CAAA;AAED,eAAO,MAAM,KAAK,UAAiB,WAAW;;EA6D7C,CAAA"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { error } from '@vltpkg/error-cause';
|
|
2
|
+
import { asError } from '@vltpkg/types';
|
|
3
|
+
import { asPostcssNodeWithChildren, asStringNode, asTagNode, isStringNode, isTagNode, } from '@vltpkg/dss-parser';
|
|
4
|
+
import { assertSecurityArchive, removeDanglingEdges, removeNode, removeQuotes, } from "./helpers.js";
|
|
5
|
+
const kinds = new Set([
|
|
6
|
+
'overall',
|
|
7
|
+
'license',
|
|
8
|
+
'maintenance',
|
|
9
|
+
'quality',
|
|
10
|
+
'supplyChain',
|
|
11
|
+
'vulnerability',
|
|
12
|
+
undefined,
|
|
13
|
+
]);
|
|
14
|
+
export const isScoreKind = (value) => kinds.has(value);
|
|
15
|
+
export const asScoreKind = (value) => {
|
|
16
|
+
if (!isScoreKind(value)) {
|
|
17
|
+
throw error('Expected a valid score kind', {
|
|
18
|
+
found: value,
|
|
19
|
+
validOptions: Array.from(kinds),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
};
|
|
24
|
+
export const parseInternals = (nodes) => {
|
|
25
|
+
let rateStr = '';
|
|
26
|
+
let comparator = '=';
|
|
27
|
+
let kind = 'overall';
|
|
28
|
+
// Parse the first parameter (rate with optional comparator)
|
|
29
|
+
if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
|
|
30
|
+
rateStr = removeQuotes(asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])
|
|
31
|
+
.value);
|
|
32
|
+
}
|
|
33
|
+
else if (isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
|
|
34
|
+
const tagNode = asTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0]);
|
|
35
|
+
rateStr = tagNode.value;
|
|
36
|
+
}
|
|
37
|
+
// Extract comparator if present
|
|
38
|
+
if (rateStr.startsWith('>=')) {
|
|
39
|
+
comparator = '>=';
|
|
40
|
+
rateStr = rateStr.substring(2);
|
|
41
|
+
}
|
|
42
|
+
else if (rateStr.startsWith('<=')) {
|
|
43
|
+
comparator = '<=';
|
|
44
|
+
rateStr = rateStr.substring(2);
|
|
45
|
+
}
|
|
46
|
+
else if (rateStr.startsWith('>')) {
|
|
47
|
+
comparator = '>';
|
|
48
|
+
rateStr = rateStr.substring(1);
|
|
49
|
+
}
|
|
50
|
+
else if (rateStr.startsWith('<')) {
|
|
51
|
+
comparator = '<';
|
|
52
|
+
rateStr = rateStr.substring(1);
|
|
53
|
+
}
|
|
54
|
+
// Parse rate as number
|
|
55
|
+
let rate = parseFloat(rateStr);
|
|
56
|
+
// Normalize to 0-1 range if needed
|
|
57
|
+
if (rate > 1) {
|
|
58
|
+
rate = rate / 100;
|
|
59
|
+
}
|
|
60
|
+
// Validate rate is in acceptable range
|
|
61
|
+
if (rate < 0 || rate > 1) {
|
|
62
|
+
throw error('Expected rate to be between 0 and 100', {
|
|
63
|
+
found: rateStr,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
// Parse the second parameter (kind) if present
|
|
67
|
+
if (nodes.length > 1) {
|
|
68
|
+
if (isStringNode(asPostcssNodeWithChildren(nodes[1]).nodes[0])) {
|
|
69
|
+
kind = asScoreKind(removeQuotes(asStringNode(asPostcssNodeWithChildren(nodes[1]).nodes[0])
|
|
70
|
+
.value));
|
|
71
|
+
}
|
|
72
|
+
else if (isTagNode(asPostcssNodeWithChildren(nodes[1]).nodes[0])) {
|
|
73
|
+
kind = asScoreKind(asTagNode(asPostcssNodeWithChildren(nodes[1]).nodes[0]).value);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return { comparator, rate, kind };
|
|
77
|
+
};
|
|
78
|
+
export const score = async (state) => {
|
|
79
|
+
assertSecurityArchive(state, 'score');
|
|
80
|
+
let internals;
|
|
81
|
+
try {
|
|
82
|
+
internals = parseInternals(asPostcssNodeWithChildren(state.current).nodes);
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
if (asError(err).message === 'Expected a query node') {
|
|
86
|
+
// No parameters provided - pseudo state form: match ANY score (scanned packages)
|
|
87
|
+
for (const node of state.partial.nodes) {
|
|
88
|
+
const report = state.securityArchive.get(node.id);
|
|
89
|
+
if (!report) {
|
|
90
|
+
removeNode(state, node);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
removeDanglingEdges(state);
|
|
94
|
+
return state;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
throw error('Failed to parse :score selector', { cause: err });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const { comparator, rate, kind } = internals;
|
|
101
|
+
for (const node of state.partial.nodes) {
|
|
102
|
+
const report = state.securityArchive.get(node.id);
|
|
103
|
+
if (!report) {
|
|
104
|
+
removeNode(state, node);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const scoreValue = report.score[kind];
|
|
108
|
+
let exclude = false;
|
|
109
|
+
switch (comparator) {
|
|
110
|
+
case '>':
|
|
111
|
+
exclude = scoreValue <= rate;
|
|
112
|
+
break;
|
|
113
|
+
case '<':
|
|
114
|
+
exclude = scoreValue >= rate;
|
|
115
|
+
break;
|
|
116
|
+
case '>=':
|
|
117
|
+
exclude = scoreValue < rate;
|
|
118
|
+
break;
|
|
119
|
+
case '<=':
|
|
120
|
+
exclude = scoreValue > rate;
|
|
121
|
+
break;
|
|
122
|
+
default: // '='
|
|
123
|
+
exclude = scoreValue !== rate;
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
if (exclude) {
|
|
127
|
+
removeNode(state, node);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
removeDanglingEdges(state);
|
|
131
|
+
return state;
|
|
132
|
+
};
|
|
133
|
+
//# sourceMappingURL=score.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"score.js","sourceRoot":"","sources":["../../../src/pseudo/score.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EACL,yBAAyB,EACzB,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,SAAS,GACV,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,UAAU,EACV,YAAY,GACb,MAAM,cAAc,CAAA;AAerB,MAAM,KAAK,GAAG,IAAI,GAAG,CAAyB;IAC5C,SAAS;IACT,SAAS;IACT,aAAa;IACb,SAAS;IACT,aAAa;IACb,eAAe;IACf,SAAS;CACV,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAc,EAAuB,EAAE,CACjE,KAAK,CAAC,GAAG,CAAC,KAAmB,CAAC,CAAA;AAEhC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAc,EAAc,EAAE;IACxD,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,KAAK,CAAC,6BAA6B,EAAE;YACzC,KAAK,EAAE,KAAK;YACZ,YAAY,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;SAChC,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,KAAoB,EAKpB,EAAE;IACF,IAAI,OAAO,GAAG,EA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,UAAU,EAAE,CAAC;YACnB,KAAK,GAAG;gBACN,OAAO,GAAG,UAAU,IAAI,IAAI,CAAA;gBAC5B,MAAK;YACP,KAAK,GAAG;gBACN,OAAO,GAAG,UAAU,IAAI,IAAI,CAAA;gBAC5B,MAAK;YACP,KAAK,IAAI;gBACP,OAAO,GAAG,UAAU,GAAG,IAAI,CAAA;gBAC3B,MAAK;YACP,KAAK,IAAI;gBACP,OAAO,GAAG,UAAU,GAAG,IAAI,CAAA;gBAC3B,MAAK;YACP,SAAS,MAAM;gBACb,OAAO,GAAG,UAAU,KAAK,IAAI,CAAA;gBAC7B,MAAK;QACT,CAAC;QAED,IAAI,OAAO,EAAE,CAAC;YACZ,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;QACzB,CAAC;IACH,CAAC;IAED,mBAAmB,CAAC,KAAK,CAAC,CAAA;IAE1B,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport { asError } from '@vltpkg/types'\nimport {\n asPostcssNodeWithChildren,\n asStringNode,\n asTagNode,\n isStringNode,\n isTagNode,\n} from '@vltpkg/dss-parser'\nimport {\n assertSecurityArchive,\n removeDanglingEdges,\n removeNode,\n removeQuotes,\n} from './helpers.ts'\nimport type { PackageScore } from '@vltpkg/security-archive'\nimport type { ParserState } from '../types.ts'\nimport type { PostcssNode } from '@vltpkg/dss-parser'\n\nexport type ScoreKinds = keyof PackageScore\n\nexport type ScoreComparator =\n | '>'\n | '<'\n | '>='\n | '<='\n | '='\n | undefined\n\nconst kinds = new Set<ScoreKinds | undefined>([\n 'overall',\n 'license',\n 'maintenance',\n 'quality',\n 'supplyChain',\n 'vulnerability',\n undefined,\n])\n\nexport const isScoreKind = (value?: string): value is ScoreKinds =>\n kinds.has(value as ScoreKinds)\n\nexport const asScoreKind = (value?: string): ScoreKinds => {\n if (!isScoreKind(value)) {\n throw error('Expected a valid score kind', {\n found: value,\n validOptions: Array.from(kinds),\n })\n }\n return value\n}\n\nexport const parseInternals = (\n nodes: PostcssNode[],\n): {\n comparator: ScoreComparator\n rate: number\n kind: ScoreKinds\n} => {\n let rateStr = ''\n let comparator: ScoreComparator = '='\n let kind: ScoreKinds = 'overall'\n\n // Parse the first parameter (rate with optional comparator)\n if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {\n rateStr = removeQuotes(\n asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n .value,\n )\n } else if (\n isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n ) {\n const tagNode = asTagNode(\n asPostcssNodeWithChildren(nodes[0]).nodes[0],\n )\n rateStr = tagNode.value\n }\n\n // Extract comparator if present\n if (rateStr.startsWith('>=')) {\n comparator = '>='\n rateStr = rateStr.substring(2)\n } else if (rateStr.startsWith('<=')) {\n comparator = '<='\n rateStr = rateStr.substring(2)\n } else if (rateStr.startsWith('>')) {\n comparator = '>'\n rateStr = rateStr.substring(1)\n } else if (rateStr.startsWith('<')) {\n comparator = '<'\n rateStr = rateStr.substring(1)\n }\n\n // Parse rate as number\n let rate = parseFloat(rateStr)\n\n // Normalize to 0-1 range if needed\n if (rate > 1) {\n rate = rate / 100\n }\n\n // Validate rate is in acceptable range\n if (rate < 0 || rate > 1) {\n throw error('Expected rate to be between 0 and 100', {\n found: rateStr,\n })\n }\n\n // Parse the second parameter (kind) if present\n if (nodes.length > 1) {\n if (isStringNode(asPostcssNodeWithChildren(nodes[1]).nodes[0])) {\n kind = asScoreKind(\n removeQuotes(\n asStringNode(asPostcssNodeWithChildren(nodes[1]).nodes[0])\n .value,\n ),\n )\n } else if (\n isTagNode(asPostcssNodeWithChildren(nodes[1]).nodes[0])\n ) {\n kind = asScoreKind(\n asTagNode(asPostcssNodeWithChildren(nodes[1]).nodes[0]).value,\n )\n }\n }\n\n return { comparator, rate, kind }\n}\n\nexport const score = async (state: ParserState) => {\n assertSecurityArchive(state, 'score')\n\n let internals\n try {\n internals = parseInternals(\n asPostcssNodeWithChildren(state.current).nodes,\n )\n } catch (err) {\n if (asError(err).message === 'Expected a query node') {\n // No parameters provided - pseudo state form: match ANY score (scanned packages)\n for (const node of state.partial.nodes) {\n const report = state.securityArchive.get(node.id)\n if (!report) {\n removeNode(state, node)\n }\n }\n removeDanglingEdges(state)\n return state\n } else {\n throw error('Failed to parse :score selector', { cause: err })\n }\n }\n\n const { comparator, rate, kind } = internals\n for (const node of state.partial.nodes) {\n const report = state.securityArchive.get(node.id)\n if (!report) {\n removeNode(state, node)\n continue\n }\n\n const scoreValue = report.score[kind]\n\n let exclude = false\n switch (comparator) {\n case '>':\n exclude = scoreValue <= rate\n break\n case '<':\n exclude = scoreValue >= rate\n break\n case '>=':\n exclude = scoreValue < rate\n break\n case '<=':\n exclude = scoreValue > rate\n break\n default: // '='\n exclude = scoreValue !== rate\n break\n }\n\n if (exclude) {\n removeNode(state, node)\n }\n }\n\n removeDanglingEdges(state)\n\n return state\n}\n"]}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import type { ParserState } from '../types.ts';
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
+
* :scripts Pseudo-Selector filters nodes based on whether they need to be built.
|
|
4
|
+
*
|
|
5
|
+
* A node needs to be built if it has:
|
|
6
|
+
* - Install lifecycle scripts (install, preinstall, postinstall)
|
|
7
|
+
* - Prepare scripts on importers or git dependencies (prepare, preprepare, postprepare)
|
|
3
8
|
*/
|
|
4
|
-
export declare const scripts: (state:
|
|
5
|
-
securityArchive: NonNullable<import("../types.ts").ParserState["securityArchive"]>;
|
|
6
|
-
}>;
|
|
9
|
+
export declare const scripts: (state: ParserState) => Promise<ParserState>;
|
|
7
10
|
//# sourceMappingURL=scripts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scripts.d.ts","sourceRoot":"","sources":["../../../src/pseudo/scripts.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scripts.d.ts","sourceRoot":"","sources":["../../../src/pseudo/scripts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAmC9C;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,UAAiB,WAAW,yBAU/C,CAAA"}
|
|
@@ -1,6 +1,44 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { removeNode, removeDanglingEdges } from "./helpers.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Checks if a node needs to be built based on the conditions from the reify build process:
|
|
4
|
+
* 1. Has install lifecycle scripts (install, preinstall, postinstall)
|
|
5
|
+
* 2. Is an importer or git dependency with prepare scripts (prepare, preprepare, postprepare)
|
|
4
6
|
*/
|
|
5
|
-
|
|
7
|
+
const nodeNeedsBuild = (node) => {
|
|
8
|
+
const { manifest } = node;
|
|
9
|
+
/* c8 ignore next */
|
|
10
|
+
if (!manifest)
|
|
11
|
+
return false;
|
|
12
|
+
const { scripts = {} } = manifest;
|
|
13
|
+
// Check for install lifecycle scripts
|
|
14
|
+
const runInstall = !!(scripts.install ||
|
|
15
|
+
scripts.preinstall ||
|
|
16
|
+
scripts.postinstall);
|
|
17
|
+
if (runInstall)
|
|
18
|
+
return true;
|
|
19
|
+
// Check for prepare scripts on importers or git dependencies
|
|
20
|
+
const prepable = node.id.startsWith('git') || node.importer;
|
|
21
|
+
const runPrepare = !!((scripts.prepare || scripts.preprepare || scripts.postprepare)
|
|
22
|
+
/* c8 ignore next 2 */
|
|
23
|
+
) && prepable;
|
|
24
|
+
if (runPrepare)
|
|
25
|
+
return true;
|
|
26
|
+
return false;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* :scripts Pseudo-Selector filters nodes based on whether they need to be built.
|
|
30
|
+
*
|
|
31
|
+
* A node needs to be built if it has:
|
|
32
|
+
* - Install lifecycle scripts (install, preinstall, postinstall)
|
|
33
|
+
* - Prepare scripts on importers or git dependencies (prepare, preprepare, postprepare)
|
|
34
|
+
*/
|
|
35
|
+
export const scripts = async (state) => {
|
|
36
|
+
for (const node of state.partial.nodes) {
|
|
37
|
+
if (!nodeNeedsBuild(node)) {
|
|
38
|
+
removeNode(state, node);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
removeDanglingEdges(state);
|
|
42
|
+
return state;
|
|
43
|
+
};
|
|
6
44
|
//# sourceMappingURL=scripts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scripts.js","sourceRoot":"","sources":["../../../src/pseudo/scripts.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scripts.js","sourceRoot":"","sources":["../../../src/pseudo/scripts.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAE9D;;;;GAIG;AACH,MAAM,cAAc,GAAG,CAAC,IAAc,EAAW,EAAE;IACjD,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAA;IACzB,oBAAoB;IACpB,IAAI,CAAC,QAAQ;QAAE,OAAO,KAAK,CAAA;IAE3B,MAAM,EAAE,OAAO,GAAG,EAAE,EAAE,GAAG,QAAQ,CAAA;IAEjC,sCAAsC;IACtC,MAAM,UAAU,GAAG,CAAC,CAAC,CACnB,OAAO,CAAC,OAAO;QACf,OAAO,CAAC,UAAU;QAClB,OAAO,CAAC,WAAW,CACpB,CAAA;IACD,IAAI,UAAU;QAAE,OAAO,IAAI,CAAA;IAE3B,6DAA6D;IAC7D,MAAM,QAAQ,GAAG,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAA;IAC3D,MAAM,UAAU,GACd,CAAC,CAAC,CACA,CAAC,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,WAAW,CAAC;IAC9D,sBAAsB;KACvB,IAAI,QAAQ,CAAA;IACf,IAAI,UAAU;QAAE,OAAO,IAAI,CAAA;IAE3B,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,EAAE,KAAkB,EAAE,EAAE;IAClD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACvC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1B,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;QACzB,CAAC;IACH,CAAC;IAED,mBAAmB,CAAC,KAAK,CAAC,CAAA;IAE1B,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import type { NodeLike } from '@vltpkg/types'\nimport type { ParserState } from '../types.ts'\nimport { removeNode, removeDanglingEdges } from './helpers.ts'\n\n/**\n * Checks if a node needs to be built based on the conditions from the reify build process:\n * 1. Has install lifecycle scripts (install, preinstall, postinstall)\n * 2. Is an importer or git dependency with prepare scripts (prepare, preprepare, postprepare)\n */\nconst nodeNeedsBuild = (node: NodeLike): boolean => {\n const { manifest } = node\n /* c8 ignore next */\n if (!manifest) return false\n\n const { scripts = {} } = manifest\n\n // Check for install lifecycle scripts\n const runInstall = !!(\n scripts.install ||\n scripts.preinstall ||\n scripts.postinstall\n )\n if (runInstall) return true\n\n // Check for prepare scripts on importers or git dependencies\n const prepable = node.id.startsWith('git') || node.importer\n const runPrepare =\n !!(\n (scripts.prepare || scripts.preprepare || scripts.postprepare)\n /* c8 ignore next 2 */\n ) && prepable\n if (runPrepare) return true\n\n return false\n}\n\n/**\n * :scripts Pseudo-Selector filters nodes based on whether they need to be built.\n *\n * A node needs to be built if it has:\n * - Install lifecycle scripts (install, preinstall, postinstall)\n * - Prepare scripts on importers or git dependencies (prepare, preprepare, postprepare)\n */\nexport const scripts = async (state: ParserState) => {\n for (const node of state.partial.nodes) {\n if (!nodeNeedsBuild(node)) {\n removeNode(state, node)\n }\n }\n\n removeDanglingEdges(state)\n\n return state\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Version } from '@vltpkg/semver';
|
|
2
2
|
import type { AttrInternals } from './attr.ts';
|
|
3
|
-
import type { ParserState
|
|
3
|
+
import type { ParserState } from '../types.ts';
|
|
4
|
+
import type { PostcssNode } from '@vltpkg/dss-parser';
|
|
4
5
|
export type SemverInternals = {
|
|
5
6
|
semverValue: string;
|
|
6
7
|
semverFunction: SemverComparatorFn;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semver.d.ts","sourceRoot":"","sources":["../../../src/pseudo/semver.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"semver.d.ts","sourceRoot":"","sources":["../../../src/pseudo/semver.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAI7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAc9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAErD,MAAM,MAAM,eAAe,GAAG;IAC5B,WAAW,EAAE,MAAM,CAAA;IACnB,cAAc,EAAE,kBAAkB,CAAA;IAClC,gBAAgB,EAAE,sBAAsB,CAAA;CACzC,CAAA;AAED,MAAM,MAAM,mBAAmB,GAC3B,WAAW,GACX,IAAI,GACJ,KAAK,GACL,IAAI,GACJ,KAAK,GACL,IAAI,GACJ,KAAK,CAAA;AACT,MAAM,MAAM,kBAAkB,GAAG,CAC/B,OAAO,EAAE,OAAO,GAAG,MAAM,EACzB,KAAK,EAAE,MAAM,KACV,OAAO,CAAA;AACZ,MAAM,MAAM,sBAAsB,GAC9B,IAAI,CAAC,aAAa,EAAE,WAAW,GAAG,YAAY,CAAC,GAC/C,SAAS,CAAA;AAWb,eAAO,MAAM,oBAAoB,SACzB,MAAM,KACX,IAAI,IAAI,mBAAoD,CAAA;AAE/D,eAAO,MAAM,oBAAoB,SACzB,MAAM,KACX,mBAQF,CAAA;AAeD,eAAO,MAAM,cAAc,UAClB,WAAW,EAAE,SACb,OAAO,KACb,eAkGF,CAAA;AAED,eAAO,MAAM,YAAY,UAAiB,WAAW,yBAyDpD,CAAA"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { satisfies, gt, gte, lt, lte, eq, neq, parse, parseRange, } from '@vltpkg/semver';
|
|
2
2
|
import { error } from '@vltpkg/error-cause';
|
|
3
|
+
import { asError } from '@vltpkg/types';
|
|
3
4
|
import { parseInternals as parseAttrInternals } from "./attr.js";
|
|
4
5
|
import { getManifestPropertyValues } from "../attribute.js";
|
|
5
|
-
import { asAttributeNode, asPostcssNodeWithChildren, asPseudoNode, asStringNode, asTagNode, isAttributeNode,
|
|
6
|
+
import { asAttributeNode, asPostcssNodeWithChildren, asPseudoNode, asStringNode, asTagNode, isAttributeNode, isPseudoNode, isStringNode, isTagNode, } from '@vltpkg/dss-parser';
|
|
6
7
|
import { removeNode, removeQuotes } from "./helpers.js";
|
|
7
8
|
const semverFunctionNames = new Set([
|
|
8
9
|
'satisfies',
|
|
@@ -32,34 +33,21 @@ const semverFunctions = new Map([
|
|
|
32
33
|
['eq', eq],
|
|
33
34
|
['neq', neq],
|
|
34
35
|
]);
|
|
35
|
-
// list a few css combinators that should never have
|
|
36
|
-
// spaces around when parsing as a semver range
|
|
37
|
-
const unspacedCombinators = new Set([' ', '+']);
|
|
38
36
|
export const parseInternals = (nodes, loose) => {
|
|
39
37
|
// tries to parse the first param as a string node, otherwise defaults
|
|
40
38
|
// to reading all postcss nodes as just strings, since it just means
|
|
41
39
|
// the value was defined as an unquoted string
|
|
42
|
-
let semverValue;
|
|
40
|
+
let semverValue = '';
|
|
43
41
|
try {
|
|
44
42
|
semverValue = removeQuotes(asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])
|
|
45
43
|
.value);
|
|
46
44
|
}
|
|
47
|
-
catch (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
semverValue += '.';
|
|
54
|
-
}
|
|
55
|
-
else if (isCombinatorNode(node) &&
|
|
56
|
-
!unspacedCombinators.has(node.value)) {
|
|
57
|
-
semverValue += ' ';
|
|
58
|
-
}
|
|
59
|
-
if (node.value) {
|
|
60
|
-
semverValue += node.value;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
if (asError(err).message === 'Mismatching query node' &&
|
|
47
|
+
isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
|
|
48
|
+
// Handle tag node (unquoted values like >=2.0.0)
|
|
49
|
+
const tagNode = asTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0]);
|
|
50
|
+
semverValue = tagNode.value;
|
|
63
51
|
}
|
|
64
52
|
else {
|
|
65
53
|
throw err;
|
|
@@ -76,9 +64,8 @@ export const parseInternals = (nodes, loose) => {
|
|
|
76
64
|
fnName = asSemverFunctionName(removeQuotes(asStringNode(asPostcssNodeWithChildren(nodes[1]).nodes[0])
|
|
77
65
|
.value));
|
|
78
66
|
}
|
|
79
|
-
catch (
|
|
80
|
-
|
|
81
|
-
if (err.message === 'Mismatching query node') {
|
|
67
|
+
catch (err) {
|
|
68
|
+
if (asError(err).message === 'Mismatching query node') {
|
|
82
69
|
fnName = asSemverFunctionName(asTagNode(asPostcssNodeWithChildren(nodes[1]).nodes[0])
|
|
83
70
|
.value);
|
|
84
71
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semver.js","sourceRoot":"","sources":["../../../src/pseudo/semver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,EAAE,EACF,GAAG,EACH,EAAE,EACF,GAAG,EACH,EAAE,EACF,GAAG,EACH,KAAK,EACL,UAAU,GACX,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,KAAK,EAA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AAC;QACvC,IAAI,gBAAgB,EAAE,CAAC;YACrB,MAAM,aAAa,GAAG,yBAAyB,CAC7C,IAAI,EACJ,gBAAgB,CAAC,UAAU,EAC3B,gBAAgB,CAAC,SAAS,CAC3B,CAAA;YAED,iEAAiE;YACjE,oEAAoE;YACpE,iEAAiE;YACjE,MAAM,YAAY,GAAG,aAAa,EAAE,CAAC,CAAC,CAAC,CAAA;YACvC,MAAM,kBAAkB,GAAG,KAAK,CAAC,WAAW,CAAC,CAAA;YAC7C,MAAM,iBAAiB,GACrB,YAAY,IAAI,UAAU,CAAC,YAAY,CAAC,CAAA;YAC1C,IACE,cAAc,KAAK,SAAS;gBAC5B,kBAAkB;gBAClB,iBAAiB,EACjB,CAAC;gBACD,IAAI,CAAC,SAAS,CAAC,kBAAkB,EAAE,iBAAiB,CAAC,EAAE,CAAC;oBACtD,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;gBACzB,CAAC;gBACD,iEAAiE;YACnE,CAAC;iBAAM,IACL,CAAC,YAAY;gBACb,CAAC,cAAc,CAAC,YAAY,EAAE,WAAW,CAAC,EAC1C,CAAC;gBACD,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;YACzB,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,eAAe,GAAG,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAA;YAC9C,IACE,CAAC,eAAe;gBAChB,CAAC,cAAc,CAAC,eAAe,EAAE,WAAW,CAAC,EAC7C,CAAC;gBACD,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;YACzB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import {\n satisfies,\n gt,\n gte,\n lt,\n lte,\n eq,\n neq,\n parse,\n parseRange,\n} from '@vltpkg/semver'\nimport type { Version } from '@vltpkg/semver'\nimport { error } from '@vltpkg/error-cause'\nimport { parseInternals as parseAttrInternals } from './attr.ts'\nimport type { AttrInternals } from './attr.ts'\nimport { getManifestPropertyValues } from '../attribute.ts'\nimport {\n asAttributeNode,\n asPostcssNodeWithChildren,\n asPseudoNode,\n asStringNode,\n asTagNode,\n isAttributeNode,\n isClassNode,\n isCombinatorNode,\n isPseudoNode,\n isStringNode,\n} from '../types.ts'\nimport type { ParserState, PostcssNode } from '../types.ts'\nimport { removeNode, removeQuotes } from './helpers.ts'\n\nexport type SemverInternals = {\n semverValue: string\n semverFunction: SemverComparatorFn\n compareAttribute: SemverCompareAttribute\n}\n\nexport type SemverFunctionNames =\n | 'satisfies'\n | 'gt'\n | 'gte'\n | 'lt'\n | 'lte'\n | 'eq'\n | 'neq'\nexport type SemverComparatorFn = (\n version: Version | string,\n range: string,\n) => boolean\nexport type SemverCompareAttribute =\n | Pick<AttrInternals, 'attribute' | 'properties'>\n | undefined\n\nconst semverFunctionNames = new Set([\n 'satisfies',\n 'gt',\n 'gte',\n 'lt',\n 'lte',\n 'eq',\n 'neq',\n])\nexport const isSemverFunctionName = (\n name: string,\n): name is SemverFunctionNames => semverFunctionNames.has(name)\n\nexport const asSemverFunctionName = (\n name: string,\n): SemverFunctionNames => {\n if (!isSemverFunctionName(name)) {\n throw error('Invalid semver function name', {\n found: name,\n validOptions: Array.from(semverFunctionNames),\n })\n }\n return name\n}\n\nconst semverFunctions = new Map<\n SemverFunctionNames,\n SemverComparatorFn\n>([\n ['satisfies', satisfies],\n ['gt', gt],\n ['gte', gte],\n ['lt', lt],\n ['lte', lte],\n ['eq', eq],\n ['neq', neq],\n])\n\n// list a few css combinators that should never have\n// spaces around when parsing as a semver range\nconst unspacedCombinators = new Set<string>([' ', '+'])\n\nexport const parseInternals = (\n nodes: PostcssNode[],\n loose: boolean,\n): SemverInternals => {\n // tries to parse the first param as a string node, otherwise defaults\n // to reading all postcss nodes as just strings, since it just means\n // the value was defined as an unquoted string\n let semverValue\n try {\n semverValue = removeQuotes(\n asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n .value,\n )\n } catch (e) {\n const err = e as Error\n if (err.message === 'Mismatching query node') {\n semverValue = ''\n for (const node of asPostcssNodeWithChildren(nodes[0]).nodes) {\n if (isClassNode(node)) {\n semverValue += '.'\n } else if (\n isCombinatorNode(node) &&\n !unspacedCombinators.has(node.value)\n ) {\n semverValue += ' '\n }\n\n if (node.value) {\n semverValue += node.value\n }\n }\n } else {\n throw err\n }\n }\n\n // second param is the function name\n let fnName: SemverFunctionNames = 'satisfies'\n try {\n // if there is a second node defined, try to parse it as a string node\n // first and if that fails, then parse it as a tag node which just means\n // it was defined as an unquoted string\n if (nodes[1]) {\n try {\n fnName = asSemverFunctionName(\n removeQuotes(\n asStringNode(asPostcssNodeWithChildren(nodes[1]).nodes[0])\n .value,\n ),\n )\n } catch (e) {\n const err = e as Error\n if (err.message === 'Mismatching query node') {\n fnName = asSemverFunctionName(\n asTagNode(asPostcssNodeWithChildren(nodes[1]).nodes[0])\n .value,\n )\n } else {\n throw err\n }\n }\n }\n } catch (e) {\n // allow invalid semver function names in loose mode, defaults to satisfies\n if (!loose) {\n throw e\n }\n }\n\n const semverFunction = semverFunctions.get(fnName)\n // the following should never happen as long as the semver function names\n // type and Set are correctly mirroring each other values\n /* c8 ignore start */\n if (!semverFunction) {\n throw error('Invalid semver function name', {\n found: fnName,\n validOptions: Array.from(semverFunctions.keys()),\n })\n }\n /* c8 ignore stop */\n\n // optional third param is the compare value\n let compareAttribute: SemverCompareAttribute\n if (nodes[2]) {\n const parentNode = asPostcssNodeWithChildren(nodes[2])\n const currNode = parentNode.nodes[0]\n if (isAttributeNode(currNode)) {\n const { attribute } = asAttributeNode(currNode)\n compareAttribute = {\n attribute,\n properties: [attribute],\n }\n } else if (isPseudoNode(currNode)) {\n compareAttribute = parseAttrInternals(\n asPseudoNode(currNode).nodes,\n )\n } else if (isStringNode(currNode)) {\n const attribute = removeQuotes(asStringNode(currNode).value)\n compareAttribute = {\n attribute,\n properties: [attribute],\n }\n }\n }\n\n return {\n semverValue,\n semverFunction,\n compareAttribute,\n }\n}\n\nexport const semverParser = async (state: ParserState) => {\n let internals\n try {\n internals = parseInternals(\n asPostcssNodeWithChildren(state.current).nodes,\n !!state.loose,\n )\n } catch (err) {\n throw error('Failed to parse :semver selector', {\n cause: err,\n })\n }\n\n const { semverValue, semverFunction, compareAttribute } = internals\n\n for (const node of state.partial.nodes) {\n if (compareAttribute) {\n const compareValues = getManifestPropertyValues(\n node,\n compareAttribute.properties,\n compareAttribute.attribute,\n )\n\n // if the provided semver value is a fixed semver version and the\n // compare attribute is resolving to a range value, then we flip the\n // order of comparison, in case it's a \"satisfies\" function check\n const compareValue = compareValues?.[0]\n const semverValueVersion = parse(semverValue)\n const compareValueRange =\n compareValue && parseRange(compareValue)\n if (\n semverFunction === satisfies &&\n semverValueVersion &&\n compareValueRange\n ) {\n if (!satisfies(semverValueVersion, compareValueRange)) {\n removeNode(state, node)\n }\n // otherwise just compares the read attribute to the semver value\n } else if (\n !compareValue ||\n !semverFunction(compareValue, semverValue)\n ) {\n removeNode(state, node)\n }\n } else {\n const manifestVersion = node.manifest?.version\n if (\n !manifestVersion ||\n !semverFunction(manifestVersion, semverValue)\n ) {\n removeNode(state, node)\n }\n }\n }\n\n return state\n}\n"]}
|
|
1
|
+
{"version":3,"file":"semver.js","sourceRoot":"","sources":["../../../src/pseudo/semver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,EAAE,EACF,GAAG,EACH,EAAE,EACF,GAAG,EACH,EAAE,EACF,GAAG,EACH,KAAK,EACL,UAAU,GACX,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAEhE,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,EACL,eAAe,EACf,yBAAyB,EACzB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AAE,IAAI,CAAC,CAAA;gBACzB,CAAC;gBACD,iEAAiE;YACnE,CAAC;iBAAM,IACL,CAAC,YAAY;gBACb,CAAC,cAAc,CAAC,YAAY,EAAE,WAAW,CAAC,EAC1C,CAAC;gBACD,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;YACzB,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,eAAe,GAAG,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAA;YAC9C,IACE,CAAC,eAAe;gBAChB,CAAC,cAAc,CAAC,eAAe,EAAE,WAAW,CAAC,EAC7C,CAAC;gBACD,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;YACzB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import {\n satisfies,\n gt,\n gte,\n lt,\n lte,\n eq,\n neq,\n parse,\n parseRange,\n} from '@vltpkg/semver'\nimport type { Version } from '@vltpkg/semver'\nimport { error } from '@vltpkg/error-cause'\nimport { asError } from '@vltpkg/types'\nimport { parseInternals as parseAttrInternals } from './attr.ts'\nimport type { AttrInternals } from './attr.ts'\nimport { getManifestPropertyValues } from '../attribute.ts'\nimport {\n asAttributeNode,\n asPostcssNodeWithChildren,\n asPseudoNode,\n asStringNode,\n asTagNode,\n isAttributeNode,\n isPseudoNode,\n isStringNode,\n isTagNode,\n} from '@vltpkg/dss-parser'\nimport { removeNode, removeQuotes } from './helpers.ts'\nimport type { ParserState } from '../types.ts'\nimport type { PostcssNode } from '@vltpkg/dss-parser'\n\nexport type SemverInternals = {\n semverValue: string\n semverFunction: SemverComparatorFn\n compareAttribute: SemverCompareAttribute\n}\n\nexport type SemverFunctionNames =\n | 'satisfies'\n | 'gt'\n | 'gte'\n | 'lt'\n | 'lte'\n | 'eq'\n | 'neq'\nexport type SemverComparatorFn = (\n version: Version | string,\n range: string,\n) => boolean\nexport type SemverCompareAttribute =\n | Pick<AttrInternals, 'attribute' | 'properties'>\n | undefined\n\nconst semverFunctionNames = new Set([\n 'satisfies',\n 'gt',\n 'gte',\n 'lt',\n 'lte',\n 'eq',\n 'neq',\n])\nexport const isSemverFunctionName = (\n name: string,\n): name is SemverFunctionNames => semverFunctionNames.has(name)\n\nexport const asSemverFunctionName = (\n name: string,\n): SemverFunctionNames => {\n if (!isSemverFunctionName(name)) {\n throw error('Invalid semver function name', {\n found: name,\n validOptions: Array.from(semverFunctionNames),\n })\n }\n return name\n}\n\nconst semverFunctions = new Map<\n SemverFunctionNames,\n SemverComparatorFn\n>([\n ['satisfies', satisfies],\n ['gt', gt],\n ['gte', gte],\n ['lt', lt],\n ['lte', lte],\n ['eq', eq],\n ['neq', neq],\n])\n\nexport const parseInternals = (\n nodes: PostcssNode[],\n loose: boolean,\n): SemverInternals => {\n // tries to parse the first param as a string node, otherwise defaults\n // to reading all postcss nodes as just strings, since it just means\n // the value was defined as an unquoted string\n let semverValue = ''\n try {\n semverValue = removeQuotes(\n asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n .value,\n )\n } catch (err) {\n if (\n asError(err).message === 'Mismatching query node' &&\n isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n ) {\n // Handle tag node (unquoted values like >=2.0.0)\n const tagNode = asTagNode(\n asPostcssNodeWithChildren(nodes[0]).nodes[0],\n )\n semverValue = tagNode.value\n } else {\n throw err\n }\n }\n\n // second param is the function name\n let fnName: SemverFunctionNames = 'satisfies'\n try {\n // if there is a second node defined, try to parse it as a string node\n // first and if that fails, then parse it as a tag node which just means\n // it was defined as an unquoted string\n if (nodes[1]) {\n try {\n fnName = asSemverFunctionName(\n removeQuotes(\n asStringNode(asPostcssNodeWithChildren(nodes[1]).nodes[0])\n .value,\n ),\n )\n } catch (err) {\n if (asError(err).message === 'Mismatching query node') {\n fnName = asSemverFunctionName(\n asTagNode(asPostcssNodeWithChildren(nodes[1]).nodes[0])\n .value,\n )\n } else {\n throw err\n }\n }\n }\n } catch (e) {\n // allow invalid semver function names in loose mode, defaults to satisfies\n if (!loose) {\n throw e\n }\n }\n\n const semverFunction = semverFunctions.get(fnName)\n // the following should never happen as long as the semver function names\n // type and Set are correctly mirroring each other values\n /* c8 ignore start */\n if (!semverFunction) {\n throw error('Invalid semver function name', {\n found: fnName,\n validOptions: Array.from(semverFunctions.keys()),\n })\n }\n /* c8 ignore stop */\n\n // optional third param is the compare value\n let compareAttribute: SemverCompareAttribute\n if (nodes[2]) {\n const parentNode = asPostcssNodeWithChildren(nodes[2])\n const currNode = parentNode.nodes[0]\n if (isAttributeNode(currNode)) {\n const { attribute } = asAttributeNode(currNode)\n compareAttribute = {\n attribute,\n properties: [attribute],\n }\n } else if (isPseudoNode(currNode)) {\n compareAttribute = parseAttrInternals(\n asPseudoNode(currNode).nodes,\n )\n } else if (isStringNode(currNode)) {\n const attribute = removeQuotes(asStringNode(currNode).value)\n compareAttribute = {\n attribute,\n properties: [attribute],\n }\n }\n }\n\n return {\n semverValue,\n semverFunction,\n compareAttribute,\n }\n}\n\nexport const semverParser = async (state: ParserState) => {\n let internals\n try {\n internals = parseInternals(\n asPostcssNodeWithChildren(state.current).nodes,\n !!state.loose,\n )\n } catch (err) {\n throw error('Failed to parse :semver selector', {\n cause: err,\n })\n }\n\n const { semverValue, semverFunction, compareAttribute } = internals\n\n for (const node of state.partial.nodes) {\n if (compareAttribute) {\n const compareValues = getManifestPropertyValues(\n node,\n compareAttribute.properties,\n compareAttribute.attribute,\n )\n\n // if the provided semver value is a fixed semver version and the\n // compare attribute is resolving to a range value, then we flip the\n // order of comparison, in case it's a \"satisfies\" function check\n const compareValue = compareValues?.[0]\n const semverValueVersion = parse(semverValue)\n const compareValueRange =\n compareValue && parseRange(compareValue)\n if (\n semverFunction === satisfies &&\n semverValueVersion &&\n compareValueRange\n ) {\n if (!satisfies(semverValueVersion, compareValueRange)) {\n removeNode(state, node)\n }\n // otherwise just compares the read attribute to the semver value\n } else if (\n !compareValue ||\n !semverFunction(compareValue, semverValue)\n ) {\n removeNode(state, node)\n }\n } else {\n const manifestVersion = node.manifest?.version\n if (\n !manifestVersion ||\n !semverFunction(manifestVersion, semverValue)\n ) {\n removeNode(state, node)\n }\n }\n }\n\n return state\n}\n"]}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import type { ParserState
|
|
1
|
+
import type { ParserState } from '../types.ts';
|
|
2
|
+
import type { PostcssNode } from '@vltpkg/dss-parser';
|
|
2
3
|
export type SeverityKinds = '0' | '1' | '2' | '3' | 'critical' | 'high' | 'medium' | 'low' | undefined;
|
|
3
4
|
export type SeverityAlertTypes = 'criticalCVE' | 'cve' | 'potentialVulnerability' | 'mildCVE' | undefined;
|
|
5
|
+
export type SeverityComparator = '>' | '<' | '>=' | '<=' | undefined;
|
|
4
6
|
export declare const isSeverityKind: (value?: string) => value is SeverityKinds;
|
|
5
7
|
export declare const asSeverityKind: (value?: string) => SeverityKinds;
|
|
6
8
|
export declare const parseInternals: (nodes: PostcssNode[]) => {
|
|
7
9
|
kind: SeverityKinds;
|
|
10
|
+
comparator: SeverityComparator;
|
|
8
11
|
};
|
|
9
12
|
export declare const severity: (state: ParserState) => Promise<ParserState & {
|
|
10
13
|
securityArchive: NonNullable<ParserState["securityArchive"]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"severity.d.ts","sourceRoot":"","sources":["../../../src/pseudo/severity.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"severity.d.ts","sourceRoot":"","sources":["../../../src/pseudo/severity.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAErD,MAAM,MAAM,aAAa,GACrB,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,UAAU,GACV,MAAM,GACN,QAAQ,GACR,KAAK,GACL,SAAS,CAAA;AAEb,MAAM,MAAM,kBAAkB,GAC1B,aAAa,GACb,KAAK,GACL,wBAAwB,GACxB,SAAS,GACT,SAAS,CAAA;AAEb,MAAM,MAAM,kBAAkB,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAA;AA2BpE,eAAO,MAAM,cAAc,WACjB,MAAM,KACb,KAAK,IAAI,aAAkD,CAAA;AAE9D,eAAO,MAAM,cAAc,WAAY,MAAM,KAAG,aAQ/C,CAAA;AAED,eAAO,MAAM,cAAc,UAClB,WAAW,EAAE,KACnB;IACD,IAAI,EAAE,aAAa,CAAA;IACnB,UAAU,EAAE,kBAAkB,CAAA;CAqD/B,CAAA;AAED,eAAO,MAAM,QAAQ,UAAiB,WAAW;;EA+FhD,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { error } from '@vltpkg/error-cause';
|
|
2
|
-
import { asPostcssNodeWithChildren, asStringNode, asTagNode, isStringNode, isTagNode, } from
|
|
2
|
+
import { asPostcssNodeWithChildren, asStringNode, asTagNode, isStringNode, isTagNode, } from '@vltpkg/dss-parser';
|
|
3
3
|
import { assertSecurityArchive, removeDanglingEdges, removeNode, removeQuotes, } from "./helpers.js";
|
|
4
4
|
const kindsMap = new Map([
|
|
5
5
|
['critical', 'criticalCVE'],
|
|
@@ -11,6 +11,17 @@ const kindsMap = new Map([
|
|
|
11
11
|
['2', 'potentialVulnerability'],
|
|
12
12
|
['3', 'mildCVE'],
|
|
13
13
|
]);
|
|
14
|
+
// Map numerical values to their respective kinds for comparison operations
|
|
15
|
+
const kindLevelMap = new Map([
|
|
16
|
+
['critical', 0],
|
|
17
|
+
['high', 1],
|
|
18
|
+
['medium', 2],
|
|
19
|
+
['low', 3],
|
|
20
|
+
['0', 0],
|
|
21
|
+
['1', 1],
|
|
22
|
+
['2', 2],
|
|
23
|
+
['3', 3],
|
|
24
|
+
]);
|
|
14
25
|
const kinds = new Set(kindsMap.keys());
|
|
15
26
|
export const isSeverityKind = (value) => kinds.has(value);
|
|
16
27
|
export const asSeverityKind = (value) => {
|
|
@@ -24,14 +35,47 @@ export const asSeverityKind = (value) => {
|
|
|
24
35
|
};
|
|
25
36
|
export const parseInternals = (nodes) => {
|
|
26
37
|
let kind;
|
|
38
|
+
let comparator;
|
|
39
|
+
if (nodes.length === 0) {
|
|
40
|
+
throw error('Missing severity kind parameter');
|
|
41
|
+
}
|
|
42
|
+
let kindValue = '';
|
|
27
43
|
if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
|
|
28
|
-
|
|
29
|
-
.value)
|
|
44
|
+
kindValue = removeQuotes(asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])
|
|
45
|
+
.value);
|
|
30
46
|
}
|
|
31
47
|
else if (isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
|
|
32
|
-
|
|
48
|
+
kindValue = asTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0]).value;
|
|
49
|
+
}
|
|
50
|
+
// Extract comparator if present
|
|
51
|
+
if (kindValue.startsWith('>=')) {
|
|
52
|
+
comparator = '>=';
|
|
53
|
+
kindValue = kindValue.substring(2);
|
|
54
|
+
}
|
|
55
|
+
else if (kindValue.startsWith('<=')) {
|
|
56
|
+
comparator = '<=';
|
|
57
|
+
kindValue = kindValue.substring(2);
|
|
33
58
|
}
|
|
34
|
-
|
|
59
|
+
else if (kindValue.startsWith('>')) {
|
|
60
|
+
comparator = '>';
|
|
61
|
+
kindValue = kindValue.substring(1);
|
|
62
|
+
}
|
|
63
|
+
else if (kindValue.startsWith('<')) {
|
|
64
|
+
comparator = '<';
|
|
65
|
+
kindValue = kindValue.substring(1);
|
|
66
|
+
}
|
|
67
|
+
// Parse kind value
|
|
68
|
+
if (kindValue) {
|
|
69
|
+
if (isSeverityKind(kindValue)) {
|
|
70
|
+
kind = kindValue;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
throw error('Expected a valid severity kind or number between 0-3', {
|
|
74
|
+
found: kindValue,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return { kind, comparator };
|
|
35
79
|
};
|
|
36
80
|
export const severity = async (state) => {
|
|
37
81
|
assertSecurityArchive(state, 'severity');
|
|
@@ -42,11 +86,70 @@ export const severity = async (state) => {
|
|
|
42
86
|
catch (err) {
|
|
43
87
|
throw error('Failed to parse :severity selector', { cause: err });
|
|
44
88
|
}
|
|
45
|
-
const { kind } = internals;
|
|
46
|
-
const alertName = kindsMap.get(kind);
|
|
89
|
+
const { kind, comparator } = internals;
|
|
47
90
|
for (const node of state.partial.nodes) {
|
|
48
91
|
const report = state.securityArchive.get(node.id);
|
|
49
|
-
|
|
92
|
+
// Always exclude nodes that don't have security data or alerts
|
|
93
|
+
if (!report?.alerts || report.alerts.length === 0) {
|
|
94
|
+
removeNode(state, node);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
for (const node of state.partial.nodes) {
|
|
98
|
+
const report = state.securityArchive.get(node.id);
|
|
99
|
+
let exclude = true;
|
|
100
|
+
if (report) {
|
|
101
|
+
if (comparator) {
|
|
102
|
+
// retrieve the value to compare against
|
|
103
|
+
const kindLevel = kindLevelMap.get(kind);
|
|
104
|
+
// the kindLevel value has already been validated at this point
|
|
105
|
+
// and thus can never return an undefined/falsy value but ts doesn't
|
|
106
|
+
// know about that, so we have the extra check here
|
|
107
|
+
/* c8 ignore next - impossible */
|
|
108
|
+
if (!kindLevel)
|
|
109
|
+
break;
|
|
110
|
+
// Check each alert to find any that match our comparison criteria
|
|
111
|
+
for (const alert of report.alerts) {
|
|
112
|
+
// Get the numerical value of the alert type
|
|
113
|
+
const alertType = alert.type;
|
|
114
|
+
// retrieve a key to the current alert level to be compared against
|
|
115
|
+
const currentAlertLevelKey = [...kindsMap.entries()].find(([_, alertValue]) => alertValue === alertType)?.[0];
|
|
116
|
+
// perform the comparison based on the user-provided kindLevel
|
|
117
|
+
if (currentAlertLevelKey) {
|
|
118
|
+
const currentAlertLevel = kindLevelMap.get(currentAlertLevelKey);
|
|
119
|
+
/* c8 ignore next - impossible but ts doesn't know */
|
|
120
|
+
if (currentAlertLevel == null)
|
|
121
|
+
continue;
|
|
122
|
+
switch (comparator) {
|
|
123
|
+
case '>':
|
|
124
|
+
if (currentAlertLevel > kindLevel) {
|
|
125
|
+
exclude = false;
|
|
126
|
+
}
|
|
127
|
+
break;
|
|
128
|
+
case '<':
|
|
129
|
+
if (currentAlertLevel < kindLevel) {
|
|
130
|
+
exclude = false;
|
|
131
|
+
}
|
|
132
|
+
break;
|
|
133
|
+
case '>=':
|
|
134
|
+
if (currentAlertLevel >= kindLevel) {
|
|
135
|
+
exclude = false;
|
|
136
|
+
}
|
|
137
|
+
break;
|
|
138
|
+
case '<=':
|
|
139
|
+
if (currentAlertLevel <= kindLevel) {
|
|
140
|
+
exclude = false;
|
|
141
|
+
}
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
// Original exact match behavior
|
|
149
|
+
const alertName = kindsMap.get(kind);
|
|
150
|
+
exclude = !report.alerts.some(alert => alert.type === alertName);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
50
153
|
if (exclude) {
|
|
51
154
|
removeNode(state, node);
|
|
52
155
|
}
|