@vltpkg/query 0.0.0-6 → 0.0.0-7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -174,6 +174,13 @@ security data needs to be fetched prior to a `Query` instantiation.
174
174
  - `:confused` Matches packages affected by manifest confusion. This
175
175
  could be malicious or caused by an error when publishing the
176
176
  package.
177
+ - `:cve(<id>)` Matches packages that have a CVE alert with the
178
+ specified CVE ID. The ID parameter is required and should be a valid
179
+ CVE identifier (e.g., `CVE-2023-1234`). This selector can be used to
180
+ find packages affected by specific known vulnerabilities.
181
+ - `:cwe(<id>)` Matches packages that have a CWE alert with the
182
+ specified CWE ID. The ID parameter is required and should be a valid
183
+ CWE identifier (e.g., `CWE-79`).
177
184
  - `:debug` Matches packages that use debug, reflection and dynamic
178
185
  code execution features.
179
186
  - `:deprecated` Matches packages marked as deprecated. This could
@@ -192,9 +199,25 @@ security data needs to be fetched prior to a `Query` instantiation.
192
199
  code may contain exploits or malicious behavior.
193
200
  - `:fs` Matches packages that accesses the file system, and could
194
201
  potentially read sensitive data.
195
- - `:obfuscated` Matches packages that use obfuscated files,
196
- intentionally packed to hide their behavior. This could be a sign of
197
- malware.
202
+ - `:license(<type>)` Matches packages based on different potential
203
+ license issues:
204
+ - `:license(unlicensed)` Matches packages with no license.
205
+ - `:license(misc)` Matches packages with fine-grained problems.
206
+ - `:license(restricted)` Matches packages with a license that is not
207
+ permissive.
208
+ - `:license(ambiguous)` Matches packages with ambiguous licensing.
209
+ - `:license(copyleft)` Matches packages with a copyleft license.
210
+ - `:license(unknown)` Matches packages that have potential license
211
+ data but its type could not be determined.
212
+ - `:license(none)` Matches packages that have no license data.
213
+ - `:license(exception)` Matches packages that have SPDX license
214
+ exception.
215
+ - `:malware(<type>)` Matches packages that may contain malware. The
216
+ type parameter is required and can be one of the following:
217
+ - `critical` or `0`
218
+ - `high` or `1`
219
+ - `medium` or `2`
220
+ - `low` or `3`
198
221
  - `:minified` Matches packages that contain minified code. This may be
199
222
  harmless in some cases where minified code is included in packaged
200
223
  libraries.
@@ -202,13 +225,28 @@ security data needs to be fetched prior to a `Query` instantiation.
202
225
  binaries or shared libraries). Including native code can obscure
203
226
  malicious behavior.
204
227
  - `:network` Matches packages that access the network.
228
+ - `:obfuscated` Matches packages that use obfuscated files,
229
+ intentionally packed to hide their behavior. This could be a sign of
230
+ malware.
205
231
  - `:scripts` Matches packages that have scripts that are run when the
206
232
  package is installed. The majority of malware in npm is hidden in
207
233
  install scripts.
234
+ - `:severity` Matches packages based of the severity level of any
235
+ attached CVE. The type paremeter is required and can be one of the
236
+ following:
237
+ - `critical` or `0`
238
+ - `high` or `1`
239
+ - `medium` or `2`
240
+ - `low` or `3`
208
241
  - `:shell` Matches packages that accesses the system shell. Accessing
209
242
  the system shell increases the risk of executing arbitrary code.
210
243
  - `:shrinkwrap` Matches packages that contains a shrinkwrap file. This
211
244
  may allow the package to bypass normal install procedures.
245
+ - `:squat(<type>)` Matches packages with names similar to other
246
+ popular packages and may not be the package you want. The type
247
+ parameter is required and can be one of the following:
248
+ - `critical` or `0`
249
+ - `medium` or `2`
212
250
  - `:suspicious` Matches packages that may have its GitHub repository
213
251
  artificially inflated with stars (from bots, crowdsourcing, etc.).
214
252
  - `:tracker` Matches packages that contains telemetry which tracks how
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAY,SAAS,EAAY,MAAM,eAAe,CAAA;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAYnE,OAAO,KAAK,EAEV,WAAW,EAEX,aAAa,EACd,MAAM,YAAY,CAAA;AAEnB,cAAc,YAAY,CAAA;AAiC1B,eAAO,MAAM,IAAI,UACR,WAAW,KACjB,OAAO,CAAC,WAAW,CAmDrB,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C,aAAa,CAAC;CAmD1B"}
package/dist/esm/index.js CHANGED
@@ -79,6 +79,7 @@ export const walk = async (state) => {
79
79
  const securitySelectors = new Set([
80
80
  ':abandoned',
81
81
  ':confused',
82
+ ':cve',
82
83
  ':debug',
83
84
  ':deprecated',
84
85
  ':dynamic',
@@ -86,13 +87,18 @@ const securitySelectors = new Set([
86
87
  ':env',
87
88
  ':eval',
88
89
  ':fs',
89
- ':obfuscated',
90
+ ':license',
91
+ ':malware',
90
92
  ':minified',
91
93
  ':native',
92
94
  ':network',
95
+ ':obfuscated',
93
96
  ':scripts',
97
+ ':sev',
98
+ ':severity',
94
99
  ':shell',
95
100
  ':shrinkwrap',
101
+ ':squat',
96
102
  ':suspicious',
97
103
  ':tracker',
98
104
  ':trivial',
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAI3C,OAAO,qBAAqB,MAAM,yBAAyB,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,cAAc,GACf,MAAM,YAAY,CAAA;AAQnB,cAAc,YAAY,CAAA;AAE1B,MAAM,MAAM,GAAG,KAAK,EAAE,KAAkB,EAAE,EAAE,CAAC,KAAK,CAAA;AAElD,MAAM,SAAS,GAAG;IAChB,SAAS;IACT,KAAK,EAAE,OAAO;IACd,UAAU;IACV,OAAO,EAAE,MAAM;IACf,EAAE;IACF,OAAO,EAAE,MAAM;IACf,MAAM;IACN,IAAI,EAAE,MAAM;I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K,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;YAChC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;SACjC,CAAA;QACD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;QAC3B,OAAO,GAAG,CAAA;IACZ,CAAC;CACF","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport type { EdgeLike, GraphLike, NodeLike } from '@vltpkg/graph'\nimport type { SpecOptions } from '@vltpkg/spec/browser'\nimport type { SecurityArchiveLike } from '@vltpkg/security-archive'\nimport postcssSelectorParser from 'postcss-selector-parser'\nimport { attribute } from './attribute.ts'\nimport { classFn } from './class.ts'\nimport { combinator } from './combinator.ts'\nimport { id } from './id.ts'\nimport { pseudo } from './pseudo.ts'\nimport {\n isPostcssNodeWithChildren,\n asPostcssNodeWithChildren,\n isSelectorNode,\n} from './types.ts'\nimport type {\n PostcssNodeWithChildren,\n ParserState,\n ParserFn,\n QueryResponse,\n} from './types.ts'\n\nexport * from './types.ts'\n\nconst noopFn = async (state: ParserState) => state\n\nconst selectors = {\n attribute,\n class: classFn,\n combinator,\n comment: noopFn,\n id,\n nesting: noopFn,\n pseudo,\n root: noopFn,\n selector: async (state: ParserState) => {\n state.partial.nodes = new Set(state.initial.nodes)\n state.partial.edges = new Set(state.initial.edges)\n return state\n },\n string: async (state: ParserState) => {\n throw error('Unsupported selector', { found: state.current })\n },\n tag: async (state: ParserState) => {\n if (state.current.value !== '{' && state.current.value !== '}') {\n throw error('Unsupported selector', { found: state.current })\n }\n return state\n },\n universal: noopFn,\n}\nconst selectorsMap = new Map<string, ParserFn>(\n Object.entries(selectors),\n)\n\nexport const walk = async (\n state: ParserState,\n): Promise<ParserState> => {\n await state.cancellable()\n\n const parserFn = selectorsMap.get(state.current.type)\n\n if (!parserFn) {\n if (state.loose) {\n return state\n }\n\n throw new Error(\n `Missing parser for query node: ${state.current.type}`,\n )\n }\n state = await parserFn(state)\n\n // pseudo selectors handle their own sub selectors\n if (\n isPostcssNodeWithChildren(state.current) &&\n state.current.type !== 'pseudo'\n ) {\n const node: PostcssNodeWithChildren = asPostcssNodeWithChildren(\n state.current,\n )\n\n if (node.nodes.length) {\n for (let i = 0; i < node.nodes.length; i++) {\n const current = node.nodes[i]\n /* c8 ignore next -- impossible but TS doesn't know that */\n if (!current) continue\n\n const childState: ParserState = {\n ...state,\n current,\n next: node.nodes[i + 1],\n prev: node.nodes[i - 1],\n }\n state = await walk(childState)\n }\n }\n\n if (isSelectorNode(node)) {\n for (const edge of state.partial.edges) {\n state.collect.edges.add(edge)\n }\n for (const node of state.partial.nodes) {\n state.collect.nodes.add(node)\n }\n }\n }\n return state\n}\n\nexport type QueryOptions = {\n graph: GraphLike\n specOptions: SpecOptions\n securityArchive: SecurityArchiveLike | undefined\n}\n\n// A list of known security selectors that rely on\n// data from the security-archive in order to work\nconst securitySelectors = new Set([\n ':abandoned',\n ':confused',\n ':debug',\n ':deprecated',\n ':dynamic',\n ':entropic',\n ':env',\n ':eval',\n ':fs',\n ':obfuscated',\n ':minified',\n ':native',\n ':network',\n ':scripts',\n ':shell',\n ':shrinkwrap',\n ':suspicious',\n ':tracker',\n ':trivial',\n ':undesirable',\n ':unknown',\n ':unmaintained',\n ':unpopular',\n ':unstable',\n])\n\nexport class Query {\n #cache: Map<string, QueryResponse>\n #graph: GraphLike\n #specOptions: SpecOptions\n #securityArchive: SecurityArchiveLike | undefined\n\n /**\n * Helper method to determine if a given query string is using any of\n * the known security selectors. This is useful so that operations can\n * skip hydrating the security archive if it's not needed.\n */\n static hasSecuritySelectors(query: string): boolean {\n for (const selector of securitySelectors) {\n if (query.includes(selector)) {\n return true\n }\n }\n return false\n }\n\n constructor({ graph, specOptions, securityArchive }: QueryOptions) {\n this.#cache = new Map()\n this.#graph = graph\n this.#specOptions = specOptions\n this.#securityArchive = securityArchive\n }\n\n /**\n * Search the graph for nodes and edges that match the given query.\n */\n async search(\n query: string,\n signal?: AbortSignal,\n ): Promise<QueryResponse> {\n if (typeof query !== 'string') {\n throw new TypeError(\n 'Query search argument needs to be a string',\n )\n }\n\n if (!query) return { edges: [], nodes: [] }\n\n const cachedResult = this.#cache.get(query)\n if (cachedResult) {\n return cachedResult\n }\n\n const nodes = new Set<NodeLike>(\n Array.from(this.#graph.nodes.values()),\n )\n const edges = new Set<EdgeLike>(Array.from(this.#graph.edges))\n\n // builds initial state and walks over it,\n // retrieving the collected result\n const { collect } = await walk({\n cancellable: async () => {\n await new Promise(resolve => {\n setTimeout(resolve, 0)\n })\n signal?.throwIfAborted()\n },\n current: postcssSelectorParser().astSync(query),\n initial: {\n nodes: new Set(nodes),\n edges: new Set(edges),\n },\n collect: {\n nodes: new Set<NodeLike>(),\n edges: new Set<EdgeLike>(),\n },\n partial: { nodes, edges },\n signal,\n securityArchive: this.#securityArchive,\n specOptions: this.#specOptions,\n walk,\n })\n\n const res: QueryResponse = {\n edges: Array.from(collect.edges),\n nodes: Array.from(collect.nodes),\n }\n this.#cache.set(query, res)\n return res\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAI3C,OAAO,qBAAqB,MAAM,yBAAyB,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,cAAc,GACf,MAAM,YAAY,CAAA;AAQnB,cAAc,YAAY,CAAA;AAE1B,MAAM,MAAM,GAAG,KAAK,EAAE,KAAkB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AI,GAAG,EAAY;gBAC1B,KAAK,EAAE,IAAI,GAAG,EAAY;aAC3B;YACD,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE;YACzB,MAAM;YACN,eAAe,EAAE,IAAI,CAAC,gBAAgB;YACtC,WAAW,EAAE,IAAI,CAAC,YAAY;YAC9B,IAAI;SACL,CAAC,CAAA;QAEF,MAAM,GAAG,GAAkB;YACzB,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;YAChC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;SACjC,CAAA;QACD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;QAC3B,OAAO,GAAG,CAAA;IACZ,CAAC;CACF","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport type { EdgeLike, GraphLike, NodeLike } from '@vltpkg/graph'\nimport type { SpecOptions } from '@vltpkg/spec/browser'\nimport type { SecurityArchiveLike } from '@vltpkg/security-archive'\nimport postcssSelectorParser from 'postcss-selector-parser'\nimport { attribute } from './attribute.ts'\nimport { classFn } from './class.ts'\nimport { combinator } from './combinator.ts'\nimport { id } from './id.ts'\nimport { pseudo } from './pseudo.ts'\nimport {\n isPostcssNodeWithChildren,\n asPostcssNodeWithChildren,\n isSelectorNode,\n} from './types.ts'\nimport type {\n PostcssNodeWithChildren,\n ParserState,\n ParserFn,\n QueryResponse,\n} from './types.ts'\n\nexport * from './types.ts'\n\nconst noopFn = async (state: ParserState) => state\n\nconst selectors = {\n attribute,\n class: classFn,\n combinator,\n comment: noopFn,\n id,\n nesting: noopFn,\n pseudo,\n root: noopFn,\n selector: async (state: ParserState) => {\n state.partial.nodes = new Set(state.initial.nodes)\n state.partial.edges = new Set(state.initial.edges)\n return state\n },\n string: async (state: ParserState) => {\n throw error('Unsupported selector', { found: state.current })\n },\n tag: async (state: ParserState) => {\n if (state.current.value !== '{' && state.current.value !== '}') {\n throw error('Unsupported selector', { found: state.current })\n }\n return state\n },\n universal: noopFn,\n}\nconst selectorsMap = new Map<string, ParserFn>(\n Object.entries(selectors),\n)\n\nexport const walk = async (\n state: ParserState,\n): Promise<ParserState> => {\n await state.cancellable()\n\n const parserFn = selectorsMap.get(state.current.type)\n\n if (!parserFn) {\n if (state.loose) {\n return state\n }\n\n throw new Error(\n `Missing parser for query node: ${state.current.type}`,\n )\n }\n state = await parserFn(state)\n\n // pseudo selectors handle their own sub selectors\n if (\n isPostcssNodeWithChildren(state.current) &&\n state.current.type !== 'pseudo'\n ) {\n const node: PostcssNodeWithChildren = asPostcssNodeWithChildren(\n state.current,\n )\n\n if (node.nodes.length) {\n for (let i = 0; i < node.nodes.length; i++) {\n const current = node.nodes[i]\n /* c8 ignore next -- impossible but TS doesn't know that */\n if (!current) continue\n\n const childState: ParserState = {\n ...state,\n current,\n next: node.nodes[i + 1],\n prev: node.nodes[i - 1],\n }\n state = await walk(childState)\n }\n }\n\n if (isSelectorNode(node)) {\n for (const edge of state.partial.edges) {\n state.collect.edges.add(edge)\n }\n for (const node of state.partial.nodes) {\n state.collect.nodes.add(node)\n }\n }\n }\n return state\n}\n\nexport type QueryOptions = {\n graph: GraphLike\n specOptions: SpecOptions\n securityArchive: SecurityArchiveLike | undefined\n}\n\n// A list of known security selectors that rely on\n// data from the security-archive in order to work\nconst securitySelectors = new Set([\n ':abandoned',\n ':confused',\n ':cve',\n ':debug',\n ':deprecated',\n ':dynamic',\n ':entropic',\n ':env',\n ':eval',\n ':fs',\n ':license',\n ':malware',\n ':minified',\n ':native',\n ':network',\n ':obfuscated',\n ':scripts',\n ':sev',\n ':severity',\n ':shell',\n ':shrinkwrap',\n ':squat',\n ':suspicious',\n ':tracker',\n ':trivial',\n ':undesirable',\n ':unknown',\n ':unmaintained',\n ':unpopular',\n ':unstable',\n])\n\nexport class Query {\n #cache: Map<string, QueryResponse>\n #graph: GraphLike\n #specOptions: SpecOptions\n #securityArchive: SecurityArchiveLike | undefined\n\n /**\n * Helper method to determine if a given query string is using any of\n * the known security selectors. This is useful so that operations can\n * skip hydrating the security archive if it's not needed.\n */\n static hasSecuritySelectors(query: string): boolean {\n for (const selector of securitySelectors) {\n if (query.includes(selector)) {\n return true\n }\n }\n return false\n }\n\n constructor({ graph, specOptions, securityArchive }: QueryOptions) {\n this.#cache = new Map()\n this.#graph = graph\n this.#specOptions = specOptions\n this.#securityArchive = securityArchive\n }\n\n /**\n * Search the graph for nodes and edges that match the given query.\n */\n async search(\n query: string,\n signal?: AbortSignal,\n ): Promise<QueryResponse> {\n if (typeof query !== 'string') {\n throw new TypeError(\n 'Query search argument needs to be a string',\n )\n }\n\n if (!query) return { edges: [], nodes: [] }\n\n const cachedResult = this.#cache.get(query)\n if (cachedResult) {\n return cachedResult\n }\n\n const nodes = new Set<NodeLike>(\n Array.from(this.#graph.nodes.values()),\n )\n const edges = new Set<EdgeLike>(Array.from(this.#graph.edges))\n\n // builds initial state and walks over it,\n // retrieving the collected result\n const { collect } = await walk({\n cancellable: async () => {\n await new Promise(resolve => {\n setTimeout(resolve, 0)\n })\n signal?.throwIfAborted()\n },\n current: postcssSelectorParser().astSync(query),\n initial: {\n nodes: new Set(nodes),\n edges: new Set(edges),\n },\n collect: {\n nodes: new Set<NodeLike>(),\n edges: new Set<EdgeLike>(),\n },\n partial: { nodes, edges },\n signal,\n securityArchive: this.#securityArchive,\n specOptions: this.#specOptions,\n walk,\n })\n\n const res: QueryResponse = {\n edges: Array.from(collect.edges),\n nodes: Array.from(collect.nodes),\n }\n this.#cache.set(query, res)\n return res\n }\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import type { ParserState, PostcssNode } from '../types.ts';
2
+ export type CveInternals = {
3
+ cveId: string;
4
+ };
5
+ export declare const parseInternals: (nodes: PostcssNode[]) => CveInternals;
6
+ /**
7
+ * Filters out any node that does not have a CVE alert with the specified CVE ID.
8
+ */
9
+ export declare const cve: (state: ParserState) => Promise<ParserState>;
10
+ //# sourceMappingURL=cve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cve.d.ts","sourceRoot":"","sources":["../../../src/pseudo/cve.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAO3D,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,eAAO,MAAM,cAAc,UAClB,WAAW,EAAE,KACnB,YAuBF,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,GAAG,UAAiB,WAAW,yBAiC3C,CAAA"}
@@ -0,0 +1,47 @@
1
+ import { error } from '@vltpkg/error-cause';
2
+ import { asPostcssNodeWithChildren, asStringNode, asTagNode, isStringNode, isTagNode, } from "../types.js";
3
+ import { removeDanglingEdges, removeNode, removeQuotes, } from "./helpers.js";
4
+ export const parseInternals = (nodes) => {
5
+ let cveId = '';
6
+ if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
7
+ cveId = removeQuotes(asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])
8
+ .value);
9
+ }
10
+ else if (isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
11
+ cveId = asTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0]).value;
12
+ }
13
+ if (!cveId) {
14
+ throw error('Expected a CVE ID', {
15
+ found: asPostcssNodeWithChildren(nodes[0]).nodes[0],
16
+ });
17
+ }
18
+ return { cveId };
19
+ };
20
+ /**
21
+ * Filters out any node that does not have a CVE alert with the specified CVE ID.
22
+ */
23
+ export const cve = async (state) => {
24
+ if (!state.securityArchive) {
25
+ throw new Error('Missing security archive while trying to parse ' +
26
+ 'the :cve security selector');
27
+ }
28
+ let internals;
29
+ try {
30
+ internals = parseInternals(asPostcssNodeWithChildren(state.current).nodes);
31
+ }
32
+ catch (err) {
33
+ throw error('Failed to parse :cve selector', { cause: err });
34
+ }
35
+ const { cveId } = internals;
36
+ for (const node of state.partial.nodes) {
37
+ const report = state.securityArchive.get(node.id);
38
+ const exclude = !report?.alerts.some(alert => alert.props.cveId.trim().toLowerCase() ===
39
+ cveId.trim().toLowerCase());
40
+ if (exclude) {
41
+ removeNode(state, node);
42
+ }
43
+ }
44
+ removeDanglingEdges(state);
45
+ return state;
46
+ };
47
+ //# sourceMappingURL=cve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cve.js","sourceRoot":"","sources":["../../../src/pseudo/cve.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,aAAa,CAAA;AAEpB,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,YAAY,GACb,MAAM,cAAc,CAAA;AAMrB,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,KAAoB,EACN,EAAE;IAChB,IAAI,KAAK,GAAG,EAAE,CAAA;IAEd,IAAI,YAAY,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/D,KAAK,GAAG,YAAY,CAClB,YAAY,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;aACvD,KAAK,CACT,CAAA;IACH,CAAC;SAAM,IACL,SAAS,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EACvD,CAAC;QACD,KAAK,GAAG,SAAS,CACf,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAC7C,CAAC,KAAK,CAAA;IACT,CAAC;IAED,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,KAAK,CAAC,mBAAmB,EAAE;YAC/B,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ACd,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport {\n asPostcssNodeWithChildren,\n asStringNode,\n asTagNode,\n isStringNode,\n isTagNode,\n} from '../types.ts'\nimport type { ParserState, PostcssNode } from '../types.ts'\nimport {\n removeDanglingEdges,\n removeNode,\n removeQuotes,\n} from './helpers.ts'\n\nexport type CveInternals = {\n cveId: string\n}\n\nexport const parseInternals = (\n nodes: PostcssNode[],\n): CveInternals => {\n let cveId = ''\n\n if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {\n cveId = removeQuotes(\n asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n .value,\n )\n } else if (\n isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n ) {\n cveId = asTagNode(\n asPostcssNodeWithChildren(nodes[0]).nodes[0],\n ).value\n }\n\n if (!cveId) {\n throw error('Expected a CVE ID', {\n found: asPostcssNodeWithChildren(nodes[0]).nodes[0],\n })\n }\n\n return { cveId }\n}\n\n/**\n * Filters out any node that does not have a CVE alert with the specified CVE ID.\n */\nexport const cve = async (state: ParserState) => {\n if (!state.securityArchive) {\n throw new Error(\n 'Missing security archive while trying to parse ' +\n 'the :cve security selector',\n )\n }\n\n let internals\n try {\n internals = parseInternals(\n asPostcssNodeWithChildren(state.current).nodes,\n )\n } catch (err) {\n throw error('Failed to parse :cve selector', { cause: err })\n }\n\n const { cveId } = internals\n for (const node of state.partial.nodes) {\n const report = state.securityArchive.get(node.id)\n const exclude = !report?.alerts.some(\n alert =>\n alert.props.cveId.trim().toLowerCase() ===\n cveId.trim().toLowerCase(),\n )\n if (exclude) {\n removeNode(state, node)\n }\n }\n\n removeDanglingEdges(state)\n\n return state\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import type { ParserState, PostcssNode } from '../types.ts';
2
+ export type CweInternals = {
3
+ cweId: string;
4
+ };
5
+ export declare const parseInternals: (nodes: PostcssNode[]) => CweInternals;
6
+ /**
7
+ * Filters out any node that does not have a CWE alert with the specified CWE ID.
8
+ */
9
+ export declare const cwe: (state: ParserState) => Promise<ParserState>;
10
+ //# sourceMappingURL=cwe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cwe.d.ts","sourceRoot":"","sources":["../../../src/pseudo/cwe.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAO3D,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,eAAO,MAAM,cAAc,UAClB,WAAW,EAAE,KACnB,YAuBF,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,GAAG,UAAiB,WAAW,yBAkC3C,CAAA"}
@@ -0,0 +1,46 @@
1
+ import { error } from '@vltpkg/error-cause';
2
+ import { asPostcssNodeWithChildren, asStringNode, asTagNode, isStringNode, isTagNode, } from "../types.js";
3
+ import { removeDanglingEdges, removeNode, removeQuotes, } from "./helpers.js";
4
+ export const parseInternals = (nodes) => {
5
+ let cweId = '';
6
+ if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
7
+ cweId = removeQuotes(asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])
8
+ .value);
9
+ }
10
+ else if (isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
11
+ cweId = asTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0]).value;
12
+ }
13
+ if (!cweId) {
14
+ throw error('Expected a CWE ID', {
15
+ found: asPostcssNodeWithChildren(nodes[0]).nodes[0],
16
+ });
17
+ }
18
+ return { cweId };
19
+ };
20
+ /**
21
+ * Filters out any node that does not have a CWE alert with the specified CWE ID.
22
+ */
23
+ export const cwe = async (state) => {
24
+ if (!state.securityArchive) {
25
+ throw new Error('Missing security archive while trying to parse ' +
26
+ 'the :cwe security selector');
27
+ }
28
+ let internals;
29
+ try {
30
+ internals = parseInternals(asPostcssNodeWithChildren(state.current).nodes);
31
+ }
32
+ catch (err) {
33
+ throw error('Failed to parse :cwe selector', { cause: err });
34
+ }
35
+ const { cweId } = internals;
36
+ for (const node of state.partial.nodes) {
37
+ const report = state.securityArchive.get(node.id);
38
+ const exclude = !report?.alerts.some(alert => alert.props.cwes.some(cwe => cwe.id.trim().toLowerCase() === cweId.trim().toLowerCase()));
39
+ if (exclude) {
40
+ removeNode(state, node);
41
+ }
42
+ }
43
+ removeDanglingEdges(state);
44
+ return state;
45
+ };
46
+ //# sourceMappingURL=cwe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cwe.js","sourceRoot":"","sources":["../../../src/pseudo/cwe.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,aAAa,CAAA;AAEpB,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,YAAY,GACb,MAAM,cAAc,CAAA;AAMrB,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,KAAoB,EACN,EAAE;IAChB,IAAI,KAAK,GAAG,EAAE,CAAA;IAEd,IAAI,YAAY,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/D,KAAK,GAAG,YAAY,CAClB,YAAY,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;aACvD,KAAK,CACT,CAAA;IACH,CAAC;SAAM,IACL,SAAS,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EACvD,CAAC;QACD,KAAK,GAAG,SAAS,CACf,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAC7C,CAAC,KAA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A;QACD,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 {\n asPostcssNodeWithChildren,\n asStringNode,\n asTagNode,\n isStringNode,\n isTagNode,\n} from '../types.ts'\nimport type { ParserState, PostcssNode } from '../types.ts'\nimport {\n removeDanglingEdges,\n removeNode,\n removeQuotes,\n} from './helpers.ts'\n\nexport type CweInternals = {\n cweId: string\n}\n\nexport const parseInternals = (\n nodes: PostcssNode[],\n): CweInternals => {\n let cweId = ''\n\n if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {\n cweId = removeQuotes(\n asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n .value,\n )\n } else if (\n isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n ) {\n cweId = asTagNode(\n asPostcssNodeWithChildren(nodes[0]).nodes[0],\n ).value\n }\n\n if (!cweId) {\n throw error('Expected a CWE ID', {\n found: asPostcssNodeWithChildren(nodes[0]).nodes[0],\n })\n }\n\n return { cweId }\n}\n\n/**\n * Filters out any node that does not have a CWE alert with the specified CWE ID.\n */\nexport const cwe = async (state: ParserState) => {\n if (!state.securityArchive) {\n throw new Error(\n 'Missing security archive while trying to parse ' +\n 'the :cwe security selector',\n )\n }\n\n let internals\n try {\n internals = parseInternals(\n asPostcssNodeWithChildren(state.current).nodes,\n )\n } catch (err) {\n throw error('Failed to parse :cwe selector', { cause: err })\n }\n\n const { cweId } = internals\n for (const node of state.partial.nodes) {\n const report = state.securityArchive.get(node.id)\n const exclude = !report?.alerts.some(alert =>\n alert.props.cwes.some(\n cwe =>\n cwe.id.trim().toLowerCase() === cweId.trim().toLowerCase(),\n ),\n )\n if (exclude) {\n removeNode(state, node)\n }\n }\n\n removeDanglingEdges(state)\n\n return state\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import type { ParserState, PostcssNode } from '../types.ts';
2
+ export type LicenseKinds = 'unlicensed' | 'misc' | 'restricted' | 'ambiguous' | 'copyleft' | 'unknown' | 'none' | 'exception' | undefined;
3
+ export type LicenseAlertTypes = 'explicitlyUnlicensedItem' | 'miscLicenseIssues' | 'nonpermissiveLicense' | 'ambiguousClassifier' | 'copyleftLicense' | 'unidentifiedLicense' | 'noLicenseFound' | 'licenseException' | undefined;
4
+ export declare const isLicenseKind: (value?: string) => value is LicenseKinds;
5
+ export declare const asLicenseKind: (value?: string) => LicenseKinds;
6
+ export declare const parseInternals: (nodes: PostcssNode[]) => {
7
+ kind: LicenseKinds;
8
+ };
9
+ export declare const license: (state: ParserState) => Promise<ParserState>;
10
+ //# sourceMappingURL=license.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"license.d.ts","sourceRoot":"","sources":["../../../src/pseudo/license.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAO3D,MAAM,MAAM,YAAY,GACpB,YAAY,GACZ,MAAM,GACN,YAAY,GACZ,WAAW,GACX,UAAU,GACV,SAAS,GACT,MAAM,GACN,WAAW,GACX,SAAS,CAAA;AAEb,MAAM,MAAM,iBAAiB,GACzB,0BAA0B,GAC1B,mBAAmB,GACnB,sBAAsB,GACtB,qBAAqB,GACrB,iBAAiB,GACjB,qBAAqB,GACrB,gBAAgB,GAChB,kBAAkB,GAClB,SAAS,CAAA;AAeb,eAAO,MAAM,aAAa,WAChB,MAAM,KACb,KAAK,IAAI,YAAgD,CAAA;AAE5D,eAAO,MAAM,aAAa,WAAY,MAAM,KAAG,YAQ9C,CAAA;AAED,eAAO,MAAM,cAAc,UAClB,WAAW,EAAE,KACnB;IAAE,IAAI,EAAE,YAAY,CAAA;CAmBtB,CAAA;AAED,eAAO,MAAM,OAAO,UAAiB,WAAW,yBAgC/C,CAAA"}
@@ -0,0 +1,61 @@
1
+ import { error } from '@vltpkg/error-cause';
2
+ import { asPostcssNodeWithChildren, asStringNode, asTagNode, isStringNode, isTagNode, } from "../types.js";
3
+ import { removeDanglingEdges, removeNode, removeQuotes, } from "./helpers.js";
4
+ const kindsMap = new Map([
5
+ ['unlicensed', 'explicitlyUnlicensedItem'],
6
+ ['misc', 'miscLicenseIssues'],
7
+ ['restricted', 'nonpermissiveLicense'],
8
+ ['ambiguous', 'ambiguousClassifier'],
9
+ ['copyleft', 'copyleftLicense'],
10
+ ['unknown', 'unidentifiedLicense'],
11
+ ['none', 'noLicenseFound'],
12
+ ['exception', 'licenseException'],
13
+ [undefined, undefined],
14
+ ]);
15
+ const kinds = new Set(kindsMap.keys());
16
+ export const isLicenseKind = (value) => kinds.has(value);
17
+ export const asLicenseKind = (value) => {
18
+ if (!isLicenseKind(value)) {
19
+ throw error('Expected a valid license kind', {
20
+ found: value,
21
+ validOptions: Array.from(kinds),
22
+ });
23
+ }
24
+ return value;
25
+ };
26
+ export const parseInternals = (nodes) => {
27
+ let kind;
28
+ if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
29
+ kind = asLicenseKind(removeQuotes(asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])
30
+ .value));
31
+ }
32
+ else if (isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
33
+ kind = asLicenseKind(asTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0]).value);
34
+ }
35
+ return { kind };
36
+ };
37
+ export const license = async (state) => {
38
+ if (!state.securityArchive) {
39
+ throw new Error('Missing security archive while trying to parse ' +
40
+ 'the :license security selector');
41
+ }
42
+ let internals;
43
+ try {
44
+ internals = parseInternals(asPostcssNodeWithChildren(state.current).nodes);
45
+ }
46
+ catch (err) {
47
+ throw error('Failed to parse :license selector', { cause: err });
48
+ }
49
+ const { kind } = internals;
50
+ const alertName = kindsMap.get(kind);
51
+ for (const node of state.partial.nodes) {
52
+ const report = state.securityArchive.get(node.id);
53
+ const exclude = !report?.alerts.some(alert => alert.type === alertName);
54
+ if (exclude) {
55
+ removeNode(state, node);
56
+ }
57
+ }
58
+ removeDanglingEdges(state);
59
+ return state;
60
+ };
61
+ //# sourceMappingURL=license.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"license.js","sourceRoot":"","sources":["../../../src/pseudo/license.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,aAAa,CAAA;AAEpB,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,YAAY,GACb,MAAM,cAAc,CAAA;AAwBrB,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAkC;IACxD,CAAC,YAAY,EAAE,0BAA0B,CAAC;IAC1C,CAAC,MAAM,EAAE,mBAAmB,CAAC;IAC7B,CAAC,YAAY,EAAE,sBAAsB,CAAC;IACtC,CAAC,WAAW,EAAE,qBAAqB,CAAC;IACpC,CAAC,UAAU,EAAE,iBAAiB,CAAC;IAC/B,CAAC,SAAS,EAAE,qBAAqB,CAAC;IAClC,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAC1B,CAAC,WAAW,EAAE,kBAAkB,CAAC;IACjC,CAAC,SAAS,EAAE,SAAS,CAAC;CACvB,CAAC,CAAA;AACF,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;AAEtC,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,KAAc,EACS,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,KAAqB,CAAC,CAAA;AAE5D,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAc,EAAgB,EAAE;IAC5D,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,KAAK,CAAC,+BAA+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AAM,KAAK,CAAC,mCAAmC,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAA;IAClE,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,GAAG,SAAS,CAAA;IAC1B,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IACpC,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACvC,MAAM,MAAM,GAAG,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACjD,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAClC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAClC,CAAA;QACD,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 {\n asPostcssNodeWithChildren,\n asStringNode,\n asTagNode,\n isStringNode,\n isTagNode,\n} from '../types.ts'\nimport type { ParserState, PostcssNode } from '../types.ts'\nimport {\n removeDanglingEdges,\n removeNode,\n removeQuotes,\n} from './helpers.ts'\n\nexport type LicenseKinds =\n | 'unlicensed'\n | 'misc'\n | 'restricted'\n | 'ambiguous'\n | 'copyleft'\n | 'unknown'\n | 'none'\n | 'exception'\n | undefined\n\nexport type LicenseAlertTypes =\n | 'explicitlyUnlicensedItem'\n | 'miscLicenseIssues'\n | 'nonpermissiveLicense'\n | 'ambiguousClassifier'\n | 'copyleftLicense'\n | 'unidentifiedLicense'\n | 'noLicenseFound'\n | 'licenseException'\n | undefined\n\nconst kindsMap = new Map<LicenseKinds, LicenseAlertTypes>([\n ['unlicensed', 'explicitlyUnlicensedItem'],\n ['misc', 'miscLicenseIssues'],\n ['restricted', 'nonpermissiveLicense'],\n ['ambiguous', 'ambiguousClassifier'],\n ['copyleft', 'copyleftLicense'],\n ['unknown', 'unidentifiedLicense'],\n ['none', 'noLicenseFound'],\n ['exception', 'licenseException'],\n [undefined, undefined],\n])\nconst kinds = new Set(kindsMap.keys())\n\nexport const isLicenseKind = (\n value?: string,\n): value is LicenseKinds => kinds.has(value as LicenseKinds)\n\nexport const asLicenseKind = (value?: string): LicenseKinds => {\n if (!isLicenseKind(value)) {\n throw error('Expected a valid license kind', {\n found: value,\n validOptions: Array.from(kinds),\n })\n }\n return value\n}\n\nexport const parseInternals = (\n nodes: PostcssNode[],\n): { kind: LicenseKinds } => {\n let kind: LicenseKinds\n\n if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {\n kind = asLicenseKind(\n removeQuotes(\n asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n .value,\n ),\n )\n } else if (\n isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n ) {\n kind = asLicenseKind(\n asTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0]).value,\n )\n }\n\n return { kind }\n}\n\nexport const license = async (state: ParserState) => {\n if (!state.securityArchive) {\n throw new Error(\n 'Missing security archive while trying to parse ' +\n 'the :license security selector',\n )\n }\n\n let internals\n try {\n internals = parseInternals(\n asPostcssNodeWithChildren(state.current).nodes,\n )\n } catch (err) {\n throw error('Failed to parse :license selector', { cause: err })\n }\n\n const { kind } = internals\n const alertName = kindsMap.get(kind)\n for (const node of state.partial.nodes) {\n const report = state.securityArchive.get(node.id)\n const exclude = !report?.alerts.some(\n alert => alert.type === alertName,\n )\n if (exclude) {\n removeNode(state, node)\n }\n }\n\n removeDanglingEdges(state)\n\n return state\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import type { ParserState, PostcssNode } from '../types.ts';
2
+ export type MalwareKinds = '0' | '1' | '2' | '3' | 'critical' | 'high' | 'medium' | 'low' | undefined;
3
+ export type MalwareAlertTypes = 'malware' | 'gptMalware' | 'gptSecurity' | 'gptAnomaly' | undefined;
4
+ export declare const isMalwareKind: (value?: string) => value is MalwareKinds;
5
+ export declare const asMalwareKind: (value?: string) => MalwareKinds;
6
+ export declare const parseInternals: (nodes: PostcssNode[]) => {
7
+ kind: MalwareKinds;
8
+ };
9
+ export declare const malware: (state: ParserState) => Promise<ParserState>;
10
+ //# sourceMappingURL=malware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"malware.d.ts","sourceRoot":"","sources":["../../../src/pseudo/malware.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAO3D,MAAM,MAAM,YAAY,GACpB,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,UAAU,GACV,MAAM,GACN,QAAQ,GACR,KAAK,GACL,SAAS,CAAA;AAEb,MAAM,MAAM,iBAAiB,GACzB,SAAS,GACT,YAAY,GACZ,aAAa,GACb,YAAY,GACZ,SAAS,CAAA;AAcb,eAAO,MAAM,aAAa,WAChB,MAAM,KACb,KAAK,IAAI,YAAgD,CAAA;AAE5D,eAAO,MAAM,aAAa,WAAY,MAAM,KAAG,YAQ9C,CAAA;AAED,eAAO,MAAM,cAAc,UAClB,WAAW,EAAE,KACnB;IAAE,IAAI,EAAE,YAAY,CAAA;CAmBtB,CAAA;AAED,eAAO,MAAM,OAAO,UAAiB,WAAW,yBAgC/C,CAAA"}
@@ -0,0 +1,60 @@
1
+ import { error } from '@vltpkg/error-cause';
2
+ import { asPostcssNodeWithChildren, asStringNode, asTagNode, isStringNode, isTagNode, } from "../types.js";
3
+ import { removeDanglingEdges, removeNode, removeQuotes, } from "./helpers.js";
4
+ const kindsMap = new Map([
5
+ ['critical', 'malware'],
6
+ ['high', 'gptMalware'],
7
+ ['medium', 'gptSecurity'],
8
+ ['low', 'gptAnomaly'],
9
+ ['0', 'malware'],
10
+ ['1', 'gptMalware'],
11
+ ['2', 'gptSecurity'],
12
+ ['3', 'gptAnomaly'],
13
+ ]);
14
+ const kinds = new Set(kindsMap.keys());
15
+ export const isMalwareKind = (value) => kinds.has(value);
16
+ export const asMalwareKind = (value) => {
17
+ if (!isMalwareKind(value)) {
18
+ throw error('Expected a valid malware kind', {
19
+ found: value,
20
+ validOptions: Array.from(kinds),
21
+ });
22
+ }
23
+ return value;
24
+ };
25
+ export const parseInternals = (nodes) => {
26
+ let kind;
27
+ if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
28
+ kind = asMalwareKind(removeQuotes(asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])
29
+ .value));
30
+ }
31
+ else if (isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
32
+ kind = asMalwareKind(asTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0]).value);
33
+ }
34
+ return { kind };
35
+ };
36
+ export const malware = async (state) => {
37
+ if (!state.securityArchive) {
38
+ throw new Error('Missing security archive while trying to parse ' +
39
+ 'the :malware security selector');
40
+ }
41
+ let internals;
42
+ try {
43
+ internals = parseInternals(asPostcssNodeWithChildren(state.current).nodes);
44
+ }
45
+ catch (err) {
46
+ throw error('Failed to parse :malware selector', { cause: err });
47
+ }
48
+ const { kind } = internals;
49
+ const alertName = kindsMap.get(kind);
50
+ for (const node of state.partial.nodes) {
51
+ const report = state.securityArchive.get(node.id);
52
+ const exclude = !report?.alerts.some(alert => alert.type === alertName);
53
+ if (exclude) {
54
+ removeNode(state, node);
55
+ }
56
+ }
57
+ removeDanglingEdges(state);
58
+ return state;
59
+ };
60
+ //# sourceMappingURL=malware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"malware.js","sourceRoot":"","sources":["../../../src/pseudo/malware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EACL,yBAAyB,EACzB,YAAY,EACZ,SAAS,EACT,YAAY,EACZ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AAC,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAClC,CAAA;QACD,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 {\n asPostcssNodeWithChildren,\n asStringNode,\n asTagNode,\n isStringNode,\n isTagNode,\n} from '../types.ts'\nimport type { ParserState, PostcssNode } from '../types.ts'\nimport {\n removeDanglingEdges,\n removeNode,\n removeQuotes,\n} from './helpers.ts'\n\nexport type MalwareKinds =\n | '0'\n | '1'\n | '2'\n | '3'\n | 'critical'\n | 'high'\n | 'medium'\n | 'low'\n | undefined\n\nexport type MalwareAlertTypes =\n | 'malware'\n | 'gptMalware'\n | 'gptSecurity'\n | 'gptAnomaly'\n | undefined\n\nconst kindsMap = new Map<MalwareKinds, MalwareAlertTypes>([\n ['critical', 'malware'],\n ['high', 'gptMalware'],\n ['medium', 'gptSecurity'],\n ['low', 'gptAnomaly'],\n ['0', 'malware'],\n ['1', 'gptMalware'],\n ['2', 'gptSecurity'],\n ['3', 'gptAnomaly'],\n])\nconst kinds = new Set(kindsMap.keys())\n\nexport const isMalwareKind = (\n value?: string,\n): value is MalwareKinds => kinds.has(value as MalwareKinds)\n\nexport const asMalwareKind = (value?: string): MalwareKinds => {\n if (!isMalwareKind(value)) {\n throw error('Expected a valid malware kind', {\n found: value,\n validOptions: Array.from(kinds),\n })\n }\n return value\n}\n\nexport const parseInternals = (\n nodes: PostcssNode[],\n): { kind: MalwareKinds } => {\n let kind: MalwareKinds\n\n if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {\n kind = asMalwareKind(\n removeQuotes(\n asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n .value,\n ),\n )\n } else if (\n isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n ) {\n kind = asMalwareKind(\n asTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0]).value,\n )\n }\n\n return { kind }\n}\n\nexport const malware = async (state: ParserState) => {\n if (!state.securityArchive) {\n throw new Error(\n 'Missing security archive while trying to parse ' +\n 'the :malware security selector',\n )\n }\n\n let internals\n try {\n internals = parseInternals(\n asPostcssNodeWithChildren(state.current).nodes,\n )\n } catch (err) {\n throw error('Failed to parse :malware selector', { cause: err })\n }\n\n const { kind } = internals\n const alertName = kindsMap.get(kind)\n for (const node of state.partial.nodes) {\n const report = state.securityArchive.get(node.id)\n const exclude = !report?.alerts.some(\n alert => alert.type === alertName,\n )\n if (exclude) {\n removeNode(state, node)\n }\n }\n\n removeDanglingEdges(state)\n\n return state\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import type { ParserState, PostcssNode } from '../types.ts';
2
+ export type SeverityKinds = '0' | '1' | '2' | '3' | 'critical' | 'high' | 'medium' | 'low' | undefined;
3
+ export type SeverityAlertTypes = 'criticalCVE' | 'cve' | 'potentialVulnerability' | 'mildCVE' | undefined;
4
+ export declare const isSeverityKind: (value?: string) => value is SeverityKinds;
5
+ export declare const asSeverityKind: (value?: string) => SeverityKinds;
6
+ export declare const parseInternals: (nodes: PostcssNode[]) => {
7
+ kind: SeverityKinds;
8
+ };
9
+ export declare const severity: (state: ParserState) => Promise<ParserState>;
10
+ //# sourceMappingURL=severity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"severity.d.ts","sourceRoot":"","sources":["../../../src/pseudo/severity.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAO3D,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;AAcb,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;IAAE,IAAI,EAAE,aAAa,CAAA;CAmBvB,CAAA;AAED,eAAO,MAAM,QAAQ,UAAiB,WAAW,yBAgChD,CAAA"}
@@ -0,0 +1,60 @@
1
+ import { error } from '@vltpkg/error-cause';
2
+ import { asPostcssNodeWithChildren, asStringNode, asTagNode, isStringNode, isTagNode, } from "../types.js";
3
+ import { 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
+ const kinds = new Set(kindsMap.keys());
15
+ export const isSeverityKind = (value) => kinds.has(value);
16
+ export const asSeverityKind = (value) => {
17
+ if (!isSeverityKind(value)) {
18
+ throw error('Expected a valid severity kind', {
19
+ found: value,
20
+ validOptions: Array.from(kinds),
21
+ });
22
+ }
23
+ return value;
24
+ };
25
+ export const parseInternals = (nodes) => {
26
+ let kind;
27
+ if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
28
+ kind = asSeverityKind(removeQuotes(asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])
29
+ .value));
30
+ }
31
+ else if (isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
32
+ kind = asSeverityKind(asTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0]).value);
33
+ }
34
+ return { kind };
35
+ };
36
+ export const severity = async (state) => {
37
+ if (!state.securityArchive) {
38
+ throw new Error('Missing security archive while trying to parse ' +
39
+ 'the :severity security selector');
40
+ }
41
+ let internals;
42
+ try {
43
+ internals = parseInternals(asPostcssNodeWithChildren(state.current).nodes);
44
+ }
45
+ catch (err) {
46
+ throw error('Failed to parse :severity selector', { cause: err });
47
+ }
48
+ const { kind } = internals;
49
+ const alertName = kindsMap.get(kind);
50
+ for (const node of state.partial.nodes) {
51
+ const report = state.securityArchive.get(node.id);
52
+ const exclude = !report?.alerts.some(alert => alert.type === alertName);
53
+ if (exclude) {
54
+ removeNode(state, node);
55
+ }
56
+ }
57
+ removeDanglingEdges(state);
58
+ return state;
59
+ };
60
+ //# sourceMappingURL=severity.js.map
@@ -0,0 +1 @@
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,aAAa,CAAA;AAEpB,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,YAAY,GACb,MAAM,cAAc,CAAA;AAoBrB,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;AACF,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;AAEtC,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,KAAc,EACU,EA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,CACpC,CAAA;IACH,CAAC;IAED,IAAI,SAAS,CAAA;IACb,IAAI,CAAC;QACH,SAAS,GAAG,cAAc,CACxB,yBAAyB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,KAAK,CAC/C,CAAA;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,KAAK,CAAC,oCAAoC,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAA;IACnE,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,GAAG,SAAS,CAAA;IAC1B,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IACpC,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACvC,MAAM,MAAM,GAAG,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACjD,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAClC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAClC,CAAA;QACD,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 {\n asPostcssNodeWithChildren,\n asStringNode,\n asTagNode,\n isStringNode,\n isTagNode,\n} from '../types.ts'\nimport type { ParserState, PostcssNode } from '../types.ts'\nimport {\n removeDanglingEdges,\n removeNode,\n removeQuotes,\n} from './helpers.ts'\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\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])\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): { kind: SeverityKinds } => {\n let kind: SeverityKinds\n\n if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {\n kind = asSeverityKind(\n removeQuotes(\n asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n .value,\n ),\n )\n } else if (\n isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n ) {\n kind = asSeverityKind(\n asTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0]).value,\n )\n }\n\n return { kind }\n}\n\nexport const severity = async (state: ParserState) => {\n if (!state.securityArchive) {\n throw new Error(\n 'Missing security archive while trying to parse ' +\n 'the :severity security selector',\n )\n }\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 } = internals\n const alertName = kindsMap.get(kind)\n for (const node of state.partial.nodes) {\n const report = state.securityArchive.get(node.id)\n const exclude = !report?.alerts.some(\n alert => alert.type === alertName,\n )\n if (exclude) {\n removeNode(state, node)\n }\n }\n\n removeDanglingEdges(state)\n\n return state\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import type { ParserState, PostcssNode } from '../types.ts';
2
+ export type SquatKinds = '0' | '2' | 'critical' | 'medium' | undefined;
3
+ export type SquatAlertTypes = 'didYouMean' | 'gptDidYouMean' | undefined;
4
+ export declare const isSquatKind: (value?: string) => value is SquatKinds;
5
+ export declare const asSquatKind: (value?: string) => SquatKinds;
6
+ export declare const parseInternals: (nodes: PostcssNode[]) => {
7
+ kind: SquatKinds;
8
+ };
9
+ export declare const squat: (state: ParserState) => Promise<ParserState>;
10
+ //# sourceMappingURL=squat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"squat.d.ts","sourceRoot":"","sources":["../../../src/pseudo/squat.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAO3D,MAAM,MAAM,UAAU,GAAG,GAAG,GAAG,GAAG,GAAG,UAAU,GAAG,QAAQ,GAAG,SAAS,CAAA;AAEtE,MAAM,MAAM,eAAe,GACvB,YAAY,GACZ,eAAe,GACf,SAAS,CAAA;AAWb,eAAO,MAAM,WAAW,WAAY,MAAM,KAAG,KAAK,IAAI,UACtB,CAAA;AAEhC,eAAO,MAAM,WAAW,WAAY,MAAM,KAAG,UAQ5C,CAAA;AAED,eAAO,MAAM,cAAc,UAClB,WAAW,EAAE,KACnB;IAAE,IAAI,EAAE,UAAU,CAAA;CAmBpB,CAAA;AAED,eAAO,MAAM,KAAK,UAAiB,WAAW,yBAgC7C,CAAA"}
@@ -0,0 +1,57 @@
1
+ import { error } from '@vltpkg/error-cause';
2
+ import { asPostcssNodeWithChildren, asStringNode, asTagNode, isStringNode, isTagNode, } from "../types.js";
3
+ import { removeDanglingEdges, removeNode, removeQuotes, } from "./helpers.js";
4
+ const kindsMap = new Map([
5
+ ['critical', 'didYouMean'],
6
+ ['medium', 'gptDidYouMean'],
7
+ ['0', 'didYouMean'],
8
+ ['2', 'gptDidYouMean'],
9
+ [undefined, undefined],
10
+ ]);
11
+ const kinds = new Set(kindsMap.keys());
12
+ export const isSquatKind = (value) => kinds.has(value);
13
+ export const asSquatKind = (value) => {
14
+ if (!isSquatKind(value)) {
15
+ throw error('Expected a valid squat kind', {
16
+ found: value,
17
+ validOptions: Array.from(kinds),
18
+ });
19
+ }
20
+ return value;
21
+ };
22
+ export const parseInternals = (nodes) => {
23
+ let kind;
24
+ if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
25
+ kind = asSquatKind(removeQuotes(asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])
26
+ .value));
27
+ }
28
+ else if (isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
29
+ kind = asSquatKind(asTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0]).value);
30
+ }
31
+ return { kind };
32
+ };
33
+ export const squat = async (state) => {
34
+ if (!state.securityArchive) {
35
+ throw new Error('Missing security archive while trying to parse ' +
36
+ 'the :squat security selector');
37
+ }
38
+ let internals;
39
+ try {
40
+ internals = parseInternals(asPostcssNodeWithChildren(state.current).nodes);
41
+ }
42
+ catch (err) {
43
+ throw error('Failed to parse :squat selector', { cause: err });
44
+ }
45
+ const { kind } = internals;
46
+ const alertName = kindsMap.get(kind);
47
+ for (const node of state.partial.nodes) {
48
+ const report = state.securityArchive.get(node.id);
49
+ const exclude = !report?.alerts.some(alert => alert.type === alertName);
50
+ if (exclude) {
51
+ removeNode(state, node);
52
+ }
53
+ }
54
+ removeDanglingEdges(state);
55
+ return state;
56
+ };
57
+ //# sourceMappingURL=squat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"squat.js","sourceRoot":"","sources":["../../../src/pseudo/squat.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,aAAa,CAAA;AAEpB,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,YAAY,GACb,MAAM,cAAc,CAAA;AASrB,MAAM,QAAQ,GAAG,IAAI,GAAG,CA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@vltpkg/error-cause'\nimport {\n asPostcssNodeWithChildren,\n asStringNode,\n asTagNode,\n isStringNode,\n isTagNode,\n} from '../types.ts'\nimport type { ParserState, PostcssNode } from '../types.ts'\nimport {\n removeDanglingEdges,\n removeNode,\n removeQuotes,\n} from './helpers.ts'\n\nexport type SquatKinds = '0' | '2' | 'critical' | 'medium' | undefined\n\nexport type SquatAlertTypes =\n | 'didYouMean'\n | 'gptDidYouMean'\n | undefined\n\nconst kindsMap = new Map<SquatKinds, SquatAlertTypes>([\n ['critical', 'didYouMean'],\n ['medium', 'gptDidYouMean'],\n ['0', 'didYouMean'],\n ['2', 'gptDidYouMean'],\n [undefined, undefined],\n])\nconst kinds = new Set(kindsMap.keys())\n\nexport const isSquatKind = (value?: string): value is SquatKinds =>\n kinds.has(value as SquatKinds)\n\nexport const asSquatKind = (value?: string): SquatKinds => {\n if (!isSquatKind(value)) {\n throw error('Expected a valid squat kind', {\n found: value,\n validOptions: Array.from(kinds),\n })\n }\n return value\n}\n\nexport const parseInternals = (\n nodes: PostcssNode[],\n): { kind: SquatKinds } => {\n let kind: SquatKinds\n\n if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {\n kind = asSquatKind(\n removeQuotes(\n asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n .value,\n ),\n )\n } else if (\n isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n ) {\n kind = asSquatKind(\n asTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0]).value,\n )\n }\n\n return { kind }\n}\n\nexport const squat = async (state: ParserState) => {\n if (!state.securityArchive) {\n throw new Error(\n 'Missing security archive while trying to parse ' +\n 'the :squat security selector',\n )\n }\n\n let internals\n try {\n internals = parseInternals(\n asPostcssNodeWithChildren(state.current).nodes,\n )\n } catch (err) {\n throw error('Failed to parse :squat selector', { cause: err })\n }\n\n const { kind } = internals\n const alertName = kindsMap.get(kind)\n for (const node of state.partial.nodes) {\n const report = state.securityArchive.get(node.id)\n const exclude = !report?.alerts.some(\n alert => alert.type === alertName,\n )\n if (exclude) {\n removeNode(state, node)\n }\n }\n\n removeDanglingEdges(state)\n\n return state\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"pseudo.d.ts","sourceRoot":"","sources":["../../src/pseudo.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAY,WAAW,EAAE,MAAM,YAAY,CAAA;AAqXvD;;GAEG;AACH,eAAO,MAAM,MAAM,UAAiB,WAAW,yBAiB9C,CAAA"}
1
+ {"version":3,"file":"pseudo.d.ts","sourceRoot":"","sources":["../../src/pseudo.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAY,WAAW,EAAE,MAAM,YAAY,CAAA;AAkYvD;;GAEG;AACH,eAAO,MAAM,MAAM,UAAiB,WAAW,yBAiB9C,CAAA"}
@@ -7,6 +7,8 @@ import { asPostcssNodeWithChildren, asPseudoNode, asTagNode, isSelectorNode, } f
7
7
  import { abandoned } from "./pseudo/abandoned.js";
8
8
  import { attr } from "./pseudo/attr.js";
9
9
  import { confused } from "./pseudo/confused.js";
10
+ import { cve } from "./pseudo/cve.js";
11
+ import { cwe } from "./pseudo/cwe.js";
10
12
  import { debug } from "./pseudo/debug.js";
11
13
  import { deprecated } from "./pseudo/deprecated.js";
12
14
  import { dynamic } from "./pseudo/dynamic.js";
@@ -14,6 +16,8 @@ import { entropic } from "./pseudo/entropic.js";
14
16
  import { env } from "./pseudo/env.js";
15
17
  import { evalParser } from "./pseudo/eval.js";
16
18
  import { fs } from "./pseudo/fs.js";
19
+ import { license } from "./pseudo/license.js";
20
+ import { malware } from "./pseudo/malware.js";
17
21
  import { minified } from "./pseudo/minified.js";
18
22
  import { nativeParser } from "./pseudo/native.js";
19
23
  import { network } from "./pseudo/network.js";
@@ -22,7 +26,9 @@ import { outdated } from "./pseudo/outdated.js";
22
26
  import { scripts } from "./pseudo/scripts.js";
23
27
  import { shell } from "./pseudo/shell.js";
24
28
  import { semverParser as semver } from "./pseudo/semver.js";
29
+ import { severity } from "./pseudo/severity.js";
25
30
  import { shrinkwrap } from "./pseudo/shrinkwrap.js";
31
+ import { squat } from "./pseudo/squat.js";
26
32
  import { suspicious } from "./pseudo/suspicious.js";
27
33
  import { tracker } from "./pseudo/tracker.js";
28
34
  import { trivial } from "./pseudo/trivial.js";
@@ -313,6 +319,8 @@ const pseudoSelectors = new Map(Object.entries({
313
319
  abandoned,
314
320
  attr,
315
321
  confused,
322
+ cve,
323
+ cwe,
316
324
  debug,
317
325
  deprecated,
318
326
  dynamic,
@@ -324,6 +332,8 @@ const pseudoSelectors = new Map(Object.entries({
324
332
  has,
325
333
  is,
326
334
  // TODO: link
335
+ license,
336
+ malware,
327
337
  minified,
328
338
  missing,
329
339
  native: nativeParser,
@@ -338,8 +348,11 @@ const pseudoSelectors = new Map(Object.entries({
338
348
  scope,
339
349
  scripts,
340
350
  semver,
351
+ sev: severity,
352
+ severity,
341
353
  shell,
342
354
  shrinkwrap,
355
+ squat,
343
356
  suspicious,
344
357
  tracker,
345
358
  trivial,
@@ -1 +1 @@
1
- {"version":3,"file":"pseudo.js","sourceRoot":"","sources":["../../src/pseudo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAE1C,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AACrE,OAAO,EACL,yBAAyB,EACzB,YAAY,EACZ,SAAS,EACT,cAAc,GACf,MAAM,YAAY,CAAA;AAGnB,4BAA4B;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAE,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AAI;IACJ,KAAK;IACL,OAAO;IACP,MAAM;IACN,KAAK;IACL,UAAU;IACV,UAAU;IACV,OAAO;IACP,OAAO;IACP,IAAI,EAAE,MAAM;IACZ,WAAW;IACX,OAAO;IACP,YAAY;IACZ,SAAS;IACT,QAAQ;CACT,CAAC,CACH,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,EAAE,KAAkB,EAAE,EAAE;IACjD,MAAM,KAAK,CAAC,WAAW,EAAE,CAAA;IAEzB,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACxC,MAAM,QAAQ,GACZ,IAAI,CAAC,KAAK,IAAI,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IAExD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YAChB,OAAO,KAAK,CAAA;QACd,CAAC;QAED,MAAM,IAAI,KAAK,CACb,6BAA6B,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CACnD,CAAA;IACH,CAAC;IACD,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAA;AACxB,CAAC,CAAA","sourcesContent":["import { splitDepID } from '@vltpkg/dep-id/browser'\nimport { error } from '@vltpkg/error-cause'\nimport type { EdgeLike, NodeLike } from '@vltpkg/graph'\nimport { asManifest } from '@vltpkg/types'\n\nimport { removeDanglingEdges, removeNode } from './pseudo/helpers.ts'\nimport {\n asPostcssNodeWithChildren,\n asPseudoNode,\n asTagNode,\n isSelectorNode,\n} from './types.ts'\nimport type { ParserFn, ParserState } from './types.ts'\n\n// imported pseudo selectors\nimport { abandoned } from './pseudo/abandoned.ts'\nimport { attr } from './pseudo/attr.ts'\nimport { confused } from './pseudo/confused.ts'\nimport { debug } from './pseudo/debug.ts'\nimport { deprecated } from './pseudo/deprecated.ts'\nimport { dynamic } from './pseudo/dynamic.ts'\nimport { entropic } from './pseudo/entropic.ts'\nimport { env } from './pseudo/env.ts'\nimport { evalParser } from './pseudo/eval.ts'\nimport { fs } from './pseudo/fs.ts'\nimport { minified } from './pseudo/minified.ts'\nimport { nativeParser } from './pseudo/native.ts'\nimport { network } from './pseudo/network.ts'\nimport { obfuscated } from './pseudo/obfuscated.ts'\nimport { outdated } from './pseudo/outdated.ts'\nimport { scripts } from './pseudo/scripts.ts'\nimport { shell } from './pseudo/shell.ts'\nimport { semverParser as semver } from './pseudo/semver.ts'\nimport { shrinkwrap } from './pseudo/shrinkwrap.ts'\nimport { suspicious } from './pseudo/suspicious.ts'\nimport { tracker } from './pseudo/tracker.ts'\nimport { trivial } from './pseudo/trivial.ts'\nimport { undesirable } from './pseudo/undesirable.ts'\nimport { unknown } from './pseudo/unknown.ts'\nimport { unmaintained } from './pseudo/unmaintained.ts'\nimport { unpopular } from './pseudo/unpopular.ts'\nimport { unstable } from './pseudo/unstable.ts'\n\n/**\n * :empty Pseudo-Selector, matches only nodes that have no children.\n */\nconst empty = async (state: ParserState) => {\n for (const node of state.partial.nodes) {\n if (node.edgesOut.size > 0) {\n removeNode(state, node)\n }\n }\n return state\n}\n\n/**\n * :has Pseudo-Selector, matches only nodes that have valid results\n * for its nested selector expressions.\n */\nconst has = async (state: ParserState) => {\n const top = asPostcssNodeWithChildren(state.current)\n const collectNodes = new Set<NodeLike>()\n const collectEdges = new Set<EdgeLike>()\n\n for (const node of top.nodes) {\n if (isSelectorNode(node)) {\n const nestedState = await state.walk({\n cancellable: state.cancellable,\n initial: {\n edges: new Set(state.initial.edges),\n nodes: new Set(state.initial.nodes),\n },\n current: node,\n walk: state.walk,\n collect: {\n edges: new Set(),\n nodes: new Set(),\n },\n partial: {\n edges: new Set(state.partial.edges),\n nodes: new Set(state.partial.nodes),\n },\n securityArchive: state.securityArchive,\n specOptions: state.specOptions,\n })\n for (const n of nestedState.collect.nodes) {\n collectNodes.add(n)\n }\n for (const e of nestedState.partial.edges) {\n collectEdges.add(e)\n }\n }\n }\n\n // if the nested selector did not match anything, that means\n // no current node has any matches\n if (collectNodes.size === 0) {\n state.partial.edges.clear()\n state.partial.nodes.clear()\n return state\n }\n\n // handles transitive dependencies\n // compareNodes collects a list of all ancestor nodes\n // from the resulting nodes of the nested selector\n const compareNodes = new Set<NodeLike>()\n const traverse = new Set(collectNodes)\n for (const node of traverse) {\n for (const edge of node.edgesIn) {\n compareNodes.add(edge.from)\n if (edge.from.edgesIn.size) {\n traverse.add(edge.from)\n }\n }\n }\n\n // for each node in the current list checks to see if\n // it has a node in the resulting nested state that is\n // a transitive dependency / children.\n nodesLoop: for (const node of state.partial.nodes) {\n if (node.edgesOut.size === 0 || !compareNodes.has(node)) {\n removeNode(state, node)\n continue\n }\n\n for (const edge of node.edgesOut.values()) {\n if (collectEdges.has(edge)) {\n continue nodesLoop\n }\n }\n removeNode(state, node)\n }\n\n removeDanglingEdges(state)\n\n return state\n}\n\n/**\n * :is Pseudo-selector, acts as a shortcut for writing more compact expressions\n * by allowing multiple nested selectors to match on the previous results.\n *\n * It also enables the loose parsing mode, skipping instead of erroring usage\n * of non-existing classes, identifiers, pseudo-classes, etc.\n */\nconst is = async (state: ParserState) => {\n const top = asPostcssNodeWithChildren(state.current)\n const collect = new Set()\n for (const node of top.nodes) {\n if (isSelectorNode(node)) {\n const nestedState = await state.walk({\n cancellable: state.cancellable,\n collect: {\n edges: new Set(),\n nodes: new Set(),\n },\n current: node,\n initial: state.initial,\n loose: true,\n partial: {\n nodes: new Set(state.partial.nodes),\n edges: new Set(state.partial.edges),\n },\n walk: state.walk,\n securityArchive: state.securityArchive,\n specOptions: state.specOptions,\n })\n for (const n of nestedState.collect.nodes) {\n collect.add(n)\n }\n }\n }\n for (const node of state.partial.nodes) {\n if (!collect.has(node)) {\n removeNode(state, node)\n }\n }\n return state\n}\n\n/**\n * :missing Pseudo-Selector, matches only\n * edges that are not linked to any node.\n */\nconst missing = async (state: ParserState) => {\n for (const edge of state.partial.edges) {\n if (edge.to) {\n state.partial.edges.delete(edge)\n }\n }\n state.partial.nodes.clear()\n return state\n}\n\n/**\n * :not Pseudo-class, serves to create negate expressions, anything that\n * matches selectors declared inside the `:not()` expression is going to be\n * filtered out in the final result.\n */\nconst not = async (state: ParserState) => {\n const top = asPostcssNodeWithChildren(state.current)\n const collect = new Set()\n for (const node of top.nodes) {\n if (isSelectorNode(node)) {\n const nestedState = await state.walk({\n cancellable: state.cancellable,\n collect: {\n edges: new Set(),\n nodes: new Set(),\n },\n current: node,\n initial: state.initial,\n partial: {\n nodes: new Set(state.partial.nodes),\n edges: new Set(state.partial.edges),\n },\n walk: state.walk,\n securityArchive: state.securityArchive,\n specOptions: state.specOptions,\n })\n for (const n of nestedState.collect.nodes) {\n collect.add(n)\n }\n /* c8 ignore start - should be impossible */\n } else {\n throw error('Error parsing :not() selectors', {\n wanted: { type: 'selector' },\n found: node,\n })\n }\n /* c8 ignore stop */\n }\n for (const node of state.partial.nodes) {\n if (collect.has(node)) {\n removeNode(state, node)\n }\n }\n return state\n}\n\n/**\n * :private Pseudo-Selector will only match packages that have\n * a `private: true` key set in their `package.json` metadata.\n */\nconst privateFn = async (state: ParserState) => {\n for (const node of state.partial.nodes) {\n if (!node.manifest || !asManifest(node.manifest).private) {\n removeNode(state, node)\n }\n }\n\n removeDanglingEdges(state)\n\n return state\n}\n\n/**\n * :root Pseudo-Element will return the project root node for the graph.\n */\nconst root = async (state: ParserState) => {\n const [anyNode] = state.initial.nodes.values()\n const mainImporter = anyNode?.graph.mainImporter\n if (!mainImporter) {\n throw error(':root pseudo-element works on local graphs only')\n }\n for (const edge of state.partial.edges) {\n if (edge.to !== mainImporter) {\n state.partial.edges.delete(edge)\n }\n }\n state.partial.nodes.clear()\n state.partial.nodes.add(mainImporter)\n return state\n}\n\n/**\n * :project Pseudo-Element, returns all graph importers (e.g: the\n * root node along with any configured workspace)\n */\nconst project = async (state: ParserState) => {\n const [anyNode] = state.initial.nodes.values()\n const importers = anyNode?.graph.importers\n if (!importers?.size) {\n throw error(':project pseudo-element works on local graphs only')\n }\n\n // make a list of all edges that are coming from importers\n // so that we can filter out any edges that are not direct\n // dependencies of the importers\n const importersEdgesIn = new Set<EdgeLike>()\n for (const importer of importers) {\n for (const edge of importer.edgesIn) {\n importersEdgesIn.add(edge)\n }\n }\n\n for (const edge of state.partial.edges) {\n if (!edge.to || !importersEdgesIn.has(edge)) {\n state.partial.edges.delete(edge)\n }\n }\n state.partial.nodes.clear()\n for (const importer of importers) {\n state.partial.nodes.add(importer)\n }\n return state\n}\n\n/**\n * :scope Pseudo-Element, returns the original scope of items\n * at the start of a given selector.\n */\nconst scope = async (state: ParserState) => {\n state.partial.edges.clear()\n state.partial.nodes.clear()\n for (const edge of state.initial.edges) {\n state.partial.edges.add(edge)\n }\n for (const node of state.initial.nodes) {\n state.partial.nodes.add(node)\n }\n return state\n}\n\n/**\n * :type(str) Pseudo-Element will match only nodes that are of\n * the same type as the value used\n */\nconst typeFn = async (state: ParserState) => {\n const type = asPostcssNodeWithChildren(state.current)\n const selector = asPostcssNodeWithChildren(type.nodes[0])\n const name = asTagNode(selector.nodes[0]).value\n for (const node of state.partial.nodes) {\n const nodeType = splitDepID(node.id)[0]\n if (nodeType !== name) {\n removeNode(state, node)\n }\n }\n return state\n}\n\nconst pseudoSelectors = new Map<string, ParserFn>(\n Object.entries({\n abandoned,\n attr,\n confused,\n debug,\n deprecated,\n dynamic,\n eval: evalParser,\n empty,\n entropic,\n env,\n fs,\n has,\n is,\n // TODO: link\n minified,\n missing,\n native: nativeParser,\n network,\n not,\n obfuscated,\n outdated,\n // TODO: overridden\n private: privateFn,\n project,\n root,\n scope,\n scripts,\n semver,\n shell,\n shrinkwrap,\n suspicious,\n tracker,\n trivial,\n type: typeFn,\n undesirable,\n unknown,\n unmaintained,\n unpopular,\n unstable,\n }),\n)\n\n/**\n * Parsers the `pseudo` node types.\n */\nexport const pseudo = async (state: ParserState) => {\n await state.cancellable()\n\n const curr = asPseudoNode(state.current)\n const parserFn =\n curr.value && pseudoSelectors.get(curr.value.slice(1))\n\n if (!parserFn) {\n if (state.loose) {\n return state\n }\n\n throw new Error(\n `Unsupported pseudo-class: ${state.current.value}`,\n )\n }\n return parserFn(state)\n}\n"]}
1
+ {"version":3,"file":"pseudo.js","sourceRoot":"","sources":["../../src/pseudo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAE1C,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AACrE,OAAO,EACL,yBAAyB,EACzB,YAAY,EACZ,SAAS,EACT,cAAc,GACf,MAAM,YAAY,CAAA;AAGnB,4BAA4B;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AACrC,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAA;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAE,OAAO,E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,MAAM;IACZ,WAAW;IACX,OAAO;IACP,YAAY;IACZ,SAAS;IACT,QAAQ;CACT,CAAC,CACH,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,EAAE,KAAkB,EAAE,EAAE;IACjD,MAAM,KAAK,CAAC,WAAW,EAAE,CAAA;IAEzB,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACxC,MAAM,QAAQ,GACZ,IAAI,CAAC,KAAK,IAAI,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IAExD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YAChB,OAAO,KAAK,CAAA;QACd,CAAC;QAED,MAAM,IAAI,KAAK,CACb,6BAA6B,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CACnD,CAAA;IACH,CAAC;IACD,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAA;AACxB,CAAC,CAAA","sourcesContent":["import { splitDepID } from '@vltpkg/dep-id/browser'\nimport { error } from '@vltpkg/error-cause'\nimport type { EdgeLike, NodeLike } from '@vltpkg/graph'\nimport { asManifest } from '@vltpkg/types'\n\nimport { removeDanglingEdges, removeNode } from './pseudo/helpers.ts'\nimport {\n asPostcssNodeWithChildren,\n asPseudoNode,\n asTagNode,\n isSelectorNode,\n} from './types.ts'\nimport type { ParserFn, ParserState } from './types.ts'\n\n// imported pseudo selectors\nimport { abandoned } from './pseudo/abandoned.ts'\nimport { attr } from './pseudo/attr.ts'\nimport { confused } from './pseudo/confused.ts'\nimport { cve } from './pseudo/cve.ts'\nimport { cwe } from './pseudo/cwe.ts'\nimport { debug } from './pseudo/debug.ts'\nimport { deprecated } from './pseudo/deprecated.ts'\nimport { dynamic } from './pseudo/dynamic.ts'\nimport { entropic } from './pseudo/entropic.ts'\nimport { env } from './pseudo/env.ts'\nimport { evalParser } from './pseudo/eval.ts'\nimport { fs } from './pseudo/fs.ts'\nimport { license } from './pseudo/license.ts'\nimport { malware } from './pseudo/malware.ts'\nimport { minified } from './pseudo/minified.ts'\nimport { nativeParser } from './pseudo/native.ts'\nimport { network } from './pseudo/network.ts'\nimport { obfuscated } from './pseudo/obfuscated.ts'\nimport { outdated } from './pseudo/outdated.ts'\nimport { scripts } from './pseudo/scripts.ts'\nimport { shell } from './pseudo/shell.ts'\nimport { semverParser as semver } from './pseudo/semver.ts'\nimport { severity } from './pseudo/severity.ts'\nimport { shrinkwrap } from './pseudo/shrinkwrap.ts'\nimport { squat } from './pseudo/squat.ts'\nimport { suspicious } from './pseudo/suspicious.ts'\nimport { tracker } from './pseudo/tracker.ts'\nimport { trivial } from './pseudo/trivial.ts'\nimport { undesirable } from './pseudo/undesirable.ts'\nimport { unknown } from './pseudo/unknown.ts'\nimport { unmaintained } from './pseudo/unmaintained.ts'\nimport { unpopular } from './pseudo/unpopular.ts'\nimport { unstable } from './pseudo/unstable.ts'\n\n/**\n * :empty Pseudo-Selector, matches only nodes that have no children.\n */\nconst empty = async (state: ParserState) => {\n for (const node of state.partial.nodes) {\n if (node.edgesOut.size > 0) {\n removeNode(state, node)\n }\n }\n return state\n}\n\n/**\n * :has Pseudo-Selector, matches only nodes that have valid results\n * for its nested selector expressions.\n */\nconst has = async (state: ParserState) => {\n const top = asPostcssNodeWithChildren(state.current)\n const collectNodes = new Set<NodeLike>()\n const collectEdges = new Set<EdgeLike>()\n\n for (const node of top.nodes) {\n if (isSelectorNode(node)) {\n const nestedState = await state.walk({\n cancellable: state.cancellable,\n initial: {\n edges: new Set(state.initial.edges),\n nodes: new Set(state.initial.nodes),\n },\n current: node,\n walk: state.walk,\n collect: {\n edges: new Set(),\n nodes: new Set(),\n },\n partial: {\n edges: new Set(state.partial.edges),\n nodes: new Set(state.partial.nodes),\n },\n securityArchive: state.securityArchive,\n specOptions: state.specOptions,\n })\n for (const n of nestedState.collect.nodes) {\n collectNodes.add(n)\n }\n for (const e of nestedState.partial.edges) {\n collectEdges.add(e)\n }\n }\n }\n\n // if the nested selector did not match anything, that means\n // no current node has any matches\n if (collectNodes.size === 0) {\n state.partial.edges.clear()\n state.partial.nodes.clear()\n return state\n }\n\n // handles transitive dependencies\n // compareNodes collects a list of all ancestor nodes\n // from the resulting nodes of the nested selector\n const compareNodes = new Set<NodeLike>()\n const traverse = new Set(collectNodes)\n for (const node of traverse) {\n for (const edge of node.edgesIn) {\n compareNodes.add(edge.from)\n if (edge.from.edgesIn.size) {\n traverse.add(edge.from)\n }\n }\n }\n\n // for each node in the current list checks to see if\n // it has a node in the resulting nested state that is\n // a transitive dependency / children.\n nodesLoop: for (const node of state.partial.nodes) {\n if (node.edgesOut.size === 0 || !compareNodes.has(node)) {\n removeNode(state, node)\n continue\n }\n\n for (const edge of node.edgesOut.values()) {\n if (collectEdges.has(edge)) {\n continue nodesLoop\n }\n }\n removeNode(state, node)\n }\n\n removeDanglingEdges(state)\n\n return state\n}\n\n/**\n * :is Pseudo-selector, acts as a shortcut for writing more compact expressions\n * by allowing multiple nested selectors to match on the previous results.\n *\n * It also enables the loose parsing mode, skipping instead of erroring usage\n * of non-existing classes, identifiers, pseudo-classes, etc.\n */\nconst is = async (state: ParserState) => {\n const top = asPostcssNodeWithChildren(state.current)\n const collect = new Set()\n for (const node of top.nodes) {\n if (isSelectorNode(node)) {\n const nestedState = await state.walk({\n cancellable: state.cancellable,\n collect: {\n edges: new Set(),\n nodes: new Set(),\n },\n current: node,\n initial: state.initial,\n loose: true,\n partial: {\n nodes: new Set(state.partial.nodes),\n edges: new Set(state.partial.edges),\n },\n walk: state.walk,\n securityArchive: state.securityArchive,\n specOptions: state.specOptions,\n })\n for (const n of nestedState.collect.nodes) {\n collect.add(n)\n }\n }\n }\n for (const node of state.partial.nodes) {\n if (!collect.has(node)) {\n removeNode(state, node)\n }\n }\n return state\n}\n\n/**\n * :missing Pseudo-Selector, matches only\n * edges that are not linked to any node.\n */\nconst missing = async (state: ParserState) => {\n for (const edge of state.partial.edges) {\n if (edge.to) {\n state.partial.edges.delete(edge)\n }\n }\n state.partial.nodes.clear()\n return state\n}\n\n/**\n * :not Pseudo-class, serves to create negate expressions, anything that\n * matches selectors declared inside the `:not()` expression is going to be\n * filtered out in the final result.\n */\nconst not = async (state: ParserState) => {\n const top = asPostcssNodeWithChildren(state.current)\n const collect = new Set()\n for (const node of top.nodes) {\n if (isSelectorNode(node)) {\n const nestedState = await state.walk({\n cancellable: state.cancellable,\n collect: {\n edges: new Set(),\n nodes: new Set(),\n },\n current: node,\n initial: state.initial,\n partial: {\n nodes: new Set(state.partial.nodes),\n edges: new Set(state.partial.edges),\n },\n walk: state.walk,\n securityArchive: state.securityArchive,\n specOptions: state.specOptions,\n })\n for (const n of nestedState.collect.nodes) {\n collect.add(n)\n }\n /* c8 ignore start - should be impossible */\n } else {\n throw error('Error parsing :not() selectors', {\n wanted: { type: 'selector' },\n found: node,\n })\n }\n /* c8 ignore stop */\n }\n for (const node of state.partial.nodes) {\n if (collect.has(node)) {\n removeNode(state, node)\n }\n }\n return state\n}\n\n/**\n * :private Pseudo-Selector will only match packages that have\n * a `private: true` key set in their `package.json` metadata.\n */\nconst privateFn = async (state: ParserState) => {\n for (const node of state.partial.nodes) {\n if (!node.manifest || !asManifest(node.manifest).private) {\n removeNode(state, node)\n }\n }\n\n removeDanglingEdges(state)\n\n return state\n}\n\n/**\n * :root Pseudo-Element will return the project root node for the graph.\n */\nconst root = async (state: ParserState) => {\n const [anyNode] = state.initial.nodes.values()\n const mainImporter = anyNode?.graph.mainImporter\n if (!mainImporter) {\n throw error(':root pseudo-element works on local graphs only')\n }\n for (const edge of state.partial.edges) {\n if (edge.to !== mainImporter) {\n state.partial.edges.delete(edge)\n }\n }\n state.partial.nodes.clear()\n state.partial.nodes.add(mainImporter)\n return state\n}\n\n/**\n * :project Pseudo-Element, returns all graph importers (e.g: the\n * root node along with any configured workspace)\n */\nconst project = async (state: ParserState) => {\n const [anyNode] = state.initial.nodes.values()\n const importers = anyNode?.graph.importers\n if (!importers?.size) {\n throw error(':project pseudo-element works on local graphs only')\n }\n\n // make a list of all edges that are coming from importers\n // so that we can filter out any edges that are not direct\n // dependencies of the importers\n const importersEdgesIn = new Set<EdgeLike>()\n for (const importer of importers) {\n for (const edge of importer.edgesIn) {\n importersEdgesIn.add(edge)\n }\n }\n\n for (const edge of state.partial.edges) {\n if (!edge.to || !importersEdgesIn.has(edge)) {\n state.partial.edges.delete(edge)\n }\n }\n state.partial.nodes.clear()\n for (const importer of importers) {\n state.partial.nodes.add(importer)\n }\n return state\n}\n\n/**\n * :scope Pseudo-Element, returns the original scope of items\n * at the start of a given selector.\n */\nconst scope = async (state: ParserState) => {\n state.partial.edges.clear()\n state.partial.nodes.clear()\n for (const edge of state.initial.edges) {\n state.partial.edges.add(edge)\n }\n for (const node of state.initial.nodes) {\n state.partial.nodes.add(node)\n }\n return state\n}\n\n/**\n * :type(str) Pseudo-Element will match only nodes that are of\n * the same type as the value used\n */\nconst typeFn = async (state: ParserState) => {\n const type = asPostcssNodeWithChildren(state.current)\n const selector = asPostcssNodeWithChildren(type.nodes[0])\n const name = asTagNode(selector.nodes[0]).value\n for (const node of state.partial.nodes) {\n const nodeType = splitDepID(node.id)[0]\n if (nodeType !== name) {\n removeNode(state, node)\n }\n }\n return state\n}\n\nconst pseudoSelectors = new Map<string, ParserFn>(\n Object.entries({\n abandoned,\n attr,\n confused,\n cve,\n cwe,\n debug,\n deprecated,\n dynamic,\n eval: evalParser,\n empty,\n entropic,\n env,\n fs,\n has,\n is,\n // TODO: link\n license,\n malware,\n minified,\n missing,\n native: nativeParser,\n network,\n not,\n obfuscated,\n outdated,\n // TODO: overridden\n private: privateFn,\n project,\n root,\n scope,\n scripts,\n semver,\n sev: severity,\n severity,\n shell,\n shrinkwrap,\n squat,\n suspicious,\n tracker,\n trivial,\n type: typeFn,\n undesirable,\n unknown,\n unmaintained,\n unpopular,\n unstable,\n }),\n)\n\n/**\n * Parsers the `pseudo` node types.\n */\nexport const pseudo = async (state: ParserState) => {\n await state.cancellable()\n\n const curr = asPseudoNode(state.current)\n const parserFn =\n curr.value && pseudoSelectors.get(curr.value.slice(1))\n\n if (!parserFn) {\n if (state.loose) {\n return state\n }\n\n throw new Error(\n `Unsupported pseudo-class: ${state.current.value}`,\n )\n }\n return parserFn(state)\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vltpkg/query",
3
3
  "description": "Query syntax parser that retrieves items from a graph",
4
- "version": "0.0.0-6",
4
+ "version": "0.0.0-7",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/vltpkg/vltpkg.git",
@@ -20,12 +20,12 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "postcss-selector-parser": "^6.1.2",
23
- "@vltpkg/dep-id": "0.0.0-6",
24
- "@vltpkg/error-cause": "0.0.0-6",
25
- "@vltpkg/graph": "0.0.0-6",
26
- "@vltpkg/security-archive": "0.0.0-6",
27
- "@vltpkg/semver": "0.0.0-6",
28
- "@vltpkg/types": "0.0.0-6"
23
+ "@vltpkg/dep-id": "0.0.0-7",
24
+ "@vltpkg/error-cause": "0.0.0-7",
25
+ "@vltpkg/graph": "0.0.0-7",
26
+ "@vltpkg/security-archive": "0.0.0-7",
27
+ "@vltpkg/semver": "0.0.0-7",
28
+ "@vltpkg/types": "0.0.0-7"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@eslint/js": "^9.20.0",
@@ -38,7 +38,7 @@
38
38
  "typedoc": "0.27.6",
39
39
  "typescript": "5.7.3",
40
40
  "typescript-eslint": "^8.23.0",
41
- "@vltpkg/spec": "0.0.0-6"
41
+ "@vltpkg/spec": "0.0.0-7"
42
42
  },
43
43
  "license": "BSD-2-Clause-Patent",
44
44
  "engines": {