@vltpkg/query 1.0.0-rc.31 → 1.0.0-rc.33

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 (214) hide show
  1. package/dist/pseudo/cve.d.ts +6 -2
  2. package/dist/pseudo/cve.js +29 -11
  3. package/dist/pseudo/cwe.d.ts +6 -2
  4. package/dist/pseudo/cwe.js +29 -10
  5. package/dist/pseudo/dist.d.ts +22 -0
  6. package/dist/pseudo/dist.js +110 -0
  7. package/dist/pseudo/hostname.js +3 -1
  8. package/dist/pseudo/scripts.js +1 -1
  9. package/dist/pseudo/semver.d.ts +3 -1
  10. package/dist/pseudo/semver.js +43 -6
  11. package/dist/pseudo/vulnerable.d.ts +8 -0
  12. package/dist/pseudo/vulnerable.js +17 -0
  13. package/dist/pseudo.js +5 -0
  14. package/package.json +19 -10
  15. package/skills/dss-query/REFERENCE.md +119 -0
  16. package/skills/dss-query/SKILL.md +190 -0
  17. package/skills/dss-query/evals/README.md +79 -0
  18. package/skills/dss-query/evals/evals.json +89 -0
  19. package/skills/dss-query/evals/grade.mjs +480 -0
  20. package/src/attribute.ts +186 -0
  21. package/src/combinator.ts +132 -0
  22. package/src/id.ts +46 -0
  23. package/src/index.ts +613 -0
  24. package/src/parser.ts +121 -0
  25. package/src/pseudo/abandoned.ts +9 -0
  26. package/src/pseudo/attr.ts +92 -0
  27. package/src/pseudo/built.ts +19 -0
  28. package/src/pseudo/confused.ts +29 -0
  29. package/src/pseudo/cve.ts +93 -0
  30. package/src/pseudo/cwe.ts +97 -0
  31. package/src/pseudo/debug.ts +9 -0
  32. package/src/pseudo/deprecated.ts +9 -0
  33. package/src/pseudo/dev.ts +18 -0
  34. package/src/pseudo/diff.ts +90 -0
  35. package/src/pseudo/dist.ts +144 -0
  36. package/src/pseudo/dynamic.ts +9 -0
  37. package/src/pseudo/empty.ts +15 -0
  38. package/src/pseudo/entropic.ts +9 -0
  39. package/src/pseudo/env.ts +6 -0
  40. package/src/pseudo/eval.ts +9 -0
  41. package/src/pseudo/fs.ts +9 -0
  42. package/src/pseudo/helpers.ts +106 -0
  43. package/src/pseudo/host.ts +111 -0
  44. package/src/pseudo/hostname.ts +156 -0
  45. package/src/pseudo/license.ts +134 -0
  46. package/src/pseudo/link.ts +30 -0
  47. package/src/pseudo/malware.ts +249 -0
  48. package/src/pseudo/minified.ts +9 -0
  49. package/src/pseudo/missing.ts +16 -0
  50. package/src/pseudo/native.ts +9 -0
  51. package/src/pseudo/network.ts +9 -0
  52. package/src/pseudo/obfuscated.ts +9 -0
  53. package/src/pseudo/optional.ts +18 -0
  54. package/src/pseudo/outdated.ts +305 -0
  55. package/src/pseudo/overridden.ts +20 -0
  56. package/src/pseudo/path.ts +146 -0
  57. package/src/pseudo/peer.ts +18 -0
  58. package/src/pseudo/prerelease.ts +47 -0
  59. package/src/pseudo/private.ts +19 -0
  60. package/src/pseudo/prod.ts +18 -0
  61. package/src/pseudo/published.ts +248 -0
  62. package/src/pseudo/registry.ts +29 -0
  63. package/src/pseudo/root.ts +19 -0
  64. package/src/pseudo/scanned.ts +20 -0
  65. package/src/pseudo/score.ts +186 -0
  66. package/src/pseudo/scripts.ts +54 -0
  67. package/src/pseudo/semver.ts +320 -0
  68. package/src/pseudo/severity.ts +231 -0
  69. package/src/pseudo/shell.ts +9 -0
  70. package/src/pseudo/shrinkwrap.ts +9 -0
  71. package/src/pseudo/spec.ts +131 -0
  72. package/src/pseudo/squat.ts +225 -0
  73. package/src/pseudo/suspicious.ts +9 -0
  74. package/src/pseudo/tracker.ts +9 -0
  75. package/src/pseudo/trivial.ts +9 -0
  76. package/src/pseudo/type.ts +26 -0
  77. package/src/pseudo/undesirable.ts +9 -0
  78. package/src/pseudo/unknown.ts +9 -0
  79. package/src/pseudo/unmaintained.ts +9 -0
  80. package/src/pseudo/unpopular.ts +9 -0
  81. package/src/pseudo/unstable.ts +9 -0
  82. package/src/pseudo/vulnerable.ts +26 -0
  83. package/src/pseudo/workspace.ts +22 -0
  84. package/src/pseudo.ts +413 -0
  85. package/src/types.ts +164 -0
  86. package/tap-snapshots/test/attribute.ts.test.cjs +304 -0
  87. package/tap-snapshots/test/combinator.ts.test.cjs +333 -0
  88. package/tap-snapshots/test/id.ts.test.cjs +118 -0
  89. package/tap-snapshots/test/parser.ts.test.cjs +344 -0
  90. package/tap-snapshots/test/pseudo/abandoned.ts.test.cjs +18 -0
  91. package/tap-snapshots/test/pseudo/attr.ts.test.cjs +161 -0
  92. package/tap-snapshots/test/pseudo/built.ts.test.cjs +70 -0
  93. package/tap-snapshots/test/pseudo/confused.ts.test.cjs +32 -0
  94. package/tap-snapshots/test/pseudo/cve.ts.test.cjs +49 -0
  95. package/tap-snapshots/test/pseudo/cwe.ts.test.cjs +49 -0
  96. package/tap-snapshots/test/pseudo/debug.ts.test.cjs +18 -0
  97. package/tap-snapshots/test/pseudo/deprecated.ts.test.cjs +18 -0
  98. package/tap-snapshots/test/pseudo/dist.ts.test.cjs +30 -0
  99. package/tap-snapshots/test/pseudo/dynamic.ts.test.cjs +18 -0
  100. package/tap-snapshots/test/pseudo/empty.ts.test.cjs +50 -0
  101. package/tap-snapshots/test/pseudo/entropic.ts.test.cjs +18 -0
  102. package/tap-snapshots/test/pseudo/env.ts.test.cjs +18 -0
  103. package/tap-snapshots/test/pseudo/eval.ts.test.cjs +18 -0
  104. package/tap-snapshots/test/pseudo/fs.ts.test.cjs +18 -0
  105. package/tap-snapshots/test/pseudo/helpers.ts.test.cjs +18 -0
  106. package/tap-snapshots/test/pseudo/hostname.ts.test.cjs +148 -0
  107. package/tap-snapshots/test/pseudo/license.ts.test.cjs +41 -0
  108. package/tap-snapshots/test/pseudo/link.ts.test.cjs +36 -0
  109. package/tap-snapshots/test/pseudo/malware.ts.test.cjs +191 -0
  110. package/tap-snapshots/test/pseudo/minified.ts.test.cjs +18 -0
  111. package/tap-snapshots/test/pseudo/missing.ts.test.cjs +30 -0
  112. package/tap-snapshots/test/pseudo/native.ts.test.cjs +18 -0
  113. package/tap-snapshots/test/pseudo/network.ts.test.cjs +18 -0
  114. package/tap-snapshots/test/pseudo/obfuscated.ts.test.cjs +18 -0
  115. package/tap-snapshots/test/pseudo/outdated.ts.test.cjs +130 -0
  116. package/tap-snapshots/test/pseudo/overridden.ts.test.cjs +75 -0
  117. package/tap-snapshots/test/pseudo/prerelease.ts.test.cjs +101 -0
  118. package/tap-snapshots/test/pseudo/private.ts.test.cjs +38 -0
  119. package/tap-snapshots/test/pseudo/published.ts.test.cjs +171 -0
  120. package/tap-snapshots/test/pseudo/registry.ts.test.cjs +68 -0
  121. package/tap-snapshots/test/pseudo/root.ts.test.cjs +24 -0
  122. package/tap-snapshots/test/pseudo/scanned.ts.test.cjs +18 -0
  123. package/tap-snapshots/test/pseudo/score.ts.test.cjs +239 -0
  124. package/tap-snapshots/test/pseudo/scripts.ts.test.cjs +61 -0
  125. package/tap-snapshots/test/pseudo/semver.ts.test.cjs +575 -0
  126. package/tap-snapshots/test/pseudo/severity.ts.test.cjs +95 -0
  127. package/tap-snapshots/test/pseudo/shell.ts.test.cjs +18 -0
  128. package/tap-snapshots/test/pseudo/shrinkwrap.ts.test.cjs +18 -0
  129. package/tap-snapshots/test/pseudo/spec.ts.test.cjs +148 -0
  130. package/tap-snapshots/test/pseudo/squat.ts.test.cjs +129 -0
  131. package/tap-snapshots/test/pseudo/suspicious.ts.test.cjs +18 -0
  132. package/tap-snapshots/test/pseudo/tracker.ts.test.cjs +18 -0
  133. package/tap-snapshots/test/pseudo/trivial.ts.test.cjs +18 -0
  134. package/tap-snapshots/test/pseudo/type.ts.test.cjs +51 -0
  135. package/tap-snapshots/test/pseudo/undesirable.ts.test.cjs +18 -0
  136. package/tap-snapshots/test/pseudo/unknown.ts.test.cjs +18 -0
  137. package/tap-snapshots/test/pseudo/unmaintained.ts.test.cjs +18 -0
  138. package/tap-snapshots/test/pseudo/unpopular.ts.test.cjs +18 -0
  139. package/tap-snapshots/test/pseudo/unstable.ts.test.cjs +18 -0
  140. package/tap-snapshots/test/pseudo/vulnerable.ts.test.cjs +18 -0
  141. package/tap-snapshots/test/pseudo/workspace.ts.test.cjs +19 -0
  142. package/tap-snapshots/test/pseudo.ts.test.cjs +1247 -0
  143. package/test/attribute.ts +266 -0
  144. package/test/combinator.ts +168 -0
  145. package/test/fixtures/graph.ts +999 -0
  146. package/test/fixtures/selector.ts +103 -0
  147. package/test/fixtures/types.ts +7 -0
  148. package/test/id.ts +102 -0
  149. package/test/index.ts +992 -0
  150. package/test/parser.ts +117 -0
  151. package/test/pseudo/abandoned.ts +98 -0
  152. package/test/pseudo/attr.ts +298 -0
  153. package/test/pseudo/built.ts +214 -0
  154. package/test/pseudo/confused.ts +160 -0
  155. package/test/pseudo/cve.ts +249 -0
  156. package/test/pseudo/cwe.ts +255 -0
  157. package/test/pseudo/debug.ts +98 -0
  158. package/test/pseudo/deprecated.ts +98 -0
  159. package/test/pseudo/dev.ts +61 -0
  160. package/test/pseudo/diff.ts +417 -0
  161. package/test/pseudo/dist.ts +215 -0
  162. package/test/pseudo/dynamic.ts +98 -0
  163. package/test/pseudo/empty.ts +108 -0
  164. package/test/pseudo/entropic.ts +101 -0
  165. package/test/pseudo/env.ts +98 -0
  166. package/test/pseudo/eval.ts +98 -0
  167. package/test/pseudo/fs.ts +98 -0
  168. package/test/pseudo/helpers.ts +370 -0
  169. package/test/pseudo/host-context.ts +276 -0
  170. package/test/pseudo/hostname.ts +314 -0
  171. package/test/pseudo/license.ts +265 -0
  172. package/test/pseudo/link.ts +94 -0
  173. package/test/pseudo/malware.ts +431 -0
  174. package/test/pseudo/minified.ts +98 -0
  175. package/test/pseudo/missing.ts +111 -0
  176. package/test/pseudo/native.ts +98 -0
  177. package/test/pseudo/network.ts +98 -0
  178. package/test/pseudo/obfuscated.ts +98 -0
  179. package/test/pseudo/optional.ts +73 -0
  180. package/test/pseudo/outdated.ts +331 -0
  181. package/test/pseudo/overridden.ts +317 -0
  182. package/test/pseudo/path.ts +680 -0
  183. package/test/pseudo/peer.ts +101 -0
  184. package/test/pseudo/prerelease.ts +279 -0
  185. package/test/pseudo/private.ts +108 -0
  186. package/test/pseudo/prod.ts +61 -0
  187. package/test/pseudo/published.ts +557 -0
  188. package/test/pseudo/registry.ts +122 -0
  189. package/test/pseudo/root.ts +66 -0
  190. package/test/pseudo/scanned.ts +78 -0
  191. package/test/pseudo/score.ts +591 -0
  192. package/test/pseudo/scripts.ts +294 -0
  193. package/test/pseudo/semver.ts +822 -0
  194. package/test/pseudo/severity.ts +310 -0
  195. package/test/pseudo/shell.ts +98 -0
  196. package/test/pseudo/shrinkwrap.ts +98 -0
  197. package/test/pseudo/spec.ts +525 -0
  198. package/test/pseudo/squat.ts +565 -0
  199. package/test/pseudo/suspicious.ts +98 -0
  200. package/test/pseudo/tracker.ts +98 -0
  201. package/test/pseudo/trivial.ts +98 -0
  202. package/test/pseudo/type.ts +105 -0
  203. package/test/pseudo/undesirable.ts +98 -0
  204. package/test/pseudo/unknown.ts +98 -0
  205. package/test/pseudo/unmaintained.ts +98 -0
  206. package/test/pseudo/unpopular.ts +98 -0
  207. package/test/pseudo/unstable.ts +98 -0
  208. package/test/pseudo/vulnerable.ts +130 -0
  209. package/test/pseudo/workspace.ts +111 -0
  210. package/test/pseudo.ts +558 -0
  211. package/tsconfig.json +3 -0
  212. package/tsconfig.publish.json +19 -0
  213. package/tsconfig.publish.tsbuildinfo +1 -0
  214. package/typedoc.mjs +2 -0
@@ -0,0 +1,225 @@
1
+ import { error } from '@vltpkg/error-cause'
2
+ import { asError } from '@vltpkg/types'
3
+ import {
4
+ asPostcssNodeWithChildren,
5
+ asStringNode,
6
+ asTagNode,
7
+ isStringNode,
8
+ isTagNode,
9
+ } from '@vltpkg/dss-parser'
10
+ import {
11
+ assertSecurityArchive,
12
+ removeDanglingEdges,
13
+ removeNode,
14
+ removeQuotes,
15
+ } from './helpers.ts'
16
+ import type { ParserState } from '../types.ts'
17
+ import type { PostcssNode } from '@vltpkg/dss-parser'
18
+
19
+ export type SquatKinds = '0' | '2' | 'critical' | 'medium' | undefined
20
+
21
+ export type SquatAlertTypes =
22
+ 'didYouMean' | 'gptDidYouMean' | undefined
23
+
24
+ export type SquatComparator = '>' | '<' | '>=' | '<=' | undefined
25
+
26
+ const kindsMap = new Map<SquatKinds, SquatAlertTypes>([
27
+ ['critical', 'didYouMean'],
28
+ ['medium', 'gptDidYouMean'],
29
+ ['0', 'didYouMean'],
30
+ ['2', 'gptDidYouMean'],
31
+ [undefined, undefined],
32
+ ])
33
+
34
+ // Map numerical values to their respective kinds for comparison operations
35
+ const kindLevelMap = new Map<SquatKinds, number>([
36
+ ['critical', 0],
37
+ ['medium', 2],
38
+ ['0', 0],
39
+ ['2', 2],
40
+ ])
41
+
42
+ const kinds = new Set(kindsMap.keys())
43
+
44
+ export const isSquatKind = (value?: string): value is SquatKinds =>
45
+ kinds.has(value as SquatKinds)
46
+
47
+ export const asSquatKind = (value?: string): SquatKinds => {
48
+ if (!isSquatKind(value)) {
49
+ throw error('Expected a valid squat kind', {
50
+ found: value,
51
+ validOptions: Array.from(kinds),
52
+ })
53
+ }
54
+ return value
55
+ }
56
+
57
+ export const parseInternals = (
58
+ nodes: PostcssNode[],
59
+ ): {
60
+ kind: SquatKinds
61
+ comparator: SquatComparator
62
+ } => {
63
+ let kind: SquatKinds
64
+ let comparator: SquatComparator
65
+
66
+ let kindValue = ''
67
+ if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
68
+ kindValue = removeQuotes(
69
+ asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])
70
+ .value,
71
+ )
72
+ } else if (
73
+ isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])
74
+ ) {
75
+ kindValue = asTagNode(
76
+ asPostcssNodeWithChildren(nodes[0]).nodes[0],
77
+ ).value
78
+ }
79
+
80
+ // Extract comparator if present
81
+ if (kindValue.startsWith('>=')) {
82
+ comparator = '>='
83
+ kindValue = kindValue.substring(2)
84
+ } else if (kindValue.startsWith('<=')) {
85
+ comparator = '<='
86
+ kindValue = kindValue.substring(2)
87
+ } else if (kindValue.startsWith('>')) {
88
+ comparator = '>'
89
+ kindValue = kindValue.substring(1)
90
+ } else if (kindValue.startsWith('<')) {
91
+ comparator = '<'
92
+ kindValue = kindValue.substring(1)
93
+ }
94
+
95
+ // Parse kind value
96
+ if (kindValue) {
97
+ if (isSquatKind(kindValue)) {
98
+ kind = kindValue
99
+ } else {
100
+ throw error('Expected a valid squat kind for comparison', {
101
+ found: kindValue,
102
+ validOptions: Array.from(kinds),
103
+ })
104
+ }
105
+ }
106
+
107
+ return { kind, comparator }
108
+ }
109
+
110
+ export const squat = async (state: ParserState) => {
111
+ assertSecurityArchive(state, 'squat')
112
+
113
+ let internals
114
+ try {
115
+ internals = parseInternals(
116
+ asPostcssNodeWithChildren(state.current).nodes,
117
+ )
118
+ } catch (err) {
119
+ if (asError(err).message === 'Expected a query node') {
120
+ // No parameters provided - pseudo state form: match ANY squat level
121
+ internals = { kind: undefined, comparator: undefined }
122
+ } else {
123
+ throw error('Failed to parse :squat selector', { cause: err })
124
+ }
125
+ }
126
+
127
+ const { kind, comparator } = internals
128
+
129
+ // First pass: Remove nodes without security data
130
+ for (const node of state.partial.nodes) {
131
+ const report = state.securityArchive.get(node.id)
132
+ // Always exclude nodes that don't have security data or alerts
133
+ if (!report?.alerts || report.alerts.length === 0) {
134
+ removeNode(state, node)
135
+ }
136
+ }
137
+
138
+ // Second pass: Apply comparison filtering
139
+ for (const node of state.partial.nodes) {
140
+ const report = state.securityArchive.get(node.id)
141
+
142
+ // Skip if report is undefined
143
+ // (should never happen since we filtered above)
144
+ /* c8 ignore next - impossible */
145
+ if (!report) continue
146
+
147
+ // At this point we know report exists and has alerts
148
+ let exclude = true
149
+
150
+ if (kind === undefined && comparator === undefined) {
151
+ // Pseudo state form: match ANY squat level
152
+ exclude = !report.alerts.some(alert =>
153
+ [...kindsMap.values()].includes(
154
+ alert.type as SquatAlertTypes,
155
+ ),
156
+ )
157
+ } else if (comparator) {
158
+ // Get the value to compare against
159
+ const kindLevel = kindLevelMap.get(kind)
160
+ /* c8 ignore next - impossible */
161
+ if (kindLevel === undefined) break
162
+
163
+ // For each alert, check if it matches the comparison criteria
164
+ let matchesComparison = false
165
+ for (const alert of report.alerts) {
166
+ // Get the alert type
167
+ const alertType = alert.type
168
+
169
+ // Find the corresponding kind for this alert type
170
+ const alertLevelKey = [...kindsMap.entries()].find(
171
+ ([_, value]) => value === alertType,
172
+ )?.[0]
173
+
174
+ if (alertLevelKey) {
175
+ // Get the numeric level for this alert
176
+ const alertLevel = kindLevelMap.get(alertLevelKey)
177
+ /* c8 ignore next - impossible */
178
+ if (alertLevel === undefined) continue
179
+
180
+ // Apply the comparison based on the comparator
181
+ switch (comparator) {
182
+ case '>':
183
+ if (alertLevel > kindLevel) {
184
+ matchesComparison = true
185
+ }
186
+ break
187
+ case '<':
188
+ if (alertLevel < kindLevel) {
189
+ matchesComparison = true
190
+ }
191
+ break
192
+ case '>=':
193
+ if (alertLevel >= kindLevel) {
194
+ matchesComparison = true
195
+ }
196
+ break
197
+ case '<=':
198
+ if (alertLevel <= kindLevel) {
199
+ matchesComparison = true
200
+ }
201
+ break
202
+ }
203
+
204
+ // If we found a match, we can stop checking other alerts
205
+ if (matchesComparison) break
206
+ }
207
+ }
208
+
209
+ // Exclude the node if it doesn't match the comparison
210
+ exclude = !matchesComparison
211
+ } else {
212
+ // Original exact match behavior
213
+ const alertName = kindsMap.get(kind)
214
+ exclude = !report.alerts.some(alert => alert.type === alertName)
215
+ }
216
+
217
+ if (exclude) {
218
+ removeNode(state, node)
219
+ }
220
+ }
221
+
222
+ removeDanglingEdges(state)
223
+
224
+ return state
225
+ }
@@ -0,0 +1,9 @@
1
+ import { createSecuritySelectorFilter } from './helpers.ts'
2
+
3
+ /**
4
+ * Filters out any node that does not have a **suspiciousStarActivity** report alert.
5
+ */
6
+ export const suspicious = createSecuritySelectorFilter(
7
+ 'suspicious',
8
+ 'suspiciousStarActivity',
9
+ )
@@ -0,0 +1,9 @@
1
+ import { createSecuritySelectorFilter } from './helpers.ts'
2
+
3
+ /**
4
+ * Filters out any node that does not have a **telemetry** report alert.
5
+ */
6
+ export const tracker = createSecuritySelectorFilter(
7
+ 'tracker',
8
+ 'telemetry',
9
+ )
@@ -0,0 +1,9 @@
1
+ import { createSecuritySelectorFilter } from './helpers.ts'
2
+
3
+ /**
4
+ * Filters out any node that does not have a **trivialPackage** report alert.
5
+ */
6
+ export const trivial = createSecuritySelectorFilter(
7
+ 'trivial',
8
+ 'trivialPackage',
9
+ )
@@ -0,0 +1,26 @@
1
+ import { splitDepID } from '@vltpkg/dep-id/browser'
2
+ import {
3
+ asPostcssNodeWithChildren,
4
+ asTagNode,
5
+ } from '@vltpkg/dss-parser'
6
+ import { removeDanglingEdges, removeNode } from './helpers.ts'
7
+ import type { ParserState } from '../types.ts'
8
+
9
+ /**
10
+ * :type(str) Pseudo-Element will match only nodes that are of
11
+ * the same type as the value used. The type is determined by the
12
+ * first part of the dependency ID.
13
+ */
14
+ export const type = async (state: ParserState) => {
15
+ const type = asPostcssNodeWithChildren(state.current)
16
+ const selector = asPostcssNodeWithChildren(type.nodes[0])
17
+ const name = asTagNode(selector.nodes[0]).value
18
+ for (const node of state.partial.nodes) {
19
+ const nodeType = splitDepID(node.id)[0]
20
+ if (nodeType !== name) {
21
+ removeNode(state, node)
22
+ }
23
+ }
24
+ removeDanglingEdges(state)
25
+ return state
26
+ }
@@ -0,0 +1,9 @@
1
+ import { createSecuritySelectorFilter } from './helpers.ts'
2
+
3
+ /**
4
+ * Filters out any node that does not have a **troll** report alert.
5
+ */
6
+ export const undesirable = createSecuritySelectorFilter(
7
+ 'undesirable',
8
+ 'troll',
9
+ )
@@ -0,0 +1,9 @@
1
+ import { createSecuritySelectorFilter } from './helpers.ts'
2
+
3
+ /**
4
+ * Filters out any node that does not have a **newAuthor** report alert.
5
+ */
6
+ export const unknown = createSecuritySelectorFilter(
7
+ 'unknown',
8
+ 'newAuthor',
9
+ )
@@ -0,0 +1,9 @@
1
+ import { createSecuritySelectorFilter } from './helpers.ts'
2
+
3
+ /**
4
+ * Filters out any node that does not have a **unmaintained** report alert.
5
+ */
6
+ export const unmaintained = createSecuritySelectorFilter(
7
+ 'unmaintained',
8
+ 'unmaintained',
9
+ )
@@ -0,0 +1,9 @@
1
+ import { createSecuritySelectorFilter } from './helpers.ts'
2
+
3
+ /**
4
+ * Filters out any node that does not have a **unpopularPackage** report alert.
5
+ */
6
+ export const unpopular = createSecuritySelectorFilter(
7
+ 'unpopular',
8
+ 'unpopularPackage',
9
+ )
@@ -0,0 +1,9 @@
1
+ import { createSecuritySelectorFilter } from './helpers.ts'
2
+
3
+ /**
4
+ * Filters out any node that does not have a **unstableOwnership** report alert.
5
+ */
6
+ export const unstable = createSecuritySelectorFilter(
7
+ 'unstable',
8
+ 'unstableOwnership',
9
+ )
@@ -0,0 +1,26 @@
1
+ import type { ParserState } from '../types.ts'
2
+ import {
3
+ assertSecurityArchive,
4
+ removeDanglingEdges,
5
+ removeNode,
6
+ } from './helpers.ts'
7
+
8
+ /**
9
+ * :vulnerable / :vuln Pseudo-Selector matches any package version
10
+ * that has at least one CVE associated with it.
11
+ */
12
+ export const vulnerable = async (state: ParserState) => {
13
+ assertSecurityArchive(state, 'vulnerable')
14
+
15
+ for (const node of state.partial.nodes) {
16
+ const report = state.securityArchive.get(node.id)
17
+ const hasCve = report?.alerts.some(alert => alert.props?.cveId)
18
+ if (!hasCve) {
19
+ removeNode(state, node)
20
+ }
21
+ }
22
+
23
+ removeDanglingEdges(state)
24
+
25
+ return state
26
+ }
@@ -0,0 +1,22 @@
1
+ import type { ParserState } from '../types.ts'
2
+ import { removeNode } from './helpers.ts'
3
+
4
+ /**
5
+ * :workspace Pseudo-Selector will only match workspace dependencies.
6
+ */
7
+ export const workspace = async (state: ParserState) => {
8
+ // Filter out the root node and any nodes that are not marked as workspaces
9
+ for (const node of state.partial.nodes) {
10
+ if (!node.importer || node.mainImporter) {
11
+ removeNode(state, node)
12
+ }
13
+ }
14
+
15
+ // Clears up any edges that are not pointing to workspace nodes
16
+ for (const edge of state.partial.edges) {
17
+ if (edge.to?.importer && !edge.to.mainImporter) continue
18
+ state.partial.edges.delete(edge)
19
+ }
20
+
21
+ return state
22
+ }