@vltpkg/query 1.5.0 → 1.6.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.
Files changed (211) hide show
  1. package/dist/id.js +12 -5
  2. package/package.json +10 -12
  3. package/skills/dss-query/REFERENCE.md +0 -125
  4. package/skills/dss-query/SKILL.md +0 -190
  5. package/skills/dss-query/evals/README.md +0 -81
  6. package/skills/dss-query/evals/evals.json +0 -89
  7. package/skills/dss-query/evals/grade.mjs +0 -481
  8. package/src/attribute.ts +0 -190
  9. package/src/combinator.ts +0 -135
  10. package/src/error.ts +0 -78
  11. package/src/id.ts +0 -46
  12. package/src/index.ts +0 -670
  13. package/src/parser.ts +0 -122
  14. package/src/pseudo/abandoned.ts +0 -9
  15. package/src/pseudo/attr.ts +0 -92
  16. package/src/pseudo/built.ts +0 -19
  17. package/src/pseudo/confused.ts +0 -29
  18. package/src/pseudo/cve.ts +0 -93
  19. package/src/pseudo/cwe.ts +0 -97
  20. package/src/pseudo/debug.ts +0 -9
  21. package/src/pseudo/deprecated.ts +0 -9
  22. package/src/pseudo/dev.ts +0 -18
  23. package/src/pseudo/diff.ts +0 -90
  24. package/src/pseudo/dist.ts +0 -148
  25. package/src/pseudo/dynamic.ts +0 -9
  26. package/src/pseudo/empty.ts +0 -15
  27. package/src/pseudo/entropic.ts +0 -9
  28. package/src/pseudo/env.ts +0 -6
  29. package/src/pseudo/eval.ts +0 -9
  30. package/src/pseudo/fs.ts +0 -9
  31. package/src/pseudo/helpers.ts +0 -106
  32. package/src/pseudo/host.ts +0 -111
  33. package/src/pseudo/hostname.ts +0 -156
  34. package/src/pseudo/license.ts +0 -134
  35. package/src/pseudo/link.ts +0 -30
  36. package/src/pseudo/malware.ts +0 -41
  37. package/src/pseudo/minified.ts +0 -9
  38. package/src/pseudo/missing.ts +0 -16
  39. package/src/pseudo/native.ts +0 -9
  40. package/src/pseudo/network.ts +0 -9
  41. package/src/pseudo/obfuscated.ts +0 -9
  42. package/src/pseudo/optional.ts +0 -18
  43. package/src/pseudo/outdated.ts +0 -345
  44. package/src/pseudo/overridden.ts +0 -20
  45. package/src/pseudo/path.ts +0 -146
  46. package/src/pseudo/peer.ts +0 -18
  47. package/src/pseudo/prerelease.ts +0 -47
  48. package/src/pseudo/private.ts +0 -19
  49. package/src/pseudo/prod.ts +0 -18
  50. package/src/pseudo/published.ts +0 -250
  51. package/src/pseudo/registry.ts +0 -29
  52. package/src/pseudo/root.ts +0 -19
  53. package/src/pseudo/scanned.ts +0 -20
  54. package/src/pseudo/score.ts +0 -186
  55. package/src/pseudo/scripts.ts +0 -61
  56. package/src/pseudo/semver.ts +0 -320
  57. package/src/pseudo/severity.ts +0 -231
  58. package/src/pseudo/shell.ts +0 -9
  59. package/src/pseudo/shrinkwrap.ts +0 -9
  60. package/src/pseudo/skill.ts +0 -59
  61. package/src/pseudo/skills.ts +0 -29
  62. package/src/pseudo/spec.ts +0 -131
  63. package/src/pseudo/squat.ts +0 -225
  64. package/src/pseudo/suspicious.ts +0 -9
  65. package/src/pseudo/tracker.ts +0 -9
  66. package/src/pseudo/trivial.ts +0 -9
  67. package/src/pseudo/type.ts +0 -26
  68. package/src/pseudo/undesirable.ts +0 -9
  69. package/src/pseudo/unknown.ts +0 -9
  70. package/src/pseudo/unmaintained.ts +0 -9
  71. package/src/pseudo/unpopular.ts +0 -9
  72. package/src/pseudo/unstable.ts +0 -9
  73. package/src/pseudo/vuln.ts +0 -273
  74. package/src/pseudo/workspace.ts +0 -22
  75. package/src/pseudo.ts +0 -440
  76. package/src/types.ts +0 -206
  77. package/tap-snapshots/test/attribute.ts.test.cjs +0 -304
  78. package/tap-snapshots/test/combinator.ts.test.cjs +0 -333
  79. package/tap-snapshots/test/id.ts.test.cjs +0 -118
  80. package/tap-snapshots/test/parser.ts.test.cjs +0 -344
  81. package/tap-snapshots/test/pseudo/abandoned.ts.test.cjs +0 -18
  82. package/tap-snapshots/test/pseudo/attr.ts.test.cjs +0 -161
  83. package/tap-snapshots/test/pseudo/built.ts.test.cjs +0 -70
  84. package/tap-snapshots/test/pseudo/confused.ts.test.cjs +0 -32
  85. package/tap-snapshots/test/pseudo/cve.ts.test.cjs +0 -49
  86. package/tap-snapshots/test/pseudo/cwe.ts.test.cjs +0 -49
  87. package/tap-snapshots/test/pseudo/debug.ts.test.cjs +0 -18
  88. package/tap-snapshots/test/pseudo/deprecated.ts.test.cjs +0 -18
  89. package/tap-snapshots/test/pseudo/dist.ts.test.cjs +0 -30
  90. package/tap-snapshots/test/pseudo/dynamic.ts.test.cjs +0 -18
  91. package/tap-snapshots/test/pseudo/empty.ts.test.cjs +0 -50
  92. package/tap-snapshots/test/pseudo/entropic.ts.test.cjs +0 -18
  93. package/tap-snapshots/test/pseudo/env.ts.test.cjs +0 -18
  94. package/tap-snapshots/test/pseudo/eval.ts.test.cjs +0 -18
  95. package/tap-snapshots/test/pseudo/fs.ts.test.cjs +0 -18
  96. package/tap-snapshots/test/pseudo/helpers.ts.test.cjs +0 -18
  97. package/tap-snapshots/test/pseudo/hostname.ts.test.cjs +0 -148
  98. package/tap-snapshots/test/pseudo/license.ts.test.cjs +0 -41
  99. package/tap-snapshots/test/pseudo/link.ts.test.cjs +0 -36
  100. package/tap-snapshots/test/pseudo/malware.ts.test.cjs +0 -22
  101. package/tap-snapshots/test/pseudo/minified.ts.test.cjs +0 -18
  102. package/tap-snapshots/test/pseudo/missing.ts.test.cjs +0 -30
  103. package/tap-snapshots/test/pseudo/native.ts.test.cjs +0 -18
  104. package/tap-snapshots/test/pseudo/network.ts.test.cjs +0 -18
  105. package/tap-snapshots/test/pseudo/obfuscated.ts.test.cjs +0 -18
  106. package/tap-snapshots/test/pseudo/outdated.ts.test.cjs +0 -132
  107. package/tap-snapshots/test/pseudo/overridden.ts.test.cjs +0 -75
  108. package/tap-snapshots/test/pseudo/prerelease.ts.test.cjs +0 -101
  109. package/tap-snapshots/test/pseudo/private.ts.test.cjs +0 -38
  110. package/tap-snapshots/test/pseudo/published.ts.test.cjs +0 -171
  111. package/tap-snapshots/test/pseudo/registry.ts.test.cjs +0 -68
  112. package/tap-snapshots/test/pseudo/root.ts.test.cjs +0 -24
  113. package/tap-snapshots/test/pseudo/scanned.ts.test.cjs +0 -18
  114. package/tap-snapshots/test/pseudo/score.ts.test.cjs +0 -239
  115. package/tap-snapshots/test/pseudo/scripts.ts.test.cjs +0 -62
  116. package/tap-snapshots/test/pseudo/semver.ts.test.cjs +0 -575
  117. package/tap-snapshots/test/pseudo/severity.ts.test.cjs +0 -122
  118. package/tap-snapshots/test/pseudo/shell.ts.test.cjs +0 -18
  119. package/tap-snapshots/test/pseudo/shrinkwrap.ts.test.cjs +0 -18
  120. package/tap-snapshots/test/pseudo/skills.ts.test.cjs +0 -19
  121. package/tap-snapshots/test/pseudo/spec.ts.test.cjs +0 -148
  122. package/tap-snapshots/test/pseudo/squat.ts.test.cjs +0 -129
  123. package/tap-snapshots/test/pseudo/suspicious.ts.test.cjs +0 -18
  124. package/tap-snapshots/test/pseudo/tracker.ts.test.cjs +0 -18
  125. package/tap-snapshots/test/pseudo/trivial.ts.test.cjs +0 -18
  126. package/tap-snapshots/test/pseudo/type.ts.test.cjs +0 -51
  127. package/tap-snapshots/test/pseudo/undesirable.ts.test.cjs +0 -18
  128. package/tap-snapshots/test/pseudo/unknown.ts.test.cjs +0 -18
  129. package/tap-snapshots/test/pseudo/unmaintained.ts.test.cjs +0 -18
  130. package/tap-snapshots/test/pseudo/unpopular.ts.test.cjs +0 -18
  131. package/tap-snapshots/test/pseudo/unstable.ts.test.cjs +0 -18
  132. package/tap-snapshots/test/pseudo/vuln.ts.test.cjs +0 -208
  133. package/tap-snapshots/test/pseudo/vulnerable.ts.test.cjs +0 -20
  134. package/tap-snapshots/test/pseudo/workspace.ts.test.cjs +0 -19
  135. package/tap-snapshots/test/pseudo.ts.test.cjs +0 -1247
  136. package/test/attribute.ts +0 -273
  137. package/test/combinator.ts +0 -175
  138. package/test/error.ts +0 -60
  139. package/test/fixtures/graph.ts +0 -999
  140. package/test/fixtures/selector.ts +0 -103
  141. package/test/fixtures/types.ts +0 -7
  142. package/test/id.ts +0 -102
  143. package/test/index.ts +0 -1148
  144. package/test/parser.ts +0 -117
  145. package/test/pseudo/abandoned.ts +0 -98
  146. package/test/pseudo/attr.ts +0 -298
  147. package/test/pseudo/built.ts +0 -214
  148. package/test/pseudo/confused.ts +0 -160
  149. package/test/pseudo/cve.ts +0 -249
  150. package/test/pseudo/cwe.ts +0 -255
  151. package/test/pseudo/debug.ts +0 -98
  152. package/test/pseudo/deprecated.ts +0 -98
  153. package/test/pseudo/dev.ts +0 -61
  154. package/test/pseudo/diff.ts +0 -417
  155. package/test/pseudo/dist.ts +0 -215
  156. package/test/pseudo/dynamic.ts +0 -98
  157. package/test/pseudo/empty.ts +0 -108
  158. package/test/pseudo/entropic.ts +0 -101
  159. package/test/pseudo/env.ts +0 -98
  160. package/test/pseudo/eval.ts +0 -98
  161. package/test/pseudo/fs.ts +0 -98
  162. package/test/pseudo/helpers.ts +0 -370
  163. package/test/pseudo/host-context.ts +0 -276
  164. package/test/pseudo/hostname.ts +0 -314
  165. package/test/pseudo/license.ts +0 -265
  166. package/test/pseudo/link.ts +0 -94
  167. package/test/pseudo/malware.ts +0 -184
  168. package/test/pseudo/minified.ts +0 -98
  169. package/test/pseudo/missing.ts +0 -111
  170. package/test/pseudo/native.ts +0 -98
  171. package/test/pseudo/network.ts +0 -98
  172. package/test/pseudo/obfuscated.ts +0 -98
  173. package/test/pseudo/optional.ts +0 -73
  174. package/test/pseudo/outdated.ts +0 -461
  175. package/test/pseudo/overridden.ts +0 -317
  176. package/test/pseudo/path.ts +0 -680
  177. package/test/pseudo/peer.ts +0 -101
  178. package/test/pseudo/prerelease.ts +0 -279
  179. package/test/pseudo/private.ts +0 -108
  180. package/test/pseudo/prod.ts +0 -61
  181. package/test/pseudo/published.ts +0 -557
  182. package/test/pseudo/registry.ts +0 -122
  183. package/test/pseudo/root.ts +0 -66
  184. package/test/pseudo/scanned.ts +0 -144
  185. package/test/pseudo/score.ts +0 -591
  186. package/test/pseudo/scripts.ts +0 -324
  187. package/test/pseudo/semver.ts +0 -822
  188. package/test/pseudo/severity.ts +0 -342
  189. package/test/pseudo/shell.ts +0 -98
  190. package/test/pseudo/shrinkwrap.ts +0 -98
  191. package/test/pseudo/skill.ts +0 -189
  192. package/test/pseudo/skills.ts +0 -90
  193. package/test/pseudo/spec.ts +0 -525
  194. package/test/pseudo/squat.ts +0 -565
  195. package/test/pseudo/suspicious.ts +0 -98
  196. package/test/pseudo/tracker.ts +0 -98
  197. package/test/pseudo/trivial.ts +0 -98
  198. package/test/pseudo/type.ts +0 -105
  199. package/test/pseudo/undesirable.ts +0 -98
  200. package/test/pseudo/unknown.ts +0 -98
  201. package/test/pseudo/unmaintained.ts +0 -98
  202. package/test/pseudo/unpopular.ts +0 -98
  203. package/test/pseudo/unstable.ts +0 -98
  204. package/test/pseudo/vuln.ts +0 -625
  205. package/test/pseudo/vulnerable.ts +0 -137
  206. package/test/pseudo/workspace.ts +0 -111
  207. package/test/pseudo.ts +0 -584
  208. package/tsconfig.json +0 -3
  209. package/tsconfig.publish.json +0 -19
  210. package/tsconfig.publish.tsbuildinfo +0 -1
  211. package/typedoc.mjs +0 -2
@@ -1,189 +0,0 @@
1
- import t from 'tap'
2
- import { Query } from '../../src/index.ts'
3
- import { getSimpleGraph } from '../fixtures/graph.ts'
4
- import type { Test } from 'tap'
5
- import type { QueryOptions } from '../../src/index.ts'
6
-
7
- type Opts = Pick<QueryOptions, 'partSelectors'>
8
-
9
- const search = (
10
- q: string,
11
- opts: Opts = { partSelectors: ['skill'] },
12
- ) => {
13
- const graph = getSimpleGraph()
14
- return new Query({
15
- edges: graph.edges,
16
- nodes: new Set(graph.nodes.values()),
17
- importers: graph.importers,
18
- securityArchive: undefined,
19
- ...opts,
20
- }).search(q, { signal: new AbortController().signal })
21
- }
22
-
23
- const parts = async (q: string) =>
24
- (await search(q)).parts?.map(({ nodes, ...p }) => ({
25
- ...p,
26
- nodes: nodes.map(n => n.name).sort(),
27
- }))
28
-
29
- type QueryErr = Error & {
30
- cause: { code: string; found: string; wanted?: string }
31
- }
32
- const errorOf = async (q: string, opts?: Opts) =>
33
- search(q, opts).then(
34
- () => {
35
- throw new Error(`expected ${q} to throw`)
36
- },
37
- (er: unknown) => er as QueryErr,
38
- )
39
-
40
- const fails = async (
41
- t: Test,
42
- queries: string[],
43
- message: string,
44
- opts?: Opts,
45
- ) => {
46
- for (const q of queries) {
47
- const er = await errorOf(q, opts)
48
- t.equal(er.message, message, q)
49
- t.equal(er.cause.code, 'EQUERY', q)
50
- }
51
- }
52
-
53
- t.test('patterns', async t => {
54
- const cases: [string, string[]][] = [
55
- ['#a:skill(find-skills)', ['find-skills']],
56
- ['#a:skill("my skill")', ['my skill']],
57
- [
58
- '#a:skill(vercel*, *-review, a*b*c, *, **)',
59
- ['vercel*', '*-review', 'a*b*c', '*', '**'],
60
- ],
61
- [
62
- '#a:skill(X, my.skill, a_b, 3d-print, -x)',
63
- ['X', 'my.skill', 'a_b', '3d-print', '-x'],
64
- ],
65
- ['#a:skill("my "*)', ['my *']],
66
- ['#a:skill(a\\ b)', ['a b']],
67
- ['#a:skill(/* c */ a)', ['a']],
68
- ['#a:skill("it\'s")', ["it's"]],
69
- ['#a:skill(x)/* c */ /* d */', ['x']],
70
- ]
71
- for (const [q, patterns] of cases) {
72
- t.strictSame(
73
- await parts(q),
74
- [{ name: 'skill', patterns, nodes: ['a'] }],
75
- q,
76
- )
77
- }
78
- })
79
-
80
- t.test('never filters nodes', async t => {
81
- const nodesOf = async (q: string) => (await parts(q))?.[0]?.nodes
82
- t.strictSame(await nodesOf(':skill(x)'), [
83
- '@x/y',
84
- 'a',
85
- 'b',
86
- 'c',
87
- 'd',
88
- 'e',
89
- 'f',
90
- 'my-project',
91
- ])
92
- t.strictSame(await nodesOf('#b :skill(x)'), ['c', 'd', 'e', 'f'])
93
- t.strictSame(await nodesOf(':root > :skill(x)'), [
94
- '@x/y',
95
- 'a',
96
- 'b',
97
- 'e',
98
- ])
99
- })
100
-
101
- t.test('specificity', async t => {
102
- t.strictSame((await search('#a:skill(x)')).specificity, {
103
- idCounter: 1,
104
- commonCounter: 1,
105
- })
106
- })
107
-
108
- t.test('errors', async t => {
109
- await fails(
110
- t,
111
- [
112
- '#a:skill(x) > #b',
113
- '#a:skill(x):prod',
114
- '#a:skill(x):skill(y)',
115
- ':not(#a:skill(x))',
116
- ':is(#a:skill(x))',
117
- ':has(#a:skill(x))',
118
- '#b, #a:skill(x) > *',
119
- ],
120
- ':skill() must end a top-level selector',
121
- )
122
- await fails(
123
- t,
124
- [
125
- '#a:skill',
126
- '#a:skill()',
127
- '#a:skill( )',
128
- '#a:skill(a,)',
129
- '#a:skill(/* c */)',
130
- '#a:skill("")',
131
- ],
132
- 'Missing skill name in :skill()',
133
- )
134
- await fails(
135
- t,
136
- ['#a:skill(a b)', '#a:skill(x > y)', '#b, #a:skill(a b)'],
137
- 'Invalid skill name in :skill(), quote names with spaces',
138
- )
139
- await fails(
140
- t,
141
- ["#a:skill('b c')", "#a:skill(x, 'y')", "#a:skill('y'*)"],
142
- 'Invalid skill name in :skill(), use double quotes',
143
- )
144
- await fails(
145
- t,
146
- [
147
- '#a:skill(#x)',
148
- '#a:skill(:prod)',
149
- '#a:skill([x])',
150
- '#a:skill(a|b)',
151
- '#a:skill(|a)',
152
- '#a:skill(a|*)',
153
- '#a:skill(a&b)',
154
- ],
155
- 'Invalid skill name in :skill()',
156
- )
157
- t.equal((await errorOf('#a:skill(a b)')).cause.found, ':skill(a b)')
158
- t.equal(
159
- (await errorOf('#a:skill(x) > #b')).cause.found,
160
- ':skill(x)',
161
- )
162
- })
163
-
164
- t.test('opt-in', async t => {
165
- const queries = ['#a:skill(x)', '#a, #b:skill(x)', '#a:skill()']
166
- const message =
167
- ':skill() only applies to --allow-skills and vlt skills'
168
- for (const opts of [{}, { partSelectors: [] }]) {
169
- await fails(t, queries, message, opts)
170
- // position is checked first
171
- await fails(
172
- t,
173
- [':not(#a:skill(x))'],
174
- ':skill() must end a top-level selector',
175
- opts,
176
- )
177
- }
178
- })
179
-
180
- t.test('typo', async t => {
181
- const er = await errorOf('#a:skills(x)')
182
- t.equal(er.message, ':skills takes no arguments')
183
- t.equal(er.cause.wanted, ':skill')
184
- // loose in a comma list: silently empty
185
- t.strictSame(await parts('#a, #b:skills(x)'), [
186
- { nodes: ['a'] },
187
- { nodes: [] },
188
- ])
189
- })
@@ -1,90 +0,0 @@
1
- import t from 'tap'
2
- import postcssSelectorParser from 'postcss-selector-parser'
3
- import type { EdgeLike, NodeLike } from '@vltpkg/types'
4
- import type { HasSkills, ParserState } from '../../src/types.ts'
5
- import { skills } from '../../src/pseudo/skills.ts'
6
- import { getSimpleGraph } from '../fixtures/graph.ts'
7
-
8
- const getState = (
9
- query: string,
10
- hasSkills?: HasSkills,
11
- loose?: boolean,
12
- ) => {
13
- const graph = getSimpleGraph()
14
- const current = postcssSelectorParser().astSync(query).first.first
15
- const state: ParserState = {
16
- comment: '',
17
- current,
18
- initial: {
19
- edges: new Set(graph.edges.values()),
20
- nodes: new Set(graph.nodes.values()),
21
- },
22
- partial: {
23
- edges: new Set(graph.edges.values()),
24
- nodes: new Set(graph.nodes.values()),
25
- },
26
- collect: { edges: new Set(), nodes: new Set() },
27
- cancellable: async () => {},
28
- walk: async i => i,
29
- retries: 0,
30
- securityArchive: undefined,
31
- importers: new Set(graph.importers),
32
- signal: new AbortController().signal,
33
- specificity: { idCounter: 0, commonCounter: 0 },
34
- hasSkills,
35
- loose,
36
- }
37
- return state
38
- }
39
-
40
- const names = (state: ParserState) => ({
41
- nodes: [...state.partial.nodes].map(n => n.name).sort(),
42
- edges: [...state.partial.edges].map(e => e.name).sort(),
43
- })
44
-
45
- t.test('matches packages the provider says ship skills', async t => {
46
- const asked: string[] = []
47
- const hasSkills: HasSkills = async (node: NodeLike) => {
48
- asked.push(String(node.name))
49
- await new Promise(r => setTimeout(r, 0))
50
- return node.name === 'a' || node.name === 'd'
51
- }
52
- const state = getState(':skills', hasSkills)
53
- // edge with no node: dropped
54
- state.partial.edges.add({ name: 'gone' } as EdgeLike)
55
- const res = await skills(state)
56
- t.strictSame(names(res), { nodes: ['a', 'd'], edges: ['a', 'd'] })
57
- t.matchSnapshot(names(res))
58
- t.strictSame(
59
- asked.sort(),
60
- ['@x/y', 'a', 'b', 'c', 'd', 'e', 'f', 'my-project'],
61
- 'asked once per node',
62
- )
63
- })
64
-
65
- t.test('none', async t => {
66
- const res = await skills(getState(':skills', async () => false))
67
- t.strictSame(names(res), { nodes: [], edges: [] })
68
- })
69
-
70
- t.test('no provider', async t => {
71
- await t.rejects(skills(getState(':skills')), {
72
- message: 'The :skills selector is not supported here',
73
- cause: { code: 'EQUERY', found: ':skills' },
74
- })
75
- })
76
-
77
- t.test('arguments', async t => {
78
- for (const q of [':skills(x)', ':skills()']) {
79
- await t.rejects(
80
- skills(getState(q, async () => true)),
81
- {
82
- message: ':skills takes no arguments',
83
- cause: { code: 'EQUERY', found: q, wanted: ':skill' },
84
- },
85
- q,
86
- )
87
- const res = await skills(getState(q, async () => true, true))
88
- t.strictSame(names(res), { nodes: [], edges: [] }, `${q} loose`)
89
- }
90
- })