@vltpkg/query 1.0.0-rc.18 → 1.0.0-rc.22

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.
Files changed (245) hide show
  1. package/package.json +30 -27
  2. package/dist/attribute.d.ts +0 -15
  3. package/dist/attribute.d.ts.map +0 -1
  4. package/dist/attribute.js +0 -133
  5. package/dist/attribute.js.map +0 -1
  6. package/dist/combinator.d.ts +0 -6
  7. package/dist/combinator.d.ts.map +0 -1
  8. package/dist/combinator.js +0 -112
  9. package/dist/combinator.js.map +0 -1
  10. package/dist/id.d.ts +0 -6
  11. package/dist/id.d.ts.map +0 -1
  12. package/dist/id.js +0 -36
  13. package/dist/id.js.map +0 -1
  14. package/dist/index.d.ts +0 -48
  15. package/dist/index.d.ts.map +0 -1
  16. package/dist/index.js +0 -408
  17. package/dist/index.js.map +0 -1
  18. package/dist/parser.d.ts +0 -15
  19. package/dist/parser.d.ts.map +0 -1
  20. package/dist/parser.js +0 -93
  21. package/dist/parser.js.map +0 -1
  22. package/dist/pseudo/abandoned.d.ts +0 -7
  23. package/dist/pseudo/abandoned.d.ts.map +0 -1
  24. package/dist/pseudo/abandoned.js +0 -6
  25. package/dist/pseudo/abandoned.js.map +0 -1
  26. package/dist/pseudo/attr.d.ts +0 -19
  27. package/dist/pseudo/attr.d.ts.map +0 -1
  28. package/dist/pseudo/attr.js +0 -58
  29. package/dist/pseudo/attr.js.map +0 -1
  30. package/dist/pseudo/built.d.ts +0 -8
  31. package/dist/pseudo/built.d.ts.map +0 -1
  32. package/dist/pseudo/built.js +0 -16
  33. package/dist/pseudo/built.js.map +0 -1
  34. package/dist/pseudo/confused.d.ts +0 -9
  35. package/dist/pseudo/confused.d.ts.map +0 -1
  36. package/dist/pseudo/confused.js +0 -19
  37. package/dist/pseudo/confused.js.map +0 -1
  38. package/dist/pseudo/cve.d.ts +0 -13
  39. package/dist/pseudo/cve.d.ts.map +0 -1
  40. package/dist/pseudo/cve.js +0 -44
  41. package/dist/pseudo/cve.js.map +0 -1
  42. package/dist/pseudo/cwe.d.ts +0 -13
  43. package/dist/pseudo/cwe.d.ts.map +0 -1
  44. package/dist/pseudo/cwe.js +0 -43
  45. package/dist/pseudo/cwe.js.map +0 -1
  46. package/dist/pseudo/debug.d.ts +0 -7
  47. package/dist/pseudo/debug.d.ts.map +0 -1
  48. package/dist/pseudo/debug.js +0 -6
  49. package/dist/pseudo/debug.js.map +0 -1
  50. package/dist/pseudo/deprecated.d.ts +0 -7
  51. package/dist/pseudo/deprecated.d.ts.map +0 -1
  52. package/dist/pseudo/deprecated.js +0 -6
  53. package/dist/pseudo/deprecated.js.map +0 -1
  54. package/dist/pseudo/dev.d.ts +0 -6
  55. package/dist/pseudo/dev.d.ts.map +0 -1
  56. package/dist/pseudo/dev.js +0 -15
  57. package/dist/pseudo/dev.js.map +0 -1
  58. package/dist/pseudo/dynamic.d.ts +0 -7
  59. package/dist/pseudo/dynamic.d.ts.map +0 -1
  60. package/dist/pseudo/dynamic.js +0 -6
  61. package/dist/pseudo/dynamic.js.map +0 -1
  62. package/dist/pseudo/empty.d.ts +0 -7
  63. package/dist/pseudo/empty.d.ts.map +0 -1
  64. package/dist/pseudo/empty.js +0 -14
  65. package/dist/pseudo/empty.js.map +0 -1
  66. package/dist/pseudo/entropic.d.ts +0 -7
  67. package/dist/pseudo/entropic.d.ts.map +0 -1
  68. package/dist/pseudo/entropic.js +0 -6
  69. package/dist/pseudo/entropic.js.map +0 -1
  70. package/dist/pseudo/env.d.ts +0 -7
  71. package/dist/pseudo/env.d.ts.map +0 -1
  72. package/dist/pseudo/env.js +0 -6
  73. package/dist/pseudo/env.js.map +0 -1
  74. package/dist/pseudo/eval.d.ts +0 -7
  75. package/dist/pseudo/eval.d.ts.map +0 -1
  76. package/dist/pseudo/eval.js +0 -6
  77. package/dist/pseudo/eval.js.map +0 -1
  78. package/dist/pseudo/fs.d.ts +0 -7
  79. package/dist/pseudo/fs.d.ts.map +0 -1
  80. package/dist/pseudo/fs.js +0 -6
  81. package/dist/pseudo/fs.js.map +0 -1
  82. package/dist/pseudo/helpers.d.ts +0 -39
  83. package/dist/pseudo/helpers.d.ts.map +0 -1
  84. package/dist/pseudo/helpers.js +0 -80
  85. package/dist/pseudo/helpers.js.map +0 -1
  86. package/dist/pseudo/host.d.ts +0 -20
  87. package/dist/pseudo/host.d.ts.map +0 -1
  88. package/dist/pseudo/host.js +0 -80
  89. package/dist/pseudo/host.js.map +0 -1
  90. package/dist/pseudo/license.d.ts +0 -13
  91. package/dist/pseudo/license.d.ts.map +0 -1
  92. package/dist/pseudo/license.js +0 -75
  93. package/dist/pseudo/license.js.map +0 -1
  94. package/dist/pseudo/link.d.ts +0 -9
  95. package/dist/pseudo/link.d.ts.map +0 -1
  96. package/dist/pseudo/link.js +0 -25
  97. package/dist/pseudo/link.js.map +0 -1
  98. package/dist/pseudo/malware.d.ts +0 -24
  99. package/dist/pseudo/malware.d.ts.map +0 -1
  100. package/dist/pseudo/malware.js +0 -187
  101. package/dist/pseudo/malware.js.map +0 -1
  102. package/dist/pseudo/minified.d.ts +0 -7
  103. package/dist/pseudo/minified.d.ts.map +0 -1
  104. package/dist/pseudo/minified.js +0 -6
  105. package/dist/pseudo/minified.js.map +0 -1
  106. package/dist/pseudo/missing.d.ts +0 -8
  107. package/dist/pseudo/missing.d.ts.map +0 -1
  108. package/dist/pseudo/missing.js +0 -15
  109. package/dist/pseudo/missing.js.map +0 -1
  110. package/dist/pseudo/native.d.ts +0 -7
  111. package/dist/pseudo/native.d.ts.map +0 -1
  112. package/dist/pseudo/native.js +0 -6
  113. package/dist/pseudo/native.js.map +0 -1
  114. package/dist/pseudo/network.d.ts +0 -7
  115. package/dist/pseudo/network.d.ts.map +0 -1
  116. package/dist/pseudo/network.js +0 -6
  117. package/dist/pseudo/network.js.map +0 -1
  118. package/dist/pseudo/obfuscated.d.ts +0 -7
  119. package/dist/pseudo/obfuscated.d.ts.map +0 -1
  120. package/dist/pseudo/obfuscated.js +0 -6
  121. package/dist/pseudo/obfuscated.js.map +0 -1
  122. package/dist/pseudo/optional.d.ts +0 -6
  123. package/dist/pseudo/optional.d.ts.map +0 -1
  124. package/dist/pseudo/optional.js +0 -15
  125. package/dist/pseudo/optional.js.map +0 -1
  126. package/dist/pseudo/outdated.d.ts +0 -54
  127. package/dist/pseudo/outdated.d.ts.map +0 -1
  128. package/dist/pseudo/outdated.js +0 -212
  129. package/dist/pseudo/outdated.js.map +0 -1
  130. package/dist/pseudo/overridden.d.ts +0 -8
  131. package/dist/pseudo/overridden.d.ts.map +0 -1
  132. package/dist/pseudo/overridden.js +0 -17
  133. package/dist/pseudo/overridden.js.map +0 -1
  134. package/dist/pseudo/path.d.ts +0 -19
  135. package/dist/pseudo/path.d.ts.map +0 -1
  136. package/dist/pseudo/path.js +0 -113
  137. package/dist/pseudo/path.js.map +0 -1
  138. package/dist/pseudo/peer.d.ts +0 -6
  139. package/dist/pseudo/peer.d.ts.map +0 -1
  140. package/dist/pseudo/peer.js +0 -15
  141. package/dist/pseudo/peer.js.map +0 -1
  142. package/dist/pseudo/prerelease.d.ts +0 -18
  143. package/dist/pseudo/prerelease.d.ts.map +0 -1
  144. package/dist/pseudo/prerelease.js +0 -41
  145. package/dist/pseudo/prerelease.js.map +0 -1
  146. package/dist/pseudo/private.d.ts +0 -7
  147. package/dist/pseudo/private.d.ts.map +0 -1
  148. package/dist/pseudo/private.js +0 -16
  149. package/dist/pseudo/private.js.map +0 -1
  150. package/dist/pseudo/prod.d.ts +0 -6
  151. package/dist/pseudo/prod.d.ts.map +0 -1
  152. package/dist/pseudo/prod.js +0 -15
  153. package/dist/pseudo/prod.js.map +0 -1
  154. package/dist/pseudo/published.d.ts +0 -40
  155. package/dist/pseudo/published.d.ts.map +0 -1
  156. package/dist/pseudo/published.js +0 -180
  157. package/dist/pseudo/published.js.map +0 -1
  158. package/dist/pseudo/root.d.ts +0 -7
  159. package/dist/pseudo/root.d.ts.map +0 -1
  160. package/dist/pseudo/root.js +0 -18
  161. package/dist/pseudo/root.js.map +0 -1
  162. package/dist/pseudo/scanned.d.ts +0 -9
  163. package/dist/pseudo/scanned.d.ts.map +0 -1
  164. package/dist/pseudo/scanned.js +0 -17
  165. package/dist/pseudo/scanned.js.map +0 -1
  166. package/dist/pseudo/score.d.ts +0 -16
  167. package/dist/pseudo/score.d.ts.map +0 -1
  168. package/dist/pseudo/score.js +0 -133
  169. package/dist/pseudo/score.js.map +0 -1
  170. package/dist/pseudo/scripts.d.ts +0 -10
  171. package/dist/pseudo/scripts.d.ts.map +0 -1
  172. package/dist/pseudo/scripts.js +0 -44
  173. package/dist/pseudo/scripts.js.map +0 -1
  174. package/dist/pseudo/semver.d.ts +0 -17
  175. package/dist/pseudo/semver.d.ts.map +0 -1
  176. package/dist/pseudo/semver.js +0 -167
  177. package/dist/pseudo/semver.js.map +0 -1
  178. package/dist/pseudo/severity.d.ts +0 -15
  179. package/dist/pseudo/severity.d.ts.map +0 -1
  180. package/dist/pseudo/severity.js +0 -160
  181. package/dist/pseudo/severity.js.map +0 -1
  182. package/dist/pseudo/shell.d.ts +0 -7
  183. package/dist/pseudo/shell.d.ts.map +0 -1
  184. package/dist/pseudo/shell.js +0 -6
  185. package/dist/pseudo/shell.js.map +0 -1
  186. package/dist/pseudo/shrinkwrap.d.ts +0 -7
  187. package/dist/pseudo/shrinkwrap.d.ts.map +0 -1
  188. package/dist/pseudo/shrinkwrap.js +0 -6
  189. package/dist/pseudo/shrinkwrap.js.map +0 -1
  190. package/dist/pseudo/spec.d.ts +0 -17
  191. package/dist/pseudo/spec.d.ts.map +0 -1
  192. package/dist/pseudo/spec.js +0 -102
  193. package/dist/pseudo/spec.js.map +0 -1
  194. package/dist/pseudo/squat.d.ts +0 -15
  195. package/dist/pseudo/squat.d.ts.map +0 -1
  196. package/dist/pseudo/squat.js +0 -172
  197. package/dist/pseudo/squat.js.map +0 -1
  198. package/dist/pseudo/suspicious.d.ts +0 -7
  199. package/dist/pseudo/suspicious.d.ts.map +0 -1
  200. package/dist/pseudo/suspicious.js +0 -6
  201. package/dist/pseudo/suspicious.js.map +0 -1
  202. package/dist/pseudo/tracker.d.ts +0 -7
  203. package/dist/pseudo/tracker.d.ts.map +0 -1
  204. package/dist/pseudo/tracker.js +0 -6
  205. package/dist/pseudo/tracker.js.map +0 -1
  206. package/dist/pseudo/trivial.d.ts +0 -7
  207. package/dist/pseudo/trivial.d.ts.map +0 -1
  208. package/dist/pseudo/trivial.js +0 -6
  209. package/dist/pseudo/trivial.js.map +0 -1
  210. package/dist/pseudo/type.d.ts +0 -8
  211. package/dist/pseudo/type.d.ts.map +0 -1
  212. package/dist/pseudo/type.js +0 -22
  213. package/dist/pseudo/type.js.map +0 -1
  214. package/dist/pseudo/undesirable.d.ts +0 -7
  215. package/dist/pseudo/undesirable.d.ts.map +0 -1
  216. package/dist/pseudo/undesirable.js +0 -6
  217. package/dist/pseudo/undesirable.js.map +0 -1
  218. package/dist/pseudo/unknown.d.ts +0 -7
  219. package/dist/pseudo/unknown.d.ts.map +0 -1
  220. package/dist/pseudo/unknown.js +0 -6
  221. package/dist/pseudo/unknown.js.map +0 -1
  222. package/dist/pseudo/unmaintained.d.ts +0 -7
  223. package/dist/pseudo/unmaintained.d.ts.map +0 -1
  224. package/dist/pseudo/unmaintained.js +0 -6
  225. package/dist/pseudo/unmaintained.js.map +0 -1
  226. package/dist/pseudo/unpopular.d.ts +0 -7
  227. package/dist/pseudo/unpopular.d.ts.map +0 -1
  228. package/dist/pseudo/unpopular.js +0 -6
  229. package/dist/pseudo/unpopular.js.map +0 -1
  230. package/dist/pseudo/unstable.d.ts +0 -7
  231. package/dist/pseudo/unstable.d.ts.map +0 -1
  232. package/dist/pseudo/unstable.js +0 -6
  233. package/dist/pseudo/unstable.js.map +0 -1
  234. package/dist/pseudo/workspace.d.ts +0 -6
  235. package/dist/pseudo/workspace.d.ts.map +0 -1
  236. package/dist/pseudo/workspace.js +0 -20
  237. package/dist/pseudo/workspace.js.map +0 -1
  238. package/dist/pseudo.d.ts +0 -6
  239. package/dist/pseudo.d.ts.map +0 -1
  240. package/dist/pseudo.js +0 -361
  241. package/dist/pseudo.js.map +0 -1
  242. package/dist/types.d.ts +0 -118
  243. package/dist/types.d.ts.map +0 -1
  244. package/dist/types.js +0 -2
  245. package/dist/types.js.map +0 -1
@@ -1,133 +0,0 @@
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
@@ -1 +0,0 @@
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,EAAE,CAAA;IAChB,IAAI,UAAU,GAAoB,GAAG,CAAA;IACrC,IAAI,IAAI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AI,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,10 +0,0 @@
1
- import type { ParserState } from '../types.ts';
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)
8
- */
9
- export declare const scripts: (state: ParserState) => Promise<ParserState>;
10
- //# sourceMappingURL=scripts.d.ts.map
@@ -1 +0,0 @@
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,44 +0,0 @@
1
- import { removeNode, removeDanglingEdges } from "./helpers.js";
2
- /**
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)
6
- */
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
- };
44
- //# sourceMappingURL=scripts.js.map
@@ -1 +0,0 @@
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,17 +0,0 @@
1
- import type { Version } from '@vltpkg/semver';
2
- import type { AttrInternals } from './attr.ts';
3
- import type { ParserState } from '../types.ts';
4
- import type { PostcssNode } from '@vltpkg/dss-parser';
5
- export type SemverInternals = {
6
- semverValue: string;
7
- semverFunction: SemverComparatorFn;
8
- compareAttribute: SemverCompareAttribute;
9
- };
10
- export type SemverFunctionNames = 'satisfies' | 'gt' | 'gte' | 'lt' | 'lte' | 'eq' | 'neq';
11
- export type SemverComparatorFn = (version: Version | string, range: string) => boolean;
12
- export type SemverCompareAttribute = Pick<AttrInternals, 'attribute' | 'properties'> | undefined;
13
- export declare const isSemverFunctionName: (name: string) => name is SemverFunctionNames;
14
- export declare const asSemverFunctionName: (name: string) => SemverFunctionNames;
15
- export declare const parseInternals: (nodes: PostcssNode[], loose: boolean) => SemverInternals;
16
- export declare const semverParser: (state: ParserState) => Promise<ParserState>;
17
- //# sourceMappingURL=semver.d.ts.map
@@ -1 +0,0 @@
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,167 +0,0 @@
1
- import { satisfies, gt, gte, lt, lte, eq, neq, parse, parseRange, } from '@vltpkg/semver';
2
- import { error } from '@vltpkg/error-cause';
3
- import { asError } from '@vltpkg/types';
4
- import { parseInternals as parseAttrInternals } from "./attr.js";
5
- import { getManifestPropertyValues } from "../attribute.js";
6
- import { asAttributeNode, asPostcssNodeWithChildren, asPseudoNode, asStringNode, asTagNode, isAttributeNode, isPseudoNode, isStringNode, isTagNode, } from '@vltpkg/dss-parser';
7
- import { removeNode, removeQuotes } from "./helpers.js";
8
- const semverFunctionNames = new Set([
9
- 'satisfies',
10
- 'gt',
11
- 'gte',
12
- 'lt',
13
- 'lte',
14
- 'eq',
15
- 'neq',
16
- ]);
17
- export const isSemverFunctionName = (name) => semverFunctionNames.has(name);
18
- export const asSemverFunctionName = (name) => {
19
- if (!isSemverFunctionName(name)) {
20
- throw error('Invalid semver function name', {
21
- found: name,
22
- validOptions: Array.from(semverFunctionNames),
23
- });
24
- }
25
- return name;
26
- };
27
- const semverFunctions = new Map([
28
- ['satisfies', satisfies],
29
- ['gt', gt],
30
- ['gte', gte],
31
- ['lt', lt],
32
- ['lte', lte],
33
- ['eq', eq],
34
- ['neq', neq],
35
- ]);
36
- export const parseInternals = (nodes, loose) => {
37
- // tries to parse the first param as a string node, otherwise defaults
38
- // to reading all postcss nodes as just strings, since it just means
39
- // the value was defined as an unquoted string
40
- let semverValue = '';
41
- try {
42
- semverValue = removeQuotes(asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])
43
- .value);
44
- }
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;
51
- }
52
- else {
53
- throw err;
54
- }
55
- }
56
- // second param is the function name
57
- let fnName = 'satisfies';
58
- try {
59
- // if there is a second node defined, try to parse it as a string node
60
- // first and if that fails, then parse it as a tag node which just means
61
- // it was defined as an unquoted string
62
- if (nodes[1]) {
63
- try {
64
- fnName = asSemverFunctionName(removeQuotes(asStringNode(asPostcssNodeWithChildren(nodes[1]).nodes[0])
65
- .value));
66
- }
67
- catch (err) {
68
- if (asError(err).message === 'Mismatching query node') {
69
- fnName = asSemverFunctionName(asTagNode(asPostcssNodeWithChildren(nodes[1]).nodes[0])
70
- .value);
71
- }
72
- else {
73
- throw err;
74
- }
75
- }
76
- }
77
- }
78
- catch (e) {
79
- // allow invalid semver function names in loose mode, defaults to satisfies
80
- if (!loose) {
81
- throw e;
82
- }
83
- }
84
- const semverFunction = semverFunctions.get(fnName);
85
- // the following should never happen as long as the semver function names
86
- // type and Set are correctly mirroring each other values
87
- /* c8 ignore start */
88
- if (!semverFunction) {
89
- throw error('Invalid semver function name', {
90
- found: fnName,
91
- validOptions: Array.from(semverFunctions.keys()),
92
- });
93
- }
94
- /* c8 ignore stop */
95
- // optional third param is the compare value
96
- let compareAttribute;
97
- if (nodes[2]) {
98
- const parentNode = asPostcssNodeWithChildren(nodes[2]);
99
- const currNode = parentNode.nodes[0];
100
- if (isAttributeNode(currNode)) {
101
- const { attribute } = asAttributeNode(currNode);
102
- compareAttribute = {
103
- attribute,
104
- properties: [attribute],
105
- };
106
- }
107
- else if (isPseudoNode(currNode)) {
108
- compareAttribute = parseAttrInternals(asPseudoNode(currNode).nodes);
109
- }
110
- else if (isStringNode(currNode)) {
111
- const attribute = removeQuotes(asStringNode(currNode).value);
112
- compareAttribute = {
113
- attribute,
114
- properties: [attribute],
115
- };
116
- }
117
- }
118
- return {
119
- semverValue,
120
- semverFunction,
121
- compareAttribute,
122
- };
123
- };
124
- export const semverParser = async (state) => {
125
- let internals;
126
- try {
127
- internals = parseInternals(asPostcssNodeWithChildren(state.current).nodes, !!state.loose);
128
- }
129
- catch (err) {
130
- throw error('Failed to parse :semver selector', {
131
- cause: err,
132
- });
133
- }
134
- const { semverValue, semverFunction, compareAttribute } = internals;
135
- for (const node of state.partial.nodes) {
136
- if (compareAttribute) {
137
- const compareValues = getManifestPropertyValues(node, compareAttribute.properties, compareAttribute.attribute);
138
- // if the provided semver value is a fixed semver version and the
139
- // compare attribute is resolving to a range value, then we flip the
140
- // order of comparison, in case it's a "satisfies" function check
141
- const compareValue = compareValues?.[0];
142
- const semverValueVersion = parse(semverValue);
143
- const compareValueRange = compareValue && parseRange(compareValue);
144
- if (semverFunction === satisfies &&
145
- semverValueVersion &&
146
- compareValueRange) {
147
- if (!satisfies(semverValueVersion, compareValueRange)) {
148
- removeNode(state, node);
149
- }
150
- // otherwise just compares the read attribute to the semver value
151
- }
152
- else if (!compareValue ||
153
- !semverFunction(compareValue, semverValue)) {
154
- removeNode(state, node);
155
- }
156
- }
157
- else {
158
- const manifestVersion = node.manifest?.version;
159
- if (!manifestVersion ||
160
- !semverFunction(manifestVersion, semverValue)) {
161
- removeNode(state, node);
162
- }
163
- }
164
- }
165
- return state;
166
- };
167
- //# sourceMappingURL=semver.js.map
@@ -1 +0,0 @@
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,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,SAAS,GACV,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AA0BvD,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC;IAClC,WAAW;IACX,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,KAAK;CACN,CAAC,CAAA;AACF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,IAAY,EACiB,EAAE,CAAC,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;AAE/D,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,IAAY,EACS,EAAE;IACvB,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC;QAChC,MAAM,KAAK,CAAC,8BAA8B,EAAE;YAC1C,KAAK,EAAE,IAAI;YACX,YAAY,EAAE,K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AAK,MAAM,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;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 { 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,15 +0,0 @@
1
- import type { ParserState } from '../types.ts';
2
- import type { PostcssNode } from '@vltpkg/dss-parser';
3
- export type SeverityKinds = '0' | '1' | '2' | '3' | 'critical' | 'high' | 'medium' | 'low' | undefined;
4
- export type SeverityAlertTypes = 'criticalCVE' | 'cve' | 'potentialVulnerability' | 'mildCVE' | undefined;
5
- export type SeverityComparator = '>' | '<' | '>=' | '<=' | undefined;
6
- export declare const isSeverityKind: (value?: string) => value is SeverityKinds;
7
- export declare const asSeverityKind: (value?: string) => SeverityKinds;
8
- export declare const parseInternals: (nodes: PostcssNode[]) => {
9
- kind: SeverityKinds;
10
- comparator: SeverityComparator;
11
- };
12
- export declare const severity: (state: ParserState) => Promise<ParserState & {
13
- securityArchive: NonNullable<ParserState["securityArchive"]>;
14
- }>;
15
- //# sourceMappingURL=severity.d.ts.map
@@ -1 +0,0 @@
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,160 +0,0 @@
1
- import { error } from '@vltpkg/error-cause';
2
- import { asPostcssNodeWithChildren, asStringNode, asTagNode, isStringNode, isTagNode, } from '@vltpkg/dss-parser';
3
- import { assertSecurityArchive, removeDanglingEdges, removeNode, removeQuotes, } from "./helpers.js";
4
- const kindsMap = new Map([
5
- ['critical', 'criticalCVE'],
6
- ['high', 'cve'],
7
- ['medium', 'potentialVulnerability'],
8
- ['low', 'mildCVE'],
9
- ['0', 'criticalCVE'],
10
- ['1', 'cve'],
11
- ['2', 'potentialVulnerability'],
12
- ['3', 'mildCVE'],
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
- ]);
25
- const kinds = new Set(kindsMap.keys());
26
- export const isSeverityKind = (value) => kinds.has(value);
27
- export const asSeverityKind = (value) => {
28
- if (!isSeverityKind(value)) {
29
- throw error('Expected a valid severity kind', {
30
- found: value,
31
- validOptions: Array.from(kinds),
32
- });
33
- }
34
- return value;
35
- };
36
- export const parseInternals = (nodes) => {
37
- let kind;
38
- let comparator;
39
- if (nodes.length === 0) {
40
- throw error('Missing severity kind parameter');
41
- }
42
- let kindValue = '';
43
- if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
44
- kindValue = removeQuotes(asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])
45
- .value);
46
- }
47
- else if (isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
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);
58
- }
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 };
79
- };
80
- export const severity = async (state) => {
81
- assertSecurityArchive(state, 'severity');
82
- let internals;
83
- try {
84
- internals = parseInternals(asPostcssNodeWithChildren(state.current).nodes);
85
- }
86
- catch (err) {
87
- throw error('Failed to parse :severity selector', { cause: err });
88
- }
89
- const { kind, comparator } = internals;
90
- for (const node of state.partial.nodes) {
91
- const report = state.securityArchive.get(node.id);
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
- }
153
- if (exclude) {
154
- removeNode(state, node);
155
- }
156
- }
157
- removeDanglingEdges(state);
158
- return state;
159
- };
160
- //# sourceMappingURL=severity.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"severity.js","sourceRoot":"","sources":["../../src/pseudo/severity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,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;AAwBrB,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAoC;IAC1D,CAAC,UAAU,EAAE,aAAa,CAAC;IAC3B,CAAC,MAAM,EAAE,KAAK,CAAC;IACf,CAAC,QAAQ,EAAE,wBAAwB,CAAC;IACpC,CAAC,KAAK,EAAE,SAAS,CAAC;IAClB,CAAC,GAAG,EAAE,aAAa,CAAC;IACpB,CAAC,GAAG,EAAE,KAAK,CAAC;IACZ,CAAC,GAAG,EAAE,wBAAwB,CAAC;IAC/B,CAAC,GAAG,EAAE,SAAS,CAAC;CACjB,CAAC,CAAA;AAEF,2EAA2E;AAC3E,MAAM,YAAY,GAAG,IAAI,GAAG,CAAwB;IAClD,CAAC,UAAU,EAAE,CAAC,CAAC;IACf,CAAC,MAAM,EAAE,CAAC,CAAC;IACX,CAAC,QAAQ,EAAE,CAAC,CAAC;IACb,CAAC,KAAK,EAAE,CAAC,CAAC;IACV,CAAC,GAAG,EAAE,CAAC,CAAC;IACR,CAAC,GAAG,EAAE,CAAC,CAAC;IACR,CAAC,GAAG,EAAE,CAAC,CAAC;IACR,CAAC,GAAG,EAAE,CAAC,CAAC;CACT,CAAC,CAAA;AAEF,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;AAEtC,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,KAAc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PostcssNodeWithChildren,\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 { ParserState } from '../types.ts'\nimport type { PostcssNode } from '@vltpkg/dss-parser'\n\nexport type SeverityKinds =\n | '0'\n | '1'\n | '2'\n | '3'\n | 'critical'\n | 'high'\n | 'medium'\n | 'low'\n | undefined\n\nexport type SeverityAlertTypes =\n | 'criticalCVE'\n | 'cve'\n | 'potentialVulnerability'\n | 'mildCVE'\n | undefined\n\nexport type SeverityComparator = '>' | '<' | '>=' | '<=' | undefined\n\nconst kindsMap = new Map<SeverityKinds, SeverityAlertTypes>([\n ['critical', 'criticalCVE'],\n ['high', 'cve'],\n ['medium', 'potentialVulnerability'],\n ['low', 'mildCVE'],\n ['0', 'criticalCVE'],\n ['1', 'cve'],\n ['2', 'potentialVulnerability'],\n ['3', 'mildCVE'],\n])\n\n// Map numerical values to their respective kinds for comparison operations\nconst kindLevelMap = new Map<SeverityKinds, number>([\n ['critical', 0],\n ['high', 1],\n ['medium', 2],\n ['low', 3],\n ['0', 0],\n ['1', 1],\n ['2', 2],\n ['3', 3],\n])\n\nconst kinds = new Set(kindsMap.keys())\n\nexport const isSeverityKind = (\n value?: string,\n): value is SeverityKinds => kinds.has(value as SeverityKinds)\n\nexport const asSeverityKind = (value?: string): SeverityKinds => {\n if (!isSeverityKind(value)) {\n throw error('Expected a valid severity kind', {\n found: value,\n validOptions: Array.from(kinds),\n })\n }\n return value\n}\n\nexport const parseInternals = (\n nodes: PostcssNode[],\n): {\n kind: SeverityKinds\n comparator: SeverityComparator\n} => {\n let kind: SeverityKinds\n let comparator: SeverityComparator\n\n if (nodes.length === 0) {\n throw error('Missing severity kind parameter')\n }\n\n let kindValue = ''\n if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {\n kindValue = removeQuotes(\n asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n .value,\n )\n } else if (\n isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n ) {\n kindValue = asTagNode(\n asPostcssNodeWithChildren(nodes[0]).nodes[0],\n ).value\n }\n\n // Extract comparator if present\n if (kindValue.startsWith('>=')) {\n comparator = '>='\n kindValue = kindValue.substring(2)\n } else if (kindValue.startsWith('<=')) {\n comparator = '<='\n kindValue = kindValue.substring(2)\n } else if (kindValue.startsWith('>')) {\n comparator = '>'\n kindValue = kindValue.substring(1)\n } else if (kindValue.startsWith('<')) {\n comparator = '<'\n kindValue = kindValue.substring(1)\n }\n\n // Parse kind value\n if (kindValue) {\n if (isSeverityKind(kindValue)) {\n kind = kindValue\n } else {\n throw error(\n 'Expected a valid severity kind or number between 0-3',\n {\n found: kindValue,\n },\n )\n }\n }\n\n return { kind, comparator }\n}\n\nexport const severity = async (state: ParserState) => {\n assertSecurityArchive(state, 'severity')\n\n let internals\n try {\n internals = parseInternals(\n asPostcssNodeWithChildren(state.current).nodes,\n )\n } catch (err) {\n throw error('Failed to parse :severity selector', { cause: err })\n }\n\n const { kind, comparator } = internals\n\n for (const node of state.partial.nodes) {\n const report = state.securityArchive.get(node.id)\n // Always exclude nodes that don't have security data or alerts\n if (!report?.alerts || report.alerts.length === 0) {\n removeNode(state, node)\n }\n }\n\n for (const node of state.partial.nodes) {\n const report = state.securityArchive.get(node.id)\n let exclude = true\n\n if (report) {\n if (comparator) {\n // retrieve the value to compare against\n const kindLevel = kindLevelMap.get(kind)\n // the kindLevel value has already been validated at this point\n // and thus can never return an undefined/falsy value but ts doesn't\n // know about that, so we have the extra check here\n /* c8 ignore next - impossible */\n if (!kindLevel) break\n\n // Check each alert to find any that match our comparison criteria\n for (const alert of report.alerts) {\n // Get the numerical value of the alert type\n const alertType = alert.type\n\n // retrieve a key to the current alert level to be compared against\n const currentAlertLevelKey = [...kindsMap.entries()].find(\n ([_, alertValue]) => alertValue === alertType,\n )?.[0]\n\n // perform the comparison based on the user-provided kindLevel\n if (currentAlertLevelKey) {\n const currentAlertLevel = kindLevelMap.get(\n currentAlertLevelKey,\n )\n /* c8 ignore next - impossible but ts doesn't know */\n if (currentAlertLevel == null) continue\n\n switch (comparator) {\n case '>':\n if (currentAlertLevel > kindLevel) {\n exclude = false\n }\n break\n case '<':\n if (currentAlertLevel < kindLevel) {\n exclude = false\n }\n break\n case '>=':\n if (currentAlertLevel >= kindLevel) {\n exclude = false\n }\n break\n case '<=':\n if (currentAlertLevel <= kindLevel) {\n exclude = false\n }\n break\n }\n }\n }\n } else {\n // Original exact match behavior\n const alertName = kindsMap.get(kind)\n exclude = !report.alerts.some(\n alert => alert.type === alertName,\n )\n }\n }\n\n if (exclude) {\n removeNode(state, node)\n }\n }\n\n removeDanglingEdges(state)\n\n return state\n}\n"]}