@vltpkg/query 1.0.0-rc.32 → 1.0.0-rc.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +10 -6
- package/dist/parser.js +2 -1
- package/dist/pseudo/hostname.js +3 -1
- package/dist/pseudo/malware.d.ts +3 -16
- package/dist/pseudo/malware.js +11 -171
- package/dist/pseudo/scripts.js +1 -1
- package/dist/pseudo/vuln.d.ts +22 -0
- package/dist/pseudo/vuln.js +220 -0
- package/dist/pseudo.js +3 -3
- package/dist/types.d.ts +3 -2
- package/package.json +19 -10
- package/skills/dss-query/REFERENCE.md +123 -0
- package/skills/dss-query/SKILL.md +190 -0
- package/skills/dss-query/evals/README.md +79 -0
- package/skills/dss-query/evals/evals.json +89 -0
- package/skills/dss-query/evals/grade.mjs +480 -0
- package/src/attribute.ts +186 -0
- package/src/combinator.ts +132 -0
- package/src/id.ts +46 -0
- package/src/index.ts +620 -0
- package/src/parser.ts +122 -0
- package/src/pseudo/abandoned.ts +9 -0
- package/src/pseudo/attr.ts +92 -0
- package/src/pseudo/built.ts +19 -0
- package/src/pseudo/confused.ts +29 -0
- package/src/pseudo/cve.ts +93 -0
- package/src/pseudo/cwe.ts +97 -0
- package/src/pseudo/debug.ts +9 -0
- package/src/pseudo/deprecated.ts +9 -0
- package/src/pseudo/dev.ts +18 -0
- package/src/pseudo/diff.ts +90 -0
- package/src/pseudo/dist.ts +144 -0
- package/src/pseudo/dynamic.ts +9 -0
- package/src/pseudo/empty.ts +15 -0
- package/src/pseudo/entropic.ts +9 -0
- package/src/pseudo/env.ts +6 -0
- package/src/pseudo/eval.ts +9 -0
- package/src/pseudo/fs.ts +9 -0
- package/src/pseudo/helpers.ts +106 -0
- package/src/pseudo/host.ts +111 -0
- package/src/pseudo/hostname.ts +156 -0
- package/src/pseudo/license.ts +134 -0
- package/src/pseudo/link.ts +30 -0
- package/src/pseudo/malware.ts +41 -0
- package/src/pseudo/minified.ts +9 -0
- package/src/pseudo/missing.ts +16 -0
- package/src/pseudo/native.ts +9 -0
- package/src/pseudo/network.ts +9 -0
- package/src/pseudo/obfuscated.ts +9 -0
- package/src/pseudo/optional.ts +18 -0
- package/src/pseudo/outdated.ts +305 -0
- package/src/pseudo/overridden.ts +20 -0
- package/src/pseudo/path.ts +146 -0
- package/src/pseudo/peer.ts +18 -0
- package/src/pseudo/prerelease.ts +47 -0
- package/src/pseudo/private.ts +19 -0
- package/src/pseudo/prod.ts +18 -0
- package/src/pseudo/published.ts +248 -0
- package/src/pseudo/registry.ts +29 -0
- package/src/pseudo/root.ts +19 -0
- package/src/pseudo/scanned.ts +20 -0
- package/src/pseudo/score.ts +186 -0
- package/src/pseudo/scripts.ts +54 -0
- package/src/pseudo/semver.ts +320 -0
- package/src/pseudo/severity.ts +231 -0
- package/src/pseudo/shell.ts +9 -0
- package/src/pseudo/shrinkwrap.ts +9 -0
- package/src/pseudo/spec.ts +131 -0
- package/src/pseudo/squat.ts +225 -0
- package/src/pseudo/suspicious.ts +9 -0
- package/src/pseudo/tracker.ts +9 -0
- package/src/pseudo/trivial.ts +9 -0
- package/src/pseudo/type.ts +26 -0
- package/src/pseudo/undesirable.ts +9 -0
- package/src/pseudo/unknown.ts +9 -0
- package/src/pseudo/unmaintained.ts +9 -0
- package/src/pseudo/unpopular.ts +9 -0
- package/src/pseudo/unstable.ts +9 -0
- package/src/pseudo/vuln.ts +273 -0
- package/src/pseudo/workspace.ts +22 -0
- package/src/pseudo.ts +413 -0
- package/src/types.ts +165 -0
- package/tap-snapshots/test/attribute.ts.test.cjs +304 -0
- package/tap-snapshots/test/combinator.ts.test.cjs +333 -0
- package/tap-snapshots/test/id.ts.test.cjs +118 -0
- package/tap-snapshots/test/parser.ts.test.cjs +344 -0
- package/tap-snapshots/test/pseudo/abandoned.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/attr.ts.test.cjs +161 -0
- package/tap-snapshots/test/pseudo/built.ts.test.cjs +70 -0
- package/tap-snapshots/test/pseudo/confused.ts.test.cjs +32 -0
- package/tap-snapshots/test/pseudo/cve.ts.test.cjs +49 -0
- package/tap-snapshots/test/pseudo/cwe.ts.test.cjs +49 -0
- package/tap-snapshots/test/pseudo/debug.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/deprecated.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/dist.ts.test.cjs +30 -0
- package/tap-snapshots/test/pseudo/dynamic.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/empty.ts.test.cjs +50 -0
- package/tap-snapshots/test/pseudo/entropic.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/env.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/eval.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/fs.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/helpers.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/hostname.ts.test.cjs +148 -0
- package/tap-snapshots/test/pseudo/license.ts.test.cjs +41 -0
- package/tap-snapshots/test/pseudo/link.ts.test.cjs +36 -0
- package/tap-snapshots/test/pseudo/malware.ts.test.cjs +22 -0
- package/tap-snapshots/test/pseudo/minified.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/missing.ts.test.cjs +30 -0
- package/tap-snapshots/test/pseudo/native.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/network.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/obfuscated.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/outdated.ts.test.cjs +130 -0
- package/tap-snapshots/test/pseudo/overridden.ts.test.cjs +75 -0
- package/tap-snapshots/test/pseudo/prerelease.ts.test.cjs +101 -0
- package/tap-snapshots/test/pseudo/private.ts.test.cjs +38 -0
- package/tap-snapshots/test/pseudo/published.ts.test.cjs +171 -0
- package/tap-snapshots/test/pseudo/registry.ts.test.cjs +68 -0
- package/tap-snapshots/test/pseudo/root.ts.test.cjs +24 -0
- package/tap-snapshots/test/pseudo/scanned.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/score.ts.test.cjs +239 -0
- package/tap-snapshots/test/pseudo/scripts.ts.test.cjs +61 -0
- package/tap-snapshots/test/pseudo/semver.ts.test.cjs +575 -0
- package/tap-snapshots/test/pseudo/severity.ts.test.cjs +95 -0
- package/tap-snapshots/test/pseudo/shell.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/shrinkwrap.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/spec.ts.test.cjs +148 -0
- package/tap-snapshots/test/pseudo/squat.ts.test.cjs +129 -0
- package/tap-snapshots/test/pseudo/suspicious.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/tracker.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/trivial.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/type.ts.test.cjs +51 -0
- package/tap-snapshots/test/pseudo/undesirable.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/unknown.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/unmaintained.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/unpopular.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/unstable.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/vuln.ts.test.cjs +208 -0
- package/tap-snapshots/test/pseudo/vulnerable.ts.test.cjs +20 -0
- package/tap-snapshots/test/pseudo/workspace.ts.test.cjs +19 -0
- package/tap-snapshots/test/pseudo.ts.test.cjs +1247 -0
- package/test/attribute.ts +266 -0
- package/test/combinator.ts +168 -0
- package/test/fixtures/graph.ts +999 -0
- package/test/fixtures/selector.ts +103 -0
- package/test/fixtures/types.ts +7 -0
- package/test/id.ts +102 -0
- package/test/index.ts +1000 -0
- package/test/parser.ts +117 -0
- package/test/pseudo/abandoned.ts +98 -0
- package/test/pseudo/attr.ts +298 -0
- package/test/pseudo/built.ts +214 -0
- package/test/pseudo/confused.ts +160 -0
- package/test/pseudo/cve.ts +249 -0
- package/test/pseudo/cwe.ts +255 -0
- package/test/pseudo/debug.ts +98 -0
- package/test/pseudo/deprecated.ts +98 -0
- package/test/pseudo/dev.ts +61 -0
- package/test/pseudo/diff.ts +417 -0
- package/test/pseudo/dist.ts +215 -0
- package/test/pseudo/dynamic.ts +98 -0
- package/test/pseudo/empty.ts +108 -0
- package/test/pseudo/entropic.ts +101 -0
- package/test/pseudo/env.ts +98 -0
- package/test/pseudo/eval.ts +98 -0
- package/test/pseudo/fs.ts +98 -0
- package/test/pseudo/helpers.ts +370 -0
- package/test/pseudo/host-context.ts +276 -0
- package/test/pseudo/hostname.ts +314 -0
- package/test/pseudo/license.ts +265 -0
- package/test/pseudo/link.ts +94 -0
- package/test/pseudo/malware.ts +184 -0
- package/test/pseudo/minified.ts +98 -0
- package/test/pseudo/missing.ts +111 -0
- package/test/pseudo/native.ts +98 -0
- package/test/pseudo/network.ts +98 -0
- package/test/pseudo/obfuscated.ts +98 -0
- package/test/pseudo/optional.ts +73 -0
- package/test/pseudo/outdated.ts +331 -0
- package/test/pseudo/overridden.ts +317 -0
- package/test/pseudo/path.ts +680 -0
- package/test/pseudo/peer.ts +101 -0
- package/test/pseudo/prerelease.ts +279 -0
- package/test/pseudo/private.ts +108 -0
- package/test/pseudo/prod.ts +61 -0
- package/test/pseudo/published.ts +557 -0
- package/test/pseudo/registry.ts +122 -0
- package/test/pseudo/root.ts +66 -0
- package/test/pseudo/scanned.ts +78 -0
- package/test/pseudo/score.ts +591 -0
- package/test/pseudo/scripts.ts +294 -0
- package/test/pseudo/semver.ts +822 -0
- package/test/pseudo/severity.ts +310 -0
- package/test/pseudo/shell.ts +98 -0
- package/test/pseudo/shrinkwrap.ts +98 -0
- package/test/pseudo/spec.ts +525 -0
- package/test/pseudo/squat.ts +565 -0
- package/test/pseudo/suspicious.ts +98 -0
- package/test/pseudo/tracker.ts +98 -0
- package/test/pseudo/trivial.ts +98 -0
- package/test/pseudo/type.ts +105 -0
- package/test/pseudo/undesirable.ts +98 -0
- package/test/pseudo/unknown.ts +98 -0
- package/test/pseudo/unmaintained.ts +98 -0
- package/test/pseudo/unpopular.ts +98 -0
- package/test/pseudo/unstable.ts +98 -0
- package/test/pseudo/vuln.ts +625 -0
- package/test/pseudo/vulnerable.ts +137 -0
- package/test/pseudo/workspace.ts +111 -0
- package/test/pseudo.ts +558 -0
- package/tsconfig.json +3 -0
- package/tsconfig.publish.json +19 -0
- package/tsconfig.publish.tsbuildinfo +1 -0
- package/typedoc.mjs +2 -0
- package/dist/pseudo/vulnerable.d.ts +0 -8
- package/dist/pseudo/vulnerable.js +0 -17
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { joinDepIDTuple } from '@vltpkg/dep-id'
|
|
2
|
+
import { parse } from '@vltpkg/dss-parser'
|
|
3
|
+
import { walk } from '../../src/index.ts'
|
|
4
|
+
import type { EdgeLike, GraphLike, NodeLike } from '@vltpkg/types'
|
|
5
|
+
import type { DepID } from '@vltpkg/dep-id'
|
|
6
|
+
import type { PostcssNode } from '@vltpkg/dss-parser'
|
|
7
|
+
import type {
|
|
8
|
+
GraphSelectionState,
|
|
9
|
+
ParserState,
|
|
10
|
+
ParserFn,
|
|
11
|
+
} from '../../src/types.ts'
|
|
12
|
+
|
|
13
|
+
export type FixtureResult = {
|
|
14
|
+
edges: EdgeLike[]
|
|
15
|
+
nodes: NodeLike[]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const copyGraphSelectionState = (
|
|
19
|
+
gss: GraphSelectionState,
|
|
20
|
+
): GraphSelectionState => ({
|
|
21
|
+
edges: new Set(gss.edges),
|
|
22
|
+
nodes: new Set(gss.nodes),
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
export const getGraphSelectionState = (
|
|
26
|
+
graph: GraphLike,
|
|
27
|
+
name: string,
|
|
28
|
+
): GraphSelectionState => {
|
|
29
|
+
const nodes = new Set<NodeLike>([
|
|
30
|
+
graph.nodes.get(
|
|
31
|
+
joinDepIDTuple(['registry', '', `${name}@1.0.0`]),
|
|
32
|
+
)!,
|
|
33
|
+
])
|
|
34
|
+
const edges = new Set<EdgeLike>()
|
|
35
|
+
for (const edge of graph.edges) {
|
|
36
|
+
if (edge.name === name) edges.add(edge)
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
edges,
|
|
40
|
+
nodes,
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Creates a {@link ParserState} state object and runs the provided `testFn`
|
|
46
|
+
* using that, returns an array of the resulting {@link NodeLike} nodes.
|
|
47
|
+
*/
|
|
48
|
+
export const selectorFixture =
|
|
49
|
+
(testFn: ParserFn) =>
|
|
50
|
+
async (
|
|
51
|
+
query: { value: string; type: string } | string,
|
|
52
|
+
initial?: GraphSelectionState,
|
|
53
|
+
partial?: GraphSelectionState,
|
|
54
|
+
loose?: boolean,
|
|
55
|
+
scopeIDs?: DepID[],
|
|
56
|
+
): Promise<FixtureResult> => {
|
|
57
|
+
initial ??= {
|
|
58
|
+
edges: new Set(),
|
|
59
|
+
nodes: new Set(),
|
|
60
|
+
}
|
|
61
|
+
partial ??= {
|
|
62
|
+
edges: new Set(),
|
|
63
|
+
nodes: new Set(),
|
|
64
|
+
}
|
|
65
|
+
scopeIDs ??= [joinDepIDTuple(['file', '.'])]
|
|
66
|
+
let current: PostcssNode
|
|
67
|
+
if (typeof query === 'string') {
|
|
68
|
+
const ast = parse(query)
|
|
69
|
+
// if the testing function handles a fully parsed
|
|
70
|
+
// css ast then just use that instead
|
|
71
|
+
current =
|
|
72
|
+
testFn === walk ? ast : (
|
|
73
|
+
(ast.nodes[0]?.nodes[0] as PostcssNode)
|
|
74
|
+
)
|
|
75
|
+
} else {
|
|
76
|
+
current = query as PostcssNode
|
|
77
|
+
}
|
|
78
|
+
const state: ParserState = {
|
|
79
|
+
cancellable: async () => {},
|
|
80
|
+
collect: {
|
|
81
|
+
edges: new Set(),
|
|
82
|
+
nodes: new Set(),
|
|
83
|
+
},
|
|
84
|
+
comment: '',
|
|
85
|
+
current,
|
|
86
|
+
loose,
|
|
87
|
+
initial,
|
|
88
|
+
partial,
|
|
89
|
+
importers: new Set<NodeLike>(),
|
|
90
|
+
hostContexts: undefined,
|
|
91
|
+
walk,
|
|
92
|
+
retries: 0,
|
|
93
|
+
scopeIDs,
|
|
94
|
+
securityArchive: undefined,
|
|
95
|
+
signal: new AbortController().signal,
|
|
96
|
+
specificity: { idCounter: 0, commonCounter: 0 },
|
|
97
|
+
}
|
|
98
|
+
const res = await testFn(state)
|
|
99
|
+
return {
|
|
100
|
+
edges: [...res.partial.edges],
|
|
101
|
+
nodes: [...res.partial.nodes],
|
|
102
|
+
}
|
|
103
|
+
}
|
package/test/id.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import t from 'tap'
|
|
2
|
+
import { id } from '../src/id.ts'
|
|
3
|
+
import { getAliasedGraph, getSimpleGraph } from './fixtures/graph.ts'
|
|
4
|
+
import {
|
|
5
|
+
copyGraphSelectionState,
|
|
6
|
+
getGraphSelectionState,
|
|
7
|
+
selectorFixture,
|
|
8
|
+
} from './fixtures/selector.ts'
|
|
9
|
+
import type { TestCase } from './fixtures/types.ts'
|
|
10
|
+
import type { GraphSelectionState } from '../src/types.ts'
|
|
11
|
+
import type { EdgeLike, NodeLike } from '@vltpkg/types'
|
|
12
|
+
|
|
13
|
+
const testId = selectorFixture(id)
|
|
14
|
+
|
|
15
|
+
t.test('id', async t => {
|
|
16
|
+
const simpleGraph = getSimpleGraph()
|
|
17
|
+
const all: GraphSelectionState = {
|
|
18
|
+
edges: new Set<EdgeLike>(simpleGraph.edges),
|
|
19
|
+
nodes: new Set<NodeLike>(simpleGraph.nodes.values()),
|
|
20
|
+
}
|
|
21
|
+
const b = getGraphSelectionState(simpleGraph, 'b')
|
|
22
|
+
const empty: GraphSelectionState = {
|
|
23
|
+
edges: new Set(),
|
|
24
|
+
nodes: new Set(),
|
|
25
|
+
}
|
|
26
|
+
const queryToExpected = new Set<TestCase>([
|
|
27
|
+
['#my-project', all, ['my-project']], // select root node
|
|
28
|
+
['#a', all, ['a']], // direct dep
|
|
29
|
+
['#f', all, ['f']], // transitive dep
|
|
30
|
+
['#a', b, []], // missing from partial
|
|
31
|
+
['#b', b, ['b']], // exact match from partial
|
|
32
|
+
['#a', empty, []], // no partial
|
|
33
|
+
])
|
|
34
|
+
const initial = copyGraphSelectionState(all)
|
|
35
|
+
for (const [query, partial, expected] of queryToExpected) {
|
|
36
|
+
const res = await testId(
|
|
37
|
+
query,
|
|
38
|
+
initial,
|
|
39
|
+
copyGraphSelectionState(partial),
|
|
40
|
+
)
|
|
41
|
+
t.strictSame(
|
|
42
|
+
res.nodes.map(i => i.name),
|
|
43
|
+
expected,
|
|
44
|
+
`query > "${query}"`,
|
|
45
|
+
)
|
|
46
|
+
t.matchSnapshot(
|
|
47
|
+
{
|
|
48
|
+
edges: res.edges.map(i => i.name).sort(),
|
|
49
|
+
nodes: res.nodes.map(i => i.name).sort(),
|
|
50
|
+
},
|
|
51
|
+
`query > "${query}"`,
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
await t.test('aliased graph', async t => {
|
|
56
|
+
const aliasedGraph = getAliasedGraph()
|
|
57
|
+
const all: GraphSelectionState = {
|
|
58
|
+
edges: new Set<EdgeLike>(aliasedGraph.edges),
|
|
59
|
+
nodes: new Set<NodeLike>(aliasedGraph.nodes.values()),
|
|
60
|
+
}
|
|
61
|
+
const empty: GraphSelectionState = {
|
|
62
|
+
edges: new Set(),
|
|
63
|
+
nodes: new Set(),
|
|
64
|
+
}
|
|
65
|
+
const queryToExpected = new Set<TestCase>([
|
|
66
|
+
['#aliased-project', all, ['aliased-project']], // select root node
|
|
67
|
+
['#a', all, ['a']], // regular direct dep
|
|
68
|
+
['#b', all, ['foo']], // select aliased dep by its dep name alias
|
|
69
|
+
['#foo', all, []], // do not select aliased dep by its pkg name
|
|
70
|
+
['#bar', all, ['d']], // select transitive aliased dep by its alias
|
|
71
|
+
['#a', empty, []], // no partial
|
|
72
|
+
])
|
|
73
|
+
const initial = copyGraphSelectionState(all)
|
|
74
|
+
for (const [query, partial, expected] of queryToExpected) {
|
|
75
|
+
const res = await testId(
|
|
76
|
+
query,
|
|
77
|
+
initial,
|
|
78
|
+
copyGraphSelectionState(partial),
|
|
79
|
+
)
|
|
80
|
+
t.strictSame(
|
|
81
|
+
res.nodes.map(i => i.name),
|
|
82
|
+
expected,
|
|
83
|
+
`query > "${query}"`,
|
|
84
|
+
)
|
|
85
|
+
t.matchSnapshot(
|
|
86
|
+
{
|
|
87
|
+
edges: res.edges.map(i => i.name).sort(),
|
|
88
|
+
nodes: res.nodes.map(i => i.name).sort(),
|
|
89
|
+
},
|
|
90
|
+
`query > "${query}"`,
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
t.test('bad selector type', async t => {
|
|
97
|
+
await t.rejects(
|
|
98
|
+
testId(':foo'),
|
|
99
|
+
/Mismatching query node/,
|
|
100
|
+
'should throw an error',
|
|
101
|
+
)
|
|
102
|
+
})
|