@vltpkg/query 0.0.0-12 → 0.0.0-14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/README.md +38 -7
  2. package/dist/esm/attribute.d.ts.map +1 -1
  3. package/dist/esm/attribute.js +5 -12
  4. package/dist/esm/attribute.js.map +1 -1
  5. package/dist/esm/combinator.d.ts.map +1 -1
  6. package/dist/esm/combinator.js +1 -1
  7. package/dist/esm/combinator.js.map +1 -1
  8. package/dist/esm/id.d.ts.map +1 -1
  9. package/dist/esm/id.js +3 -1
  10. package/dist/esm/id.js.map +1 -1
  11. package/dist/esm/index.d.ts +7 -0
  12. package/dist/esm/index.d.ts.map +1 -1
  13. package/dist/esm/index.js +46 -10
  14. package/dist/esm/index.js.map +1 -1
  15. package/dist/esm/parser.d.ts.map +1 -1
  16. package/dist/esm/parser.js +1 -1
  17. package/dist/esm/parser.js.map +1 -1
  18. package/dist/esm/pseudo/attr.d.ts +2 -1
  19. package/dist/esm/pseudo/attr.d.ts.map +1 -1
  20. package/dist/esm/pseudo/attr.js +1 -1
  21. package/dist/esm/pseudo/attr.js.map +1 -1
  22. package/dist/esm/pseudo/cve.d.ts +2 -1
  23. package/dist/esm/pseudo/cve.d.ts.map +1 -1
  24. package/dist/esm/pseudo/cve.js +1 -1
  25. package/dist/esm/pseudo/cve.js.map +1 -1
  26. package/dist/esm/pseudo/cwe.d.ts +2 -1
  27. package/dist/esm/pseudo/cwe.d.ts.map +1 -1
  28. package/dist/esm/pseudo/cwe.js +1 -1
  29. package/dist/esm/pseudo/cwe.js.map +1 -1
  30. package/dist/esm/pseudo/helpers.d.ts.map +1 -1
  31. package/dist/esm/pseudo/helpers.js.map +1 -1
  32. package/dist/esm/pseudo/license.d.ts +2 -1
  33. package/dist/esm/pseudo/license.d.ts.map +1 -1
  34. package/dist/esm/pseudo/license.js +1 -1
  35. package/dist/esm/pseudo/license.js.map +1 -1
  36. package/dist/esm/pseudo/malware.d.ts +2 -1
  37. package/dist/esm/pseudo/malware.d.ts.map +1 -1
  38. package/dist/esm/pseudo/malware.js +1 -1
  39. package/dist/esm/pseudo/malware.js.map +1 -1
  40. package/dist/esm/pseudo/outdated.d.ts +2 -1
  41. package/dist/esm/pseudo/outdated.d.ts.map +1 -1
  42. package/dist/esm/pseudo/outdated.js +4 -4
  43. package/dist/esm/pseudo/outdated.js.map +1 -1
  44. package/dist/esm/pseudo/published.d.ts +2 -1
  45. package/dist/esm/pseudo/published.d.ts.map +1 -1
  46. package/dist/esm/pseudo/published.js +2 -3
  47. package/dist/esm/pseudo/published.js.map +1 -1
  48. package/dist/esm/pseudo/root.d.ts +8 -0
  49. package/dist/esm/pseudo/root.d.ts.map +1 -0
  50. package/dist/esm/pseudo/root.js +22 -0
  51. package/dist/esm/pseudo/root.js.map +1 -0
  52. package/dist/esm/pseudo/score.d.ts +2 -1
  53. package/dist/esm/pseudo/score.d.ts.map +1 -1
  54. package/dist/esm/pseudo/score.js +1 -1
  55. package/dist/esm/pseudo/score.js.map +1 -1
  56. package/dist/esm/pseudo/semver.d.ts +2 -1
  57. package/dist/esm/pseudo/semver.d.ts.map +1 -1
  58. package/dist/esm/pseudo/semver.js +3 -2
  59. package/dist/esm/pseudo/semver.js.map +1 -1
  60. package/dist/esm/pseudo/severity.d.ts +2 -1
  61. package/dist/esm/pseudo/severity.d.ts.map +1 -1
  62. package/dist/esm/pseudo/severity.js +1 -1
  63. package/dist/esm/pseudo/severity.js.map +1 -1
  64. package/dist/esm/pseudo/squat.d.ts +2 -1
  65. package/dist/esm/pseudo/squat.d.ts.map +1 -1
  66. package/dist/esm/pseudo/squat.js +1 -1
  67. package/dist/esm/pseudo/squat.js.map +1 -1
  68. package/dist/esm/pseudo/type.d.ts +8 -0
  69. package/dist/esm/pseudo/type.d.ts.map +1 -0
  70. package/dist/esm/pseudo/type.js +22 -0
  71. package/dist/esm/pseudo/type.js.map +1 -0
  72. package/dist/esm/pseudo/workspace.d.ts.map +1 -1
  73. package/dist/esm/pseudo/workspace.js +5 -2
  74. package/dist/esm/pseudo/workspace.js.map +1 -1
  75. package/dist/esm/pseudo.d.ts.map +1 -1
  76. package/dist/esm/pseudo.js +21 -38
  77. package/dist/esm/pseudo.js.map +1 -1
  78. package/dist/esm/types.d.ts +9 -19
  79. package/dist/esm/types.d.ts.map +1 -1
  80. package/dist/esm/types.js +1 -105
  81. package/dist/esm/types.js.map +1 -1
  82. package/package.json +13 -12
package/README.md CHANGED
@@ -17,16 +17,47 @@ const res = await query.search(':root > *')
17
17
 
18
18
  ## Examples
19
19
 
20
- Querying nodes from a local `node_modules` folder.
20
+ ### Querying against an ideal/virtual graph
21
+
22
+ ```js
23
+ import { ideal } from '@vltpkg/graph'
24
+ import { Query } from '@vltpkg/query'
25
+ import { PackageJson } from '@vltpkg/package-json'
26
+ const signal = new AbortController().signal
27
+ const projectRoot = process.cwd()
28
+ const packageJson = new PackageJson()
29
+ const graph = await ideal.build({ projectRoot, packageJson })
30
+ const query = new Query({ graph })
31
+ const res = await query.search(':root > *', { signal })
32
+ ```
33
+
34
+ ### Querying against a local `node_modules` folder
21
35
 
22
36
  ```js
23
37
  import { actual } from '@vltpkg/graph'
24
38
  import { Query } from '@vltpkg/query'
39
+ import { PackageJson } from '@vltpkg/package-json'
40
+ import { PathScurry } from 'path-scurry'
41
+ const signal = new AbortController().signal
42
+ const projectRoot = process.cwd()
43
+ const scurry = new PathScurry(projectRoot)
44
+ const packageJson = new PackageJson()
45
+ const graph = await actual.load({ projectRoot, packageJson, scurry })
46
+ const query = new Query({ graph })
47
+ const res = await query.search(':root > *', { signal })
48
+ ```
25
49
 
26
- const specOptions = {
27
- registry: 'https://registry.npmjs.org',
28
- }
29
- const graph = await actual.load({ projectRoot: process.cwd() })
30
- const query = new Query({ graph, specOptions })
31
- const res = await query.search(':root > *')
50
+ ### Querying against a lockfile
51
+
52
+ ```js
53
+ import { lockfile } from '@vltpkg/graph'
54
+ import { Query } from '@vltpkg/query'
55
+ const signal = new AbortController().signal
56
+ const projectRoot = process.cwd()
57
+ const graph = await lockfile.load({
58
+ mainManifest: 'package.json',
59
+ projectRoot,
60
+ })
61
+ const query = new Query({ graph })
62
+ const res = await query.search(':root > *', { signal })
32
63
  ```
@@ -1 +1 @@
1
- {"version":3,"file":"attribute.d.ts","sourceRoot":"","sources":["../../src/attribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAG7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,OAAO,CAAA;AAOpE;;;GAGG;AACH,eAAO,MAAM,yBAAyB,SAC9B,QAAQ,cACF,MAAM,EAAE,aACT,MAAM,KAChB,MAAM,EAAE,GAAG,SA+Db,CAAA;AAID,eAAO,MAAM,gBAAgB,UACpB,WAAW,cACN,YAAY,GAAG,SAAS,SAC7B,MAAM,gBACC,MAAM,eACP,OAAO,qBACF,MAAM,EAAE,KACzB,WAgDF,CAAA;AAcD,eAAO,MAAM,qBAAqB,2BAEjC,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,SAAS,UACb,WAAW,KACjB,OAAO,CAAC,WAAW,CAyBrB,CAAA"}
1
+ {"version":3,"file":"attribute.d.ts","sourceRoot":"","sources":["../../src/attribute.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAE7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,OAAO,CAAA;AAOpE;;;GAGG;AACH,eAAO,MAAM,yBAAyB,SAC9B,QAAQ,cACF,MAAM,EAAE,aACT,MAAM,KAChB,MAAM,EAAE,GAAG,SA+Db,CAAA;AAID,eAAO,MAAM,gBAAgB,UACpB,WAAW,cACN,YAAY,GAAG,SAAS,SAC7B,MAAM,gBACC,MAAM,eACP,OAAO,qBACF,MAAM,EAAE,KACzB,WAsCF,CAAA;AAcD,eAAO,MAAM,qBAAqB,2BAEjC,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,SAAS,UACb,WAAW,KACjB,OAAO,CAAC,WAAW,CA6BrB,CAAA"}
@@ -1,5 +1,6 @@
1
+ import { asAttributeNode } from '@vltpkg/dss-parser';
1
2
  import { error } from '@vltpkg/error-cause';
2
- import { asAttributeNode } from "./types.js";
3
+ import { removeDanglingEdges } from "./pseudo/helpers.js";
3
4
  // JSONField has a mapped type constituent that would coerce to [object Object]
4
5
  // when stringified, which is what we want in this case.
5
6
  // eslint-disable-next-line @typescript-eslint/no-base-to-string
@@ -93,17 +94,7 @@ export const filterAttributes = (state, comparator, value, propertyName, insensi
93
94
  deleteNode(node);
94
95
  }
95
96
  }
96
- for (const edge of state.partial.edges) {
97
- // edge.name is a special case in order
98
- // to be able to match missing nodes by name
99
- if (propertyName === 'name' && check(edge.name)) {
100
- continue;
101
- }
102
- // remove any remaining dangling edge
103
- if (!edge.to) {
104
- state.partial.edges.delete(edge);
105
- }
106
- }
97
+ removeDanglingEdges(state);
107
98
  return state;
108
99
  };
109
100
  // ref: https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors
@@ -135,6 +126,8 @@ export const attribute = async (state) => {
135
126
  const value = curr.value || '';
136
127
  const propertyName = curr.attribute;
137
128
  const insensitive = !!curr.insensitive;
129
+ // Increment the commonCounter for specificity
130
+ state.specificity.commonCounter += 1;
138
131
  return filterAttributes(state, operatorFn, value, propertyName, insensitive);
139
132
  };
140
133
  //# sourceMappingURL=attribute.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"attribute.js","sourceRoot":"","sources":["../../src/attribute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CA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UAAU,GAAG,qBAAqB,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAA;IACnE,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YAChB,OAAO,KAAK,CAAA;QACd,CAAC;QAED,MAAM,KAAK,CAAC,mCAAmC,IAAI,CAAC,QAAQ,EAAE,EAAE;YAC9D,KAAK,EAAE,KAAK,CAAC,OAAO;SACrB,CAAC,CAAA;IACJ,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,CAAA;IAC9B,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAA;IACnC,MAAM,WAAW,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAA;IACtC,OAAO,gBAAgB,CACrB,KAAK,EACL,UAAU,EACV,KAAK,EACL,YAAY,EACZ,WAAW,CACZ,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport type { NodeLike } from '@vltpkg/graph'\nimport type { JSONField, Manifest } from '@vltpkg/types'\nimport { asAttributeNode } from './types.ts'\nimport type { ParserState } from './types.ts'\n\nexport type ComparatorFn = (attr: string, value?: string) => boolean\n\n// JSONField has a mapped type constituent that would coerce to [object Object]\n// when stringified, which is what we want in this case.\n// eslint-disable-next-line @typescript-eslint/no-base-to-string\nconst jsonFieldToString = (v: JSONField) => String(v)\n\n/**\n * Retrieve the {@link Manifest} values found at the given `properties`\n * location for a given {@link Node}.\n */\nexport const getManifestPropertyValues = (\n node: NodeLike,\n properties: string[],\n attribute: string,\n): string[] | undefined => {\n if (!node.manifest) return\n\n const traverse = new Set<JSONField>([node.manifest as JSONField])\n const props = new Set<JSONField>()\n for (const key of properties) {\n for (const prop of traverse) {\n /* c8 ignore start - should be impossible */\n if (!prop) {\n throw error('failed to find nested property in :attr', {\n found: properties,\n })\n }\n /* c8 ignore stop */\n\n // expand the result list to include nested array values\n if (Array.isArray(prop)) {\n for (const p of prop) {\n traverse.add(p)\n }\n continue\n }\n\n // guard for inspecting keys of objects next\n if (\n typeof prop === 'string' ||\n typeof prop === 'number' ||\n typeof prop === 'boolean'\n ) {\n continue\n }\n\n // assign next value when found\n if (key in prop) {\n const nextValue = prop[key]\n if (nextValue) {\n if (key === attribute) {\n props.add(nextValue)\n } else {\n traverse.delete(prop)\n traverse.add(nextValue)\n }\n }\n }\n }\n }\n // if no value was found after trying a given key\n // then there's nothing to be collected\n if (!props.size) return\n\n // expand the result to include array values\n const collect = new Set<string>()\n for (const prop of props) {\n if (Array.isArray(prop)) {\n for (const p of prop) {\n collect.add(p ? jsonFieldToString(p) : '')\n }\n } else {\n collect.add(jsonFieldToString(prop))\n }\n }\n\n return [...collect]\n}\n\n// decorator style of function that will filter `ParserState` results\n// based on a provided `comparator` function\nexport const filterAttributes = (\n state: ParserState,\n comparator: ComparatorFn | undefined,\n value: string,\n propertyName: string,\n insensitive: boolean,\n prefixProperties: string[] = [],\n): ParserState => {\n const check = (attr: JSONField) =>\n comparator?.(\n insensitive ?\n jsonFieldToString(attr).toLowerCase()\n : jsonFieldToString(attr),\n insensitive ? value.toLowerCase() : value,\n )\n const deleteNode = (node: NodeLike) => {\n for (const edge of node.edgesIn) {\n state.partial.edges.delete(edge)\n }\n state.partial.nodes.delete(node)\n }\n\n for (const node of state.partial.nodes) {\n const prefixes =\n prefixProperties.length ? prefixProperties : [propertyName]\n const attrs = getManifestPropertyValues(\n node,\n prefixes,\n propertyName,\n )\n\n // if no attribute value was found, that means the attribute won't match\n if (!attrs?.length) {\n deleteNode(node)\n continue\n }\n\n // if the node attribute value won't match, then remove the node\n if (comparator && !attrs.some(check)) {\n deleteNode(node)\n }\n }\n\n for (const edge of state.partial.edges) {\n // edge.name is a special case in order\n // to be able to match missing nodes by name\n if (propertyName === 'name' && check(edge.name)) {\n continue\n }\n // remove any remaining dangling edge\n if (!edge.to) {\n state.partial.edges.delete(edge)\n }\n }\n return state\n}\n\n// ref: https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors\nconst attributeSelectors: Record<string, ComparatorFn> = {\n '=': (attr: string, value = '') => attr === value,\n '^=': (attr: string, value = '') => attr.startsWith(value),\n '$=': (attr: string, value = '') => attr.endsWith(value),\n '~=': (attr: string, value = '') =>\n new Set<string>(attr.match(/\\w+/g)).has(value),\n '*=': (attr: string, value = '') => attr.includes(value),\n '|=': (attr: string, value = '') =>\n attr === value || attr.startsWith(`${value}-`),\n undefined: (attr: string) => !!attr,\n}\nexport const attributeSelectorsMap = new Map<string, ComparatorFn>(\n Object.entries(attributeSelectors),\n)\n\n/**\n * Parse attributes selectors, e.g: `[name]`, `[name=value]`, etc\n */\nexport const attribute = async (\n state: ParserState,\n): Promise<ParserState> => {\n await state.cancellable()\n\n const curr = asAttributeNode(state.current)\n const operatorFn = attributeSelectorsMap.get(String(curr.operator))\n if (!operatorFn) {\n if (state.loose) {\n return state\n }\n\n throw error(`Unsupported attribute operator: ${curr.operator}`, {\n found: state.current,\n })\n }\n\n const value = curr.value || ''\n const propertyName = curr.attribute\n const insensitive = !!curr.insensitive\n return filterAttributes(\n state,\n operatorFn,\n value,\n propertyName,\n insensitive,\n )\n}\n"]}
1
+ {"version":3,"file":"attribute.js","sourceRoot":"","sources":["../../src/attribute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAOzD,+EAA+E;AAC/E,wDAAwD;AACxD,gEAAgE;AAChE,MAAM,iBAAiB,GAAG,CAAC,CAAY,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;AAErD;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,IAAc,EACd,UAAoB,EACpB,SAAiB,EACK,EAAE;IACxB,IAAI,CA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,EACL,YAAY,EACZ,WAAW,CACZ,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { asAttributeNode } from '@vltpkg/dss-parser'\nimport { error } from '@vltpkg/error-cause'\nimport { removeDanglingEdges } from './pseudo/helpers.ts'\nimport type { NodeLike } from '@vltpkg/graph'\nimport type { JSONField, Manifest } from '@vltpkg/types'\nimport type { ParserState } from './types.ts'\n\nexport type ComparatorFn = (attr: string, value?: string) => boolean\n\n// JSONField has a mapped type constituent that would coerce to [object Object]\n// when stringified, which is what we want in this case.\n// eslint-disable-next-line @typescript-eslint/no-base-to-string\nconst jsonFieldToString = (v: JSONField) => String(v)\n\n/**\n * Retrieve the {@link Manifest} values found at the given `properties`\n * location for a given {@link Node}.\n */\nexport const getManifestPropertyValues = (\n node: NodeLike,\n properties: string[],\n attribute: string,\n): string[] | undefined => {\n if (!node.manifest) return\n\n const traverse = new Set<JSONField>([node.manifest as JSONField])\n const props = new Set<JSONField>()\n for (const key of properties) {\n for (const prop of traverse) {\n /* c8 ignore start - should be impossible */\n if (!prop) {\n throw error('failed to find nested property in :attr', {\n found: properties,\n })\n }\n /* c8 ignore stop */\n\n // expand the result list to include nested array values\n if (Array.isArray(prop)) {\n for (const p of prop) {\n traverse.add(p)\n }\n continue\n }\n\n // guard for inspecting keys of objects next\n if (\n typeof prop === 'string' ||\n typeof prop === 'number' ||\n typeof prop === 'boolean'\n ) {\n continue\n }\n\n // assign next value when found\n if (key in prop) {\n const nextValue = prop[key]\n if (nextValue) {\n if (key === attribute) {\n props.add(nextValue)\n } else {\n traverse.delete(prop)\n traverse.add(nextValue)\n }\n }\n }\n }\n }\n // if no value was found after trying a given key\n // then there's nothing to be collected\n if (!props.size) return\n\n // expand the result to include array values\n const collect = new Set<string>()\n for (const prop of props) {\n if (Array.isArray(prop)) {\n for (const p of prop) {\n collect.add(p ? jsonFieldToString(p) : '')\n }\n } else {\n collect.add(jsonFieldToString(prop))\n }\n }\n\n return [...collect]\n}\n\n// decorator style of function that will filter `ParserState` results\n// based on a provided `comparator` function\nexport const filterAttributes = (\n state: ParserState,\n comparator: ComparatorFn | undefined,\n value: string,\n propertyName: string,\n insensitive: boolean,\n prefixProperties: string[] = [],\n): ParserState => {\n const check = (attr: JSONField) =>\n comparator?.(\n insensitive ?\n jsonFieldToString(attr).toLowerCase()\n : jsonFieldToString(attr),\n insensitive ? value.toLowerCase() : value,\n )\n const deleteNode = (node: NodeLike) => {\n for (const edge of node.edgesIn) {\n state.partial.edges.delete(edge)\n }\n state.partial.nodes.delete(node)\n }\n\n for (const node of state.partial.nodes) {\n const prefixes =\n prefixProperties.length ? prefixProperties : [propertyName]\n const attrs = getManifestPropertyValues(\n node,\n prefixes,\n propertyName,\n )\n\n // if no attribute value was found, that means the attribute won't match\n if (!attrs?.length) {\n deleteNode(node)\n continue\n }\n\n // if the node attribute value won't match, then remove the node\n if (comparator && !attrs.some(check)) {\n deleteNode(node)\n }\n }\n\n removeDanglingEdges(state)\n return state\n}\n\n// ref: https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors\nconst attributeSelectors: Record<string, ComparatorFn> = {\n '=': (attr: string, value = '') => attr === value,\n '^=': (attr: string, value = '') => attr.startsWith(value),\n '$=': (attr: string, value = '') => attr.endsWith(value),\n '~=': (attr: string, value = '') =>\n new Set<string>(attr.match(/\\w+/g)).has(value),\n '*=': (attr: string, value = '') => attr.includes(value),\n '|=': (attr: string, value = '') =>\n attr === value || attr.startsWith(`${value}-`),\n undefined: (attr: string) => !!attr,\n}\nexport const attributeSelectorsMap = new Map<string, ComparatorFn>(\n Object.entries(attributeSelectors),\n)\n\n/**\n * Parse attributes selectors, e.g: `[name]`, `[name=value]`, etc\n */\nexport const attribute = async (\n state: ParserState,\n): Promise<ParserState> => {\n await state.cancellable()\n\n const curr = asAttributeNode(state.current)\n const operatorFn = attributeSelectorsMap.get(String(curr.operator))\n if (!operatorFn) {\n if (state.loose) {\n return state\n }\n\n throw error(`Unsupported attribute operator: ${curr.operator}`, {\n found: state.current,\n })\n }\n\n const value = curr.value || ''\n const propertyName = curr.attribute\n const insensitive = !!curr.insensitive\n\n // Increment the commonCounter for specificity\n state.specificity.commonCounter += 1\n\n return filterAttributes(\n state,\n operatorFn,\n value,\n propertyName,\n insensitive,\n )\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"combinator.d.ts","sourceRoot":"","sources":["../../src/combinator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAY,MAAM,YAAY,CAAA;AA8GvD;;GAEG;AACH,eAAO,MAAM,UAAU,UAAiB,WAAW,yBAgBlD,CAAA"}
1
+ {"version":3,"file":"combinator.d.ts","sourceRoot":"","sources":["../../src/combinator.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAY,MAAM,YAAY,CAAA;AA6GvD;;GAEG;AACH,eAAO,MAAM,UAAU,UAAiB,WAAW,yBAgBlD,CAAA"}
@@ -1,4 +1,4 @@
1
- import { asCombinatorNode } from "./types.js";
1
+ import { asCombinatorNode } from '@vltpkg/dss-parser';
2
2
  import { error } from '@vltpkg/error-cause';
3
3
  /**
4
4
  * Returns a new set of nodes, containing all direct dependencies
@@ -1 +1 @@
1
- {"version":3,"file":"combinator.js","sourceRoot":"","sources":["../../src/combinator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAE7C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAE3C;;;;;GAKG;AACH,MAAM,eAAe,GAAG,KAAK,EAAE,KAAkB,EAAE,EAAE;IACnD,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC7C,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;IAC3B,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;IAE3B,qDAAqD;IACrD,uDAAuD;IACvD,kBAAkB;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pB,GAAG,EAAE,2BAA2B;IAChC,GAAG,EAAE,oBAAoB;CAC1B,CAAA;AAED,MAAM,sBAAsB,GAAG,IAAI,GAAG,CACpC,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,CACpC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAAE,KAAkB,EAAE,EAAE;IACrD,MAAM,KAAK,CAAC,WAAW,EAAE,CAAA;IAEzB,MAAM,IAAI,GAAG,gBAAgB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAC5C,MAAM,QAAQ,GACZ,IAAI,CAAC,KAAK,IAAI,sBAAsB,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACtD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YAChB,OAAO,KAAK,CAAA;QACd,CAAC;QAED,MAAM,KAAK,CAAC,2BAA2B,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE;YAC5D,KAAK,EAAE,KAAK,CAAC,OAAO;SACrB,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAA;AACxB,CAAC,CAAA","sourcesContent":["import type { EdgeLike, NodeLike } from '@vltpkg/graph'\nimport { asCombinatorNode } from './types.ts'\nimport type { ParserState, ParserFn } from './types.ts'\nimport { error } from '@vltpkg/error-cause'\n\n/**\n * Returns a new set of nodes, containing all direct dependencies\n * of the current list of nodes used.\n *\n * ref: https://developer.mozilla.org/en-US/docs/Web/CSS/Child_combinator\n */\nconst childCombinator = async (state: ParserState) => {\n const traverse = new Set(state.partial.nodes)\n state.partial.edges.clear()\n state.partial.nodes.clear()\n\n // visit direct children of the current list of nodes\n // collecting refs to these children and the edges that\n // connected them.\n for (const node of traverse) {\n for (const edge of node.edgesOut.values()) {\n if (edge.to) {\n state.partial.edges.add(edge)\n state.partial.nodes.add(edge.to)\n }\n }\n }\n\n return state\n}\n\n/**\n * Returns a new set of nodes, containing nodes that are also children\n * of all parent nodes to the current list of nodes used.\n *\n * Note: The subsequent-sibling comparator has a behavior that is\n * somehow approximative of that of its css counterpart, given that\n * in the context of dependency graphs the order of appearance is\n * not necessarily controlled by the end user. The approach for\n * this comparator is to match all siblings of a node.\n *\n * ref: https://developer.mozilla.org/en-US/docs/Web/CSS/Subsequent-sibling_combinator\n */\nconst subsequentSiblingCombinator = async (state: ParserState) => {\n const traverse = new Set(state.partial.nodes)\n state.partial.edges.clear()\n state.partial.nodes.clear()\n\n // visits direct parents of the current list of node and then\n // visit their children, collecting refs to all children and edges\n // that are not in the original list of nodes.\n for (const node of traverse) {\n for (const edge of node.edgesIn) {\n const parents: IterableIterator<EdgeLike> =\n edge.from.edgesOut.values()\n for (const edge of parents) {\n if (edge.to && edge.to !== node) {\n state.partial.edges.add(edge)\n state.partial.nodes.add(edge.to)\n }\n }\n }\n }\n\n return state\n}\n\n/**\n * Returns a new set of nodes containing all nodes that are descendents\n * to items in the current list of nodes.\n *\n * ref: https://developer.mozilla.org/en-US/docs/Web/CSS/Descendant_combinator\n */\nconst descendentCombinator = async (state: ParserState) => {\n // spaces between tags selectors are a noop\n if (state.prev?.type === 'tag' || state.next?.type === 'tag') {\n return state\n }\n\n const traverse = new Set<NodeLike>(state.partial.nodes)\n state.partial.edges.clear()\n state.partial.nodes.clear()\n\n // breadth-first traversal of the graph, starting from the current\n // list of nodes, collecting all nodes and edges along the way\n for (const node of traverse) {\n const children = new Set<NodeLike>()\n for (const edge of node.edgesOut.values()) {\n if (edge.to) {\n children.add(edge.to)\n state.partial.edges.add(edge)\n state.partial.nodes.add(edge.to)\n }\n }\n for (const child of children) {\n traverse.add(child)\n }\n }\n\n return state\n}\n\nconst combinatorSelectors = {\n '>': childCombinator,\n '~': subsequentSiblingCombinator,\n ' ': descendentCombinator,\n}\n\nconst combinatorSelectorsMap = new Map<string, ParserFn>(\n Object.entries(combinatorSelectors),\n)\n\n/**\n * Parse css-style combinators, e.g: `>`, `~` and ` `\n */\nexport const combinator = async (state: ParserState) => {\n await state.cancellable()\n\n const curr = asCombinatorNode(state.current)\n const parserFn =\n curr.value && combinatorSelectorsMap.get(curr.value)\n if (!parserFn) {\n if (state.loose) {\n return state\n }\n\n throw error(`Unsupported combinator: ${state.current.value}`, {\n found: state.current,\n })\n }\n return parserFn(state)\n}\n"]}
1
+ {"version":3,"file":"combinator.js","sourceRoot":"","sources":["../../src/combinator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAI3C;;;;;GAKG;AACH,MAAM,eAAe,GAAG,KAAK,EAAE,KAAkB,EAAE,EAAE;IACnD,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC7C,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;IAC3B,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;IAE3B,qDAAqD;IACrD,uDAAuD;IACvD,kBAAkB;IAClB,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;QAC5B,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;YAC1C,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;gBACZ,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;gBAC7B,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;YAClC,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED;;;;;;;;;;;GAWG;AACH,MAAM,2BAA2B,GAAG,KAAK,EAAE,KAAkB,EAAE,EAAE;IAC/D,M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d,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YAChB,OAAO,KAAK,CAAA;QACd,CAAC;QAED,MAAM,KAAK,CAAC,2BAA2B,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE;YAC5D,KAAK,EAAE,KAAK,CAAC,OAAO;SACrB,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAA;AACxB,CAAC,CAAA","sourcesContent":["import { asCombinatorNode } from '@vltpkg/dss-parser'\nimport { error } from '@vltpkg/error-cause'\nimport type { EdgeLike, NodeLike } from '@vltpkg/graph'\nimport type { ParserState, ParserFn } from './types.ts'\n\n/**\n * Returns a new set of nodes, containing all direct dependencies\n * of the current list of nodes used.\n *\n * ref: https://developer.mozilla.org/en-US/docs/Web/CSS/Child_combinator\n */\nconst childCombinator = async (state: ParserState) => {\n const traverse = new Set(state.partial.nodes)\n state.partial.edges.clear()\n state.partial.nodes.clear()\n\n // visit direct children of the current list of nodes\n // collecting refs to these children and the edges that\n // connected them.\n for (const node of traverse) {\n for (const edge of node.edgesOut.values()) {\n if (edge.to) {\n state.partial.edges.add(edge)\n state.partial.nodes.add(edge.to)\n }\n }\n }\n\n return state\n}\n\n/**\n * Returns a new set of nodes, containing nodes that are also children\n * of all parent nodes to the current list of nodes used.\n *\n * Note: The subsequent-sibling comparator has a behavior that is\n * somehow approximative of that of its css counterpart, given that\n * in the context of dependency graphs the order of appearance is\n * not necessarily controlled by the end user. The approach for\n * this comparator is to match all siblings of a node.\n *\n * ref: https://developer.mozilla.org/en-US/docs/Web/CSS/Subsequent-sibling_combinator\n */\nconst subsequentSiblingCombinator = async (state: ParserState) => {\n const traverse = new Set(state.partial.nodes)\n state.partial.edges.clear()\n state.partial.nodes.clear()\n\n // visits direct parents of the current list of node and then\n // visit their children, collecting refs to all children and edges\n // that are not in the original list of nodes.\n for (const node of traverse) {\n for (const edge of node.edgesIn) {\n const parents: IterableIterator<EdgeLike> =\n edge.from.edgesOut.values()\n for (const edge of parents) {\n if (edge.to && edge.to !== node) {\n state.partial.edges.add(edge)\n state.partial.nodes.add(edge.to)\n }\n }\n }\n }\n\n return state\n}\n\n/**\n * Returns a new set of nodes containing all nodes that are descendents\n * to items in the current list of nodes.\n *\n * ref: https://developer.mozilla.org/en-US/docs/Web/CSS/Descendant_combinator\n */\nconst descendentCombinator = async (state: ParserState) => {\n // spaces between tags selectors are a noop\n if (state.prev?.type === 'tag' || state.next?.type === 'tag') {\n return state\n }\n\n const traverse = new Set<NodeLike>(state.partial.nodes)\n state.partial.edges.clear()\n state.partial.nodes.clear()\n\n // breadth-first traversal of the graph, starting from the current\n // list of nodes, collecting all nodes and edges along the way\n for (const node of traverse) {\n const children = new Set<NodeLike>()\n for (const edge of node.edgesOut.values()) {\n if (edge.to) {\n children.add(edge.to)\n state.partial.edges.add(edge)\n state.partial.nodes.add(edge.to)\n }\n }\n for (const child of children) {\n traverse.add(child)\n }\n }\n\n return state\n}\n\nconst combinatorSelectors = {\n '>': childCombinator,\n '~': subsequentSiblingCombinator,\n ' ': descendentCombinator,\n}\n\nconst combinatorSelectorsMap = new Map<string, ParserFn>(\n Object.entries(combinatorSelectors),\n)\n\n/**\n * Parse css-style combinators, e.g: `>`, `~` and ` `\n */\nexport const combinator = async (state: ParserState) => {\n await state.cancellable()\n\n const curr = asCombinatorNode(state.current)\n const parserFn =\n curr.value && combinatorSelectorsMap.get(curr.value)\n if (!parserFn) {\n if (state.loose) {\n return state\n }\n\n throw error(`Unsupported combinator: ${state.current.value}`, {\n found: state.current,\n })\n }\n return parserFn(state)\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../../src/id.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C;;GAEG;AACH,eAAO,MAAM,EAAE,UACN,WAAW,KACjB,OAAO,CAAC,WAAW,CAiCrB,CAAA"}
1
+ {"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../../src/id.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C;;GAEG;AACH,eAAO,MAAM,EAAE,UACN,WAAW,KACjB,OAAO,CAAC,WAAW,CAoCrB,CAAA"}
package/dist/esm/id.js CHANGED
@@ -1,5 +1,5 @@
1
+ import { asIdentifierNode } from '@vltpkg/dss-parser';
1
2
  import { error } from '@vltpkg/error-cause';
2
- import { asIdentifierNode } from "./types.js";
3
3
  /**
4
4
  * Parse ids, e.g: `#foo`
5
5
  */
@@ -29,6 +29,8 @@ export const id = async (state) => {
29
29
  state.partial.nodes.delete(node);
30
30
  }
31
31
  }
32
+ // Increment the idCounter for specificity
33
+ state.specificity.idCounter += 1;
32
34
  return state;
33
35
  };
34
36
  //# sourceMappingURL=id.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"id.js","sourceRoot":"","sources":["../../src/id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAG7C;;GAEG;AACH,MAAM,CAAC,MAAM,EAAE,GAAG,KAAK,EACrB,KAAkB,EACI,EAAE;IACxB,MAAM,EAAE,KAAK,EAAE,GAAG,gBAAgB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAEjD,8CAA8C;IAC9C,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,KAAK,CAAC,yBAAyB,CAAC,CAAA;IACxC,CAAC;IACD,oBAAoB;IAEpB,wCAAwC;IACxC,yCAAyC;IACzC,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACvC,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;YACxB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;YAChC,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;gBACZ,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;YACrC,CAAC;QACH,CAAC;IACH,CAAC;IAED,uDAAuD;IACvD,yDAAyD;IACzD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACvC,IACE,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC;YACvB,IAAI,CAAC,IAAI,KAAK,KAAK;YACnB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAC7B,CAAC;YACD,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QAClC,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport { asIdentifierNode } from './types.ts'\nimport type { ParserState } from './types.ts'\n\n/**\n * Parse ids, e.g: `#foo`\n */\nexport const id = async (\n state: ParserState,\n): Promise<ParserState> => {\n const { value } = asIdentifierNode(state.current)\n\n /* c8 ignore start - should not be possible */\n if (!value) {\n throw error('Missing identifier name')\n }\n /* c8 ignore stop */\n\n // Filter out any edges and their linked\n // nodes if they don't match the id value\n for (const edge of state.partial.edges) {\n if (edge.name !== value) {\n state.partial.edges.delete(edge)\n if (edge.to) {\n state.partial.nodes.delete(edge.to)\n }\n }\n }\n\n // Filter out importer nodes, this extra step is needed\n // to filter out nodes that have no edges linking to them\n for (const node of state.partial.nodes) {\n if (\n node.edgesIn.size === 0 &&\n node.name !== value &&\n state.partial.nodes.has(node)\n ) {\n state.partial.nodes.delete(node)\n }\n }\n\n return state\n}\n"]}
1
+ {"version":3,"file":"id.js","sourceRoot":"","sources":["../../src/id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,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from '@vltpkg/error-cause'\nimport type { ParserState } from './types.ts'\n\n/**\n * Parse ids, e.g: `#foo`\n */\nexport const id = async (\n state: ParserState,\n): Promise<ParserState> => {\n const { value } = asIdentifierNode(state.current)\n\n /* c8 ignore start - should not be possible */\n if (!value) {\n throw error('Missing identifier name')\n }\n /* c8 ignore stop */\n\n // Filter out any edges and their linked\n // nodes if they don't match the id value\n for (const edge of state.partial.edges) {\n if (edge.name !== value) {\n state.partial.edges.delete(edge)\n if (edge.to) {\n state.partial.nodes.delete(edge.to)\n }\n }\n }\n\n // Filter out importer nodes, this extra step is needed\n // to filter out nodes that have no edges linking to them\n for (const node of state.partial.nodes) {\n if (\n node.edgesIn.size === 0 &&\n node.name !== value &&\n state.partial.nodes.has(node)\n ) {\n state.partial.nodes.delete(node)\n }\n }\n\n // Increment the idCounter for specificity\n state.specificity.idCounter += 1\n\n return state\n}\n"]}
@@ -27,6 +27,13 @@ export declare class Query {
27
27
  * skip hydrating the security archive if it's not needed.
28
28
  */
29
29
  static hasSecuritySelectors(query: string): boolean;
30
+ /**
31
+ * Sorts an array of QueryResponse objects by specificity. Objects with
32
+ * higher idCounter values come first, if idCounter values are equal,
33
+ * then objects with higher commonCounter values come first. Otherwise,
34
+ * the original order is preserved.
35
+ */
36
+ static specificitySort(responses: QueryResponse[]): QueryResponse[];
30
37
  constructor({ graph, retries, specOptions, securityArchive, }: QueryOptions);
31
38
  /**
32
39
  * Search the graph for nodes and edges that match the given query.
@@ -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;AAcnE,OAAO,KAAK,EAEV,mBAAmB,EAEnB,WAAW,EAEX,aAAa,EAGd,MAAM,YAAY,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AA;AAE3C,cAAc,YAAY,CAAA;AAE1B,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,WAAW,CAAA;IACnB,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAA;CACnB,CAAA;AA+CD,eAAO,MAAM,IAAI,UACR,WAAW,KACjB,OAAO,CAAC,WAAW,CAsDrB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,SAAS,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,WAAW,CAAA;IACxB,eAAe,EAAE,mBAAmB,GAAG,SAAS,CAAA;CACjD,CAAA;AAiDD;;;GAGG;AACH,qBAAa,KAAK;;IAOhB;;;;OAIG;IACH,MAAM,CAAC,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IASnD;;;;;OAKG;IACH,MAAM,CAAC,eAAe,CACpB,SAAS,EAAE,aAAa,EAAE,GACzB,aAAa,EAAE;gBAqBN,EACV,KAAK,EACL,OAAO,EACP,WAAW,EACX,eAAe,GAChB,EAAE,YAAY;IAuLf;;OAEG;IACG,MAAM,CACV,KAAK,EAAE,MAAM,EACb,EACE,MAAM,EACN,QAA0C,GAC3C,EAAE,aAAa,GACf,OAAO,CAAC,aAAa,CAAC;IAmEzB;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,mBAAmB,EAAE;CAmE5D"}
package/dist/esm/index.js CHANGED
@@ -1,11 +1,10 @@
1
1
  import { error } from '@vltpkg/error-cause';
2
- import { parse } from "./parser.js";
2
+ import { joinDepIDTuple } from '@vltpkg/dep-id/browser';
3
+ import { parse, isPostcssNodeWithChildren, asPostcssNodeWithChildren, isSelectorNode, isPseudoNode, isIdentifierNode, isAttributeNode, } from '@vltpkg/dss-parser';
3
4
  import { attribute } from "./attribute.js";
4
5
  import { combinator } from "./combinator.js";
5
6
  import { id } from "./id.js";
6
7
  import { pseudo } from "./pseudo.js";
7
- import { isPostcssNodeWithChildren, asPostcssNodeWithChildren, isSelectorNode, isPseudoNode, isIdentifierNode, isAttributeNode, } from "./types.js";
8
- import { joinDepIDTuple } from '@vltpkg/dep-id/browser';
9
8
  export * from "./types.js";
10
9
  const noopFn = async (state) => state;
11
10
  const selectors = {
@@ -16,7 +15,17 @@ const selectors = {
16
15
  },
17
16
  /* c8 ignore end */
18
17
  combinator,
19
- comment: noopFn,
18
+ comment: async (state) => {
19
+ if (state.current.value && !state.comment) {
20
+ const commentValue = state.current.value;
21
+ const cleanComment = commentValue
22
+ .replace(/^\/\*/, '')
23
+ .replace(/\*\/$/, '')
24
+ .trim();
25
+ state.comment = cleanComment;
26
+ }
27
+ return state;
28
+ },
20
29
  id,
21
30
  nesting: noopFn,
22
31
  pseudo,
@@ -148,6 +157,26 @@ export class Query {
148
157
  }
149
158
  return false;
150
159
  }
160
+ /**
161
+ * Sorts an array of QueryResponse objects by specificity. Objects with
162
+ * higher idCounter values come first, if idCounter values are equal,
163
+ * then objects with higher commonCounter values come first. Otherwise,
164
+ * the original order is preserved.
165
+ */
166
+ static specificitySort(responses) {
167
+ return [...responses].sort((a, b) => {
168
+ // First compare by idCounter (higher comes first)
169
+ if (a.specificity.idCounter !== b.specificity.idCounter) {
170
+ return b.specificity.idCounter - a.specificity.idCounter;
171
+ }
172
+ // If idCounter values are equal, compare by commonCounter
173
+ if (a.specificity.commonCounter !== b.specificity.commonCounter) {
174
+ return (b.specificity.commonCounter - a.specificity.commonCounter);
175
+ }
176
+ // If both counters are equal, preserve original order
177
+ return 0;
178
+ });
179
+ }
151
180
  constructor({ graph, retries, specOptions, securityArchive, }) {
152
181
  this.#cache = new Map();
153
182
  this.#graph = graph;
@@ -178,10 +207,8 @@ export class Query {
178
207
  abandoned: securityArchiveEntry.alerts.some(i => i.type === 'missingAuthor'),
179
208
  confused: securityArchiveEntry.alerts.some(i => i.type === 'manifestConfusion'),
180
209
  cve: securityArchiveEntry.alerts
181
- .filter(i => i.props?.cveId)
182
- // can not be undefined because of the filter above but TS doesn't know that
183
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
184
- .map(i => i.props?.cveId),
210
+ .map(i => i.props?.cveId)
211
+ .filter(i => i !== undefined),
185
212
  cwe: Array.from(new Set(securityArchiveEntry.alerts
186
213
  .filter(i => i.props?.cveId)
187
214
  .flatMap(i => i.props?.cwes?.map(j => j.id)))),
@@ -243,7 +270,12 @@ export class Query {
243
270
  */
244
271
  async search(query, { signal, scopeIDs = [joinDepIDTuple(['file', '.'])], }) {
245
272
  if (!query)
246
- return { edges: [], nodes: [] };
273
+ return {
274
+ edges: [],
275
+ nodes: [],
276
+ comment: '',
277
+ specificity: { idCounter: 0, commonCounter: 0 },
278
+ };
247
279
  const cachedResult = this.#cache.get(query);
248
280
  if (cachedResult) {
249
281
  return cachedResult;
@@ -260,7 +292,7 @@ export class Query {
260
292
  const loose = asPostcssNodeWithChildren(current).nodes.length > 1;
261
293
  // builds initial state and walks over it,
262
294
  // retrieving the collected result
263
- const { collect } = await walk({
295
+ const { collect, comment, specificity } = await walk({
264
296
  cancellable: async () => {
265
297
  await new Promise(resolve => {
266
298
  setTimeout(resolve, 0);
@@ -276,6 +308,7 @@ export class Query {
276
308
  nodes: new Set(),
277
309
  edges: new Set(),
278
310
  },
311
+ comment: '',
279
312
  loose,
280
313
  partial: { nodes, edges },
281
314
  retries: this.#retries,
@@ -284,10 +317,13 @@ export class Query {
284
317
  specOptions: this.#specOptions,
285
318
  scopeIDs,
286
319
  walk,
320
+ specificity: { idCounter: 0, commonCounter: 0 },
287
321
  });
288
322
  const res = {
289
323
  edges: this.#getQueryResponseEdges(collect.edges),
290
324
  nodes: this.#getQueryResponseNodes(collect.nodes),
325
+ comment,
326
+ specificity,
291
327
  };
292
328
  this.#cache.set(query, res);
293
329
  return res;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAA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I,CAAC,KAAK,CAAC,MAAM,EACjB,CAAC;wBACD,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;wBACnC,KAAK,IAAI,GAAG,CAAA;oBACd,CAAC;oBAED,IACE,CAAC,cAAc,CAAC,IAAI,CAAC;wBACrB,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EACtC,CAAC;wBACD,MAAM,CAAC,IAAI,CAAC;4BACV,GAAG,IAAI;4BACP,KAAK;yBACiB,CAAC,CAAA;oBAC3B,CAAC;gBACH,CAAC;YACH,CAAC;YACD,IAAI,yBAAyB,CAAC,IAAI,CAAC,EAAE,CAAC;gBACpC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;oBAC/B,WAAW,CAAC,KAAK,CAAC,CAAA;gBACpB,CAAC;gBACD,IAAI,YAAY,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;oBAC5C,MAAM,CAAC,IAAI,CAAC;wBACV,GAAG,IAAI;wBACP,KAAK,EAAE,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK;wBAC9B,IAAI,EAAE,QAAQ;qBACQ,CAAC,CAAA;gBAC3B,CAAC;YACH,CAAC;QACH,CAAC,CAAA;QAED,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAA;QACvB,OAAO,MAAM,CAAA;IACf,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 { parse } from './parser.ts'\nimport { attribute } from './attribute.ts'\nimport { combinator } from './combinator.ts'\nimport { id } from './id.ts'\nimport { pseudo } from './pseudo.ts'\nimport {\n isPostcssNodeWithChildren,\n asPostcssNodeWithChildren,\n isSelectorNode,\n isPseudoNode,\n isIdentifierNode,\n isAttributeNode,\n} from './types.ts'\nimport type {\n PostcssNode,\n ParsedSelectorToken,\n PostcssNodeWithChildren,\n ParserState,\n ParserFn,\n QueryResponse,\n QueryResponseNode,\n QueryResponseEdge,\n} from './types.ts'\nimport { joinDepIDTuple } from '@vltpkg/dep-id/browser'\nimport type { DepID } from '@vltpkg/dep-id'\n\nexport * from './types.ts'\n\nexport type SearchOptions = {\n signal: AbortSignal\n scopeIDs?: DepID[]\n}\n\nconst noopFn = async (state: ParserState) => state\n\nconst selectors = {\n attribute,\n /* c8 ignore start */\n class: async (state: ParserState) => {\n throw error('Unsupported selector', { found: state.current })\n },\n /* c8 ignore end */\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 error(\n `Missing parser for query node: ${state.current.type}`,\n {\n found: state.current,\n },\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 retries?: number\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 ':cwe',\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 ':scanned',\n ':score',\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\nconst setMethodToJSON = (node: QueryResponseNode) => {\n const { toJSON } = node\n const insights = node.insights\n node.toJSON = () => ({\n ...toJSON.call(node),\n insights,\n })\n}\n\n/**\n * The Query class is used to search the graph for nodes and edges\n * using the Dependency Selector Syntax (DSS).\n */\nexport class Query {\n #cache: Map<string, QueryResponse>\n #graph: GraphLike\n #retries: number\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({\n graph,\n retries,\n specOptions,\n securityArchive,\n }: QueryOptions) {\n this.#cache = new Map()\n this.#graph = graph\n this.#retries = retries ?? 3\n this.#specOptions = specOptions\n this.#securityArchive = securityArchive\n }\n\n #getQueryResponseEdges(_edges: Set<EdgeLike>): QueryResponseEdge[] {\n return Array.from(_edges) as QueryResponseEdge[]\n }\n\n #getQueryResponseNodes(_nodes: Set<NodeLike>): QueryResponseNode[] {\n const nodes = Array.from(_nodes) as QueryResponseNode[]\n for (const node of nodes) {\n const securityArchiveEntry = this.#securityArchive?.get(node.id)\n\n // if a security archive entry is not found then the insights object\n // should just be empty with scanned=false\n if (!securityArchiveEntry) {\n node.insights = {\n scanned: false,\n }\n\n setMethodToJSON(node)\n continue\n }\n\n // if a security archive entry is found then we can populate the insights\n node.insights = {\n scanned: true,\n score: securityArchiveEntry.score,\n abandoned: securityArchiveEntry.alerts.some(\n i => i.type === 'missingAuthor',\n ),\n confused: securityArchiveEntry.alerts.some(\n i => i.type === 'manifestConfusion',\n ),\n cve: securityArchiveEntry.alerts\n .filter(i => i.props?.cveId)\n // can not be undefined because of the filter above but TS doesn't know that\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain\n .map(i => i.props?.cveId!),\n cwe: Array.from(\n new Set(\n securityArchiveEntry.alerts\n .filter(i => i.props?.cveId)\n .flatMap(i => i.props?.cwes?.map(j => j.id)),\n ),\n ) as `CWE-${string}`[],\n debug: securityArchiveEntry.alerts.some(\n i => i.type === 'debugAccess',\n ),\n deprecated: securityArchiveEntry.alerts.some(\n i => i.type === 'deprecated',\n ),\n dynamic: securityArchiveEntry.alerts.some(\n i => i.type === 'dynamicRequire',\n ),\n entropic: securityArchiveEntry.alerts.some(\n i => i.type === 'highEntropyStrings',\n ),\n env: securityArchiveEntry.alerts.some(\n i => i.type === 'envVars',\n ),\n eval: securityArchiveEntry.alerts.some(\n i => i.type === 'usesEval',\n ),\n fs: securityArchiveEntry.alerts.some(\n i => i.type === 'filesystemAccess',\n ),\n license: {\n unlicensed: securityArchiveEntry.alerts.some(\n i => i.type === 'explicitlyUnlicensedItem',\n ),\n misc: securityArchiveEntry.alerts.some(\n i => i.type === 'miscLicenseIssues',\n ),\n restricted: securityArchiveEntry.alerts.some(\n i => i.type === 'nonpermissiveLicense',\n ),\n ambiguous: securityArchiveEntry.alerts.some(\n i => i.type === 'ambiguousClassifier',\n ),\n copyleft: securityArchiveEntry.alerts.some(\n i => i.type === 'copyleftLicense',\n ),\n unknown: securityArchiveEntry.alerts.some(\n i => i.type === 'unidentifiedLicense',\n ),\n none: securityArchiveEntry.alerts.some(\n i => i.type === 'noLicenseFound',\n ),\n exception: securityArchiveEntry.alerts.some(\n i => i.type === 'licenseException',\n ),\n },\n malware: {\n low: securityArchiveEntry.alerts.some(\n i => i.type === 'gptAnomaly',\n ),\n medium: securityArchiveEntry.alerts.some(\n i => i.type === 'gptSecurity',\n ),\n high: securityArchiveEntry.alerts.some(\n i => i.type === 'gptMalware',\n ),\n critical: securityArchiveEntry.alerts.some(\n i => i.type === 'malware',\n ),\n },\n minified: securityArchiveEntry.alerts.some(\n i => i.type === 'minifiedFile',\n ),\n native: securityArchiveEntry.alerts.some(\n i => i.type === 'hasNativeCode',\n ),\n network: securityArchiveEntry.alerts.some(\n i => i.type === 'networkAccess',\n ),\n obfuscated: securityArchiveEntry.alerts.some(\n i => i.type === 'obfuscatedFile',\n ),\n scripts: securityArchiveEntry.alerts.some(\n i => i.type === 'installScripts',\n ),\n severity: {\n low: securityArchiveEntry.alerts.some(\n i => i.type === 'mildCVE',\n ),\n medium: securityArchiveEntry.alerts.some(\n i => i.type === 'potentialVulnerability',\n ),\n high: securityArchiveEntry.alerts.some(\n i => i.type === 'cve',\n ),\n critical: securityArchiveEntry.alerts.some(\n i => i.type === 'criticalCVE',\n ),\n },\n shell: securityArchiveEntry.alerts.some(\n i => i.type === 'shellAccess',\n ),\n shrinkwrap: securityArchiveEntry.alerts.some(\n i => i.type === 'shrinkwrap',\n ),\n squat: {\n medium: securityArchiveEntry.alerts.some(\n i => i.type === 'gptDidYouMean',\n ),\n critical: securityArchiveEntry.alerts.some(\n i => i.type === 'didYouMean',\n ),\n },\n suspicious: securityArchiveEntry.alerts.some(\n i => i.type === 'suspiciousStarActivity',\n ),\n tracker: securityArchiveEntry.alerts.some(\n i => i.type === 'telemetry',\n ),\n trivial: securityArchiveEntry.alerts.some(\n i => i.type === 'trivialPackage',\n ),\n undesirable: securityArchiveEntry.alerts.some(\n i => i.type === 'troll',\n ),\n unknown: securityArchiveEntry.alerts.some(\n i => i.type === 'newAuthor',\n ),\n unmaintained: securityArchiveEntry.alerts.some(\n i => i.type === 'unmaintained',\n ),\n unpopular: securityArchiveEntry.alerts.some(\n i => i.type === 'unpopularPackage',\n ),\n unstable: securityArchiveEntry.alerts.some(\n i => i.type === 'unstableOwnership',\n ),\n }\n\n setMethodToJSON(node)\n }\n return nodes\n }\n\n /**\n * Search the graph for nodes and edges that match the given query.\n */\n async search(\n query: string,\n {\n signal,\n scopeIDs = [joinDepIDTuple(['file', '.'])],\n }: SearchOptions,\n ): Promise<QueryResponse> {\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 // parse the query string into AST\n const current = parse(query)\n // set loose mode for the entire parse in case there are multiple selectors\n // so that using invalid pseudo selectors or other query language parser\n // errors won't throw an error,\n // e.g: `:root > *, #a, :foo` still returns results for `:root > ` and `#a`\n // while :foo is ignored\n const loose = asPostcssNodeWithChildren(current).nodes.length > 1\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,\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 loose,\n partial: { nodes, edges },\n retries: this.#retries,\n signal,\n securityArchive: this.#securityArchive,\n specOptions: this.#specOptions,\n scopeIDs,\n walk,\n })\n\n const res: QueryResponse = {\n edges: this.#getQueryResponseEdges(collect.edges),\n nodes: this.#getQueryResponseNodes(collect.nodes),\n }\n this.#cache.set(query, res)\n return res\n }\n\n /**\n * Parses a query string in order to retrieve an array of tokens.\n */\n static getQueryTokens(query: string): ParsedSelectorToken[] {\n if (!query) return []\n\n const tokens: ParsedSelectorToken[] = []\n\n const ast = (q: string) => {\n try {\n return parse(q)\n } catch (_e) {\n return ast(q.slice(0, -1))\n }\n }\n\n const processNode = (node: PostcssNode) => {\n for (const key of selectorsMap.keys()) {\n if (node.type === key && node.type !== 'root') {\n let token = `${node.spaces.before}${node.value}${node.spaces.after}`\n\n if (isIdentifierNode(node)) {\n token = `${node.spaces.before}#${node.value}${node.spaces.after}`\n } else if (isSelectorNode(node)) {\n token = `${node.spaces.before},${node.spaces.after}`\n } else if (isAttributeNode(node)) {\n token = String(\n node.source?.start?.column &&\n node.source.end?.column &&\n `${node.spaces.before}${query.slice(node.source.start.column - 1, node.source.end.column)}${node.spaces.after}`,\n )\n }\n\n if (\n isPostcssNodeWithChildren(node) &&\n isPseudoNode(node) &&\n node.nodes.length\n ) {\n token = String(token.split('(')[0])\n token += '('\n }\n\n if (\n !isSelectorNode(node) ||\n node.parent?.nodes.indexOf(node) !== 0\n ) {\n tokens.push({\n ...node,\n token,\n } as ParsedSelectorToken)\n }\n }\n }\n if (isPostcssNodeWithChildren(node)) {\n for (const child of node.nodes) {\n processNode(child)\n }\n if (isPseudoNode(node) && node.nodes.length) {\n tokens.push({\n ...node,\n token: ')' + node.spaces.after,\n type: 'pseudo',\n } as ParsedSelectorToken)\n }\n }\n }\n\n processNode(ast(query))\n return tokens\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AACvD,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AAK,IAAI,GAAG,CAAA;oBACd,CAAC;oBAED,IACE,CAAC,cAAc,CAAC,IAAI,CAAC;wBACrB,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EACtC,CAAC;wBACD,MAAM,CAAC,IAAI,CAAC;4BACV,GAAG,IAAI;4BACP,KAAK;yBACiB,CAAC,CAAA;oBAC3B,CAAC;gBACH,CAAC;YACH,CAAC;YACD,IAAI,yBAAyB,CAAC,IAAI,CAAC,EAAE,CAAC;gBACpC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;oBAC/B,WAAW,CAAC,KAAK,CAAC,CAAA;gBACpB,CAAC;gBACD,IAAI,YAAY,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;oBAC5C,MAAM,CAAC,IAAI,CAAC;wBACV,GAAG,IAAI;wBACP,KAAK,EAAE,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK;wBAC9B,IAAI,EAAE,QAAQ;qBACQ,CAAC,CAAA;gBAC3B,CAAC;YACH,CAAC;QACH,CAAC,CAAA;QAED,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAA;QACvB,OAAO,MAAM,CAAA;IACf,CAAC;CACF","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport { joinDepIDTuple } from '@vltpkg/dep-id/browser'\nimport {\n parse,\n isPostcssNodeWithChildren,\n asPostcssNodeWithChildren,\n isSelectorNode,\n isPseudoNode,\n isIdentifierNode,\n isAttributeNode,\n} from '@vltpkg/dss-parser'\nimport { attribute } from './attribute.ts'\nimport { combinator } from './combinator.ts'\nimport { id } from './id.ts'\nimport { pseudo } from './pseudo.ts'\nimport type { EdgeLike, GraphLike, NodeLike } from '@vltpkg/graph'\nimport type { SpecOptions } from '@vltpkg/spec/browser'\nimport type { SecurityArchiveLike } from '@vltpkg/security-archive'\nimport type {\n PostcssNode,\n PostcssNodeWithChildren,\n} from '@vltpkg/dss-parser'\nimport type {\n ParsedSelectorToken,\n ParserState,\n ParserFn,\n QueryResponse,\n QueryResponseNode,\n QueryResponseEdge,\n} from './types.ts'\nimport type { DepID } from '@vltpkg/dep-id'\n\nexport * from './types.ts'\n\nexport type SearchOptions = {\n signal: AbortSignal\n scopeIDs?: DepID[]\n}\n\nconst noopFn = async (state: ParserState) => state\n\nconst selectors = {\n attribute,\n /* c8 ignore start */\n class: async (state: ParserState) => {\n throw error('Unsupported selector', { found: state.current })\n },\n /* c8 ignore end */\n combinator,\n comment: async (state: ParserState) => {\n if (state.current.value && !state.comment) {\n const commentValue = state.current.value\n const cleanComment = commentValue\n .replace(/^\\/\\*/, '')\n .replace(/\\*\\/$/, '')\n .trim()\n state.comment = cleanComment\n }\n return state\n },\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 error(\n `Missing parser for query node: ${state.current.type}`,\n {\n found: state.current,\n },\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 retries?: number\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 ':cwe',\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 ':scanned',\n ':score',\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\nconst setMethodToJSON = (node: QueryResponseNode) => {\n const { toJSON } = node\n const insights = node.insights\n node.toJSON = () => ({\n ...toJSON.call(node),\n insights,\n })\n}\n\n/**\n * The Query class is used to search the graph for nodes and edges\n * using the Dependency Selector Syntax (DSS).\n */\nexport class Query {\n #cache: Map<string, QueryResponse>\n #graph: GraphLike\n #retries: number\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 /**\n * Sorts an array of QueryResponse objects by specificity. Objects with\n * higher idCounter values come first, if idCounter values are equal,\n * then objects with higher commonCounter values come first. Otherwise,\n * the original order is preserved.\n */\n static specificitySort(\n responses: QueryResponse[],\n ): QueryResponse[] {\n return [...responses].sort((a, b) => {\n // First compare by idCounter (higher comes first)\n if (a.specificity.idCounter !== b.specificity.idCounter) {\n return b.specificity.idCounter - a.specificity.idCounter\n }\n\n // If idCounter values are equal, compare by commonCounter\n if (\n a.specificity.commonCounter !== b.specificity.commonCounter\n ) {\n return (\n b.specificity.commonCounter - a.specificity.commonCounter\n )\n }\n\n // If both counters are equal, preserve original order\n return 0\n })\n }\n\n constructor({\n graph,\n retries,\n specOptions,\n securityArchive,\n }: QueryOptions) {\n this.#cache = new Map()\n this.#graph = graph\n this.#retries = retries ?? 3\n this.#specOptions = specOptions\n this.#securityArchive = securityArchive\n }\n\n #getQueryResponseEdges(_edges: Set<EdgeLike>): QueryResponseEdge[] {\n return Array.from(_edges) as QueryResponseEdge[]\n }\n\n #getQueryResponseNodes(_nodes: Set<NodeLike>): QueryResponseNode[] {\n const nodes = Array.from(_nodes) as QueryResponseNode[]\n for (const node of nodes) {\n const securityArchiveEntry = this.#securityArchive?.get(node.id)\n\n // if a security archive entry is not found then the insights object\n // should just be empty with scanned=false\n if (!securityArchiveEntry) {\n node.insights = {\n scanned: false,\n }\n\n setMethodToJSON(node)\n continue\n }\n\n // if a security archive entry is found then we can populate the insights\n node.insights = {\n scanned: true,\n score: securityArchiveEntry.score,\n abandoned: securityArchiveEntry.alerts.some(\n i => i.type === 'missingAuthor',\n ),\n confused: securityArchiveEntry.alerts.some(\n i => i.type === 'manifestConfusion',\n ),\n cve: securityArchiveEntry.alerts\n .map(i => i.props?.cveId)\n .filter(i => i !== undefined),\n cwe: Array.from(\n new Set(\n securityArchiveEntry.alerts\n .filter(i => i.props?.cveId)\n .flatMap(i => i.props?.cwes?.map(j => j.id)),\n ),\n ) as `CWE-${string}`[],\n debug: securityArchiveEntry.alerts.some(\n i => i.type === 'debugAccess',\n ),\n deprecated: securityArchiveEntry.alerts.some(\n i => i.type === 'deprecated',\n ),\n dynamic: securityArchiveEntry.alerts.some(\n i => i.type === 'dynamicRequire',\n ),\n entropic: securityArchiveEntry.alerts.some(\n i => i.type === 'highEntropyStrings',\n ),\n env: securityArchiveEntry.alerts.some(\n i => i.type === 'envVars',\n ),\n eval: securityArchiveEntry.alerts.some(\n i => i.type === 'usesEval',\n ),\n fs: securityArchiveEntry.alerts.some(\n i => i.type === 'filesystemAccess',\n ),\n license: {\n unlicensed: securityArchiveEntry.alerts.some(\n i => i.type === 'explicitlyUnlicensedItem',\n ),\n misc: securityArchiveEntry.alerts.some(\n i => i.type === 'miscLicenseIssues',\n ),\n restricted: securityArchiveEntry.alerts.some(\n i => i.type === 'nonpermissiveLicense',\n ),\n ambiguous: securityArchiveEntry.alerts.some(\n i => i.type === 'ambiguousClassifier',\n ),\n copyleft: securityArchiveEntry.alerts.some(\n i => i.type === 'copyleftLicense',\n ),\n unknown: securityArchiveEntry.alerts.some(\n i => i.type === 'unidentifiedLicense',\n ),\n none: securityArchiveEntry.alerts.some(\n i => i.type === 'noLicenseFound',\n ),\n exception: securityArchiveEntry.alerts.some(\n i => i.type === 'licenseException',\n ),\n },\n malware: {\n low: securityArchiveEntry.alerts.some(\n i => i.type === 'gptAnomaly',\n ),\n medium: securityArchiveEntry.alerts.some(\n i => i.type === 'gptSecurity',\n ),\n high: securityArchiveEntry.alerts.some(\n i => i.type === 'gptMalware',\n ),\n critical: securityArchiveEntry.alerts.some(\n i => i.type === 'malware',\n ),\n },\n minified: securityArchiveEntry.alerts.some(\n i => i.type === 'minifiedFile',\n ),\n native: securityArchiveEntry.alerts.some(\n i => i.type === 'hasNativeCode',\n ),\n network: securityArchiveEntry.alerts.some(\n i => i.type === 'networkAccess',\n ),\n obfuscated: securityArchiveEntry.alerts.some(\n i => i.type === 'obfuscatedFile',\n ),\n scripts: securityArchiveEntry.alerts.some(\n i => i.type === 'installScripts',\n ),\n severity: {\n low: securityArchiveEntry.alerts.some(\n i => i.type === 'mildCVE',\n ),\n medium: securityArchiveEntry.alerts.some(\n i => i.type === 'potentialVulnerability',\n ),\n high: securityArchiveEntry.alerts.some(\n i => i.type === 'cve',\n ),\n critical: securityArchiveEntry.alerts.some(\n i => i.type === 'criticalCVE',\n ),\n },\n shell: securityArchiveEntry.alerts.some(\n i => i.type === 'shellAccess',\n ),\n shrinkwrap: securityArchiveEntry.alerts.some(\n i => i.type === 'shrinkwrap',\n ),\n squat: {\n medium: securityArchiveEntry.alerts.some(\n i => i.type === 'gptDidYouMean',\n ),\n critical: securityArchiveEntry.alerts.some(\n i => i.type === 'didYouMean',\n ),\n },\n suspicious: securityArchiveEntry.alerts.some(\n i => i.type === 'suspiciousStarActivity',\n ),\n tracker: securityArchiveEntry.alerts.some(\n i => i.type === 'telemetry',\n ),\n trivial: securityArchiveEntry.alerts.some(\n i => i.type === 'trivialPackage',\n ),\n undesirable: securityArchiveEntry.alerts.some(\n i => i.type === 'troll',\n ),\n unknown: securityArchiveEntry.alerts.some(\n i => i.type === 'newAuthor',\n ),\n unmaintained: securityArchiveEntry.alerts.some(\n i => i.type === 'unmaintained',\n ),\n unpopular: securityArchiveEntry.alerts.some(\n i => i.type === 'unpopularPackage',\n ),\n unstable: securityArchiveEntry.alerts.some(\n i => i.type === 'unstableOwnership',\n ),\n }\n\n setMethodToJSON(node)\n }\n return nodes\n }\n\n /**\n * Search the graph for nodes and edges that match the given query.\n */\n async search(\n query: string,\n {\n signal,\n scopeIDs = [joinDepIDTuple(['file', '.'])],\n }: SearchOptions,\n ): Promise<QueryResponse> {\n if (!query)\n return {\n edges: [],\n nodes: [],\n comment: '',\n specificity: { idCounter: 0, commonCounter: 0 },\n }\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 // parse the query string into AST\n const current = parse(query)\n // set loose mode for the entire parse in case there are multiple selectors\n // so that using invalid pseudo selectors or other query language parser\n // errors won't throw an error,\n // e.g: `:root > *, #a, :foo` still returns results for `:root > ` and `#a`\n // while :foo is ignored\n const loose = asPostcssNodeWithChildren(current).nodes.length > 1\n // builds initial state and walks over it,\n // retrieving the collected result\n const { collect, comment, specificity } = await walk({\n cancellable: async () => {\n await new Promise(resolve => {\n setTimeout(resolve, 0)\n })\n signal.throwIfAborted()\n },\n current,\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 comment: '',\n loose,\n partial: { nodes, edges },\n retries: this.#retries,\n signal,\n securityArchive: this.#securityArchive,\n specOptions: this.#specOptions,\n scopeIDs,\n walk,\n specificity: { idCounter: 0, commonCounter: 0 },\n })\n\n const res: QueryResponse = {\n edges: this.#getQueryResponseEdges(collect.edges),\n nodes: this.#getQueryResponseNodes(collect.nodes),\n comment,\n specificity,\n }\n this.#cache.set(query, res)\n return res\n }\n\n /**\n * Parses a query string in order to retrieve an array of tokens.\n */\n static getQueryTokens(query: string): ParsedSelectorToken[] {\n if (!query) return []\n\n const tokens: ParsedSelectorToken[] = []\n\n const ast = (q: string) => {\n try {\n return parse(q)\n } catch (_e) {\n return ast(q.slice(0, -1))\n }\n }\n\n const processNode = (node: PostcssNode) => {\n for (const key of selectorsMap.keys()) {\n if (node.type === key && node.type !== 'root') {\n let token = `${node.spaces.before}${node.value}${node.spaces.after}`\n\n if (isIdentifierNode(node)) {\n token = `${node.spaces.before}#${node.value}${node.spaces.after}`\n } else if (isSelectorNode(node)) {\n token = `${node.spaces.before},${node.spaces.after}`\n } else if (isAttributeNode(node)) {\n token = String(\n node.source?.start?.column &&\n node.source.end?.column &&\n `${node.spaces.before}${query.slice(node.source.start.column - 1, node.source.end.column)}${node.spaces.after}`,\n )\n }\n\n if (\n isPostcssNodeWithChildren(node) &&\n isPseudoNode(node) &&\n node.nodes.length\n ) {\n token = String(token.split('(')[0])\n token += '('\n }\n\n if (\n !isSelectorNode(node) ||\n node.parent?.nodes.indexOf(node) !== 0\n ) {\n tokens.push({\n ...node,\n token,\n } as ParsedSelectorToken)\n }\n }\n }\n if (isPostcssNodeWithChildren(node)) {\n for (const child of node.nodes) {\n processNode(child)\n }\n if (isPseudoNode(node) && node.nodes.length) {\n tokens.push({\n ...node,\n token: ')' + node.spaces.after,\n type: 'pseudo',\n } as ParsedSelectorToken)\n }\n }\n }\n\n processNode(ast(query))\n return tokens\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAU,IAAI,EAAE,MAAM,yBAAyB,CAAA;AAS3D;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,UAAW,MAAM,KAAG,MAItD,CAAA;AAEH,eAAO,MAAM,UAAU,UAAW,MAAM,KAAG,MACb,CAAA;AAE9B,eAAO,MAAM,YAAY,UAAW,MAAM,KAAG,MACf,CAAA;AAgB9B;;;GAGG;AACH,eAAO,MAAM,KAAK,UAAW,MAAM,KAAG,IA0ErC,CAAA"}
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAU,IAAI,EAAE,MAAM,yBAAyB,CAAA;AAG3D;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,UAAW,MAAM,KAAG,MAItD,CAAA;AAEH,eAAO,MAAM,UAAU,UAAW,MAAM,KAAG,MACb,CAAA;AAE9B,eAAO,MAAM,YAAY,UAAW,MAAM,KAAG,MACf,CAAA;AAgB9B;;;GAGG;AACH,eAAO,MAAM,KAAK,UAAW,MAAM,KAAG,IA0ErC,CAAA"}
@@ -1,5 +1,5 @@
1
1
  import postcssSelectorParser from 'postcss-selector-parser';
2
- import { asSelectorNode, isCombinatorNode, isPseudoNode, isTagNode, } from "./types.js";
2
+ import { asSelectorNode, isCombinatorNode, isPseudoNode, isTagNode, } from '@vltpkg/dss-parser';
3
3
  /**
4
4
  * Escapes forward slashes in specific patterns matching @scoped/name paths
5
5
  * This will allow usage of unescaped forward slashes necessary for scoped
@@ -1 +1 @@
1
- {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,MAAM,yBAAyB,CAAA;AAE3D,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,SAAS,GACV,MAAM,YAAY,CAAA;AAGnB;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,KAAa,EAAU,EAAE,CAChE,KAAK,CAAC,OAAO,CACX,oBAAoB,EACpB,CAAC,CAAC,EAAE,KAAa,EAAE,EAAE,CAAC,GAAG,KAAK,KAAK,CACpC,CAAA;AAEH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAa,EAAU,EAAE,CAClD,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;AAE9B,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAa,EAAU,EAAE,CACpD,KAAK,CAAC,UAAU,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;AAE9B,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC;IAClC,YAAY;IACZ,QAAQ;IACR,UAAU;IACV,WAAW;IACX,MAAM;IACN,QAAQ;IACR,SAAS;IACT,IAAI;CACL,CAAC,CAAA;AAEF,MAAM,iBAAiB,GAAG,CAAC,IAAY,EAAE,EAAE,CACzC,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AAErC;;;GAGG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,KAAa,EAAQ,EAAE;IAC3C,MAAM,YAAY,GAAG,UAAU,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC,CAAA;IAChE,MAAM,YAAY,GAAG,CAAC,IAAU,EAAE,EAAE;QAClC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAiB,EAAE,EAAE;YAC9B,4BA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QAAQ,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAA;gBAC3B,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;IACD,OAAO,qBAAqB,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;AAClE,CAAC,CAAA","sourcesContent":["import postcssSelectorParser from 'postcss-selector-parser'\nimport type { Pseudo, Root } from 'postcss-selector-parser'\nimport {\n asSelectorNode,\n isCombinatorNode,\n isPseudoNode,\n isTagNode,\n} from './types.ts'\nimport type { PostcssNode } from './types.ts'\n\n/**\n * Escapes forward slashes in specific patterns matching @scoped/name paths\n * This will allow usage of unescaped forward slashes necessary for scoped\n * package names in the id selector.\n */\nexport const escapeScopedNamesSlashes = (query: string): string =>\n query.replace(\n /(#@(\\w|-|\\.)+)\\//gm,\n (_, scope: string) => `${scope}\\\\/`,\n )\n\nexport const escapeDots = (query: string): string =>\n query.replaceAll('.', '\\\\.')\n\nexport const unescapeDots = (query: string): string =>\n query.replaceAll('\\\\.', '.')\n\nconst pseudoCleanUpNeeded = new Set([\n ':published',\n ':score',\n ':malware',\n ':severity',\n ':sev',\n ':squat',\n ':semver',\n ':v',\n])\n\nconst hasParamsToEscape = (node: Pseudo) =>\n pseudoCleanUpNeeded.has(node.value)\n\n/**\n * Parses a CSS selector string into an AST\n * Handles escaping of forward slashes in specific patterns\n */\nexport const parse = (query: string): Root => {\n const escapedQuery = escapeDots(escapeScopedNamesSlashes(query))\n const transformAst = (root: Root) => {\n root.walk((node: PostcssNode) => {\n // clean up the escaped dots\n if (node.value && typeof node.value === 'string') {\n node.value = unescapeDots(node.value)\n }\n if (isPseudoNode(node) && hasParamsToEscape(node)) {\n // these are pseudo nodes that should only take strings as\n // parameters, so in this preparse step we clean up anything\n // that was recognized as a postcss node and transform that\n // into something that can be most likely parsed as a string\n for (const n of node.nodes) {\n // the parameters have a selector node that wraps them up\n const selector = asSelectorNode(n)\n selector.nodes.forEach((currentNode, index, arr) => {\n // get the next node, we'll update it later\n const nextNode = arr[index + 1]\n // if the current node is a combinator node, we'll need to\n // escape it, we do so by removing the node entirely and\n // updating the contents of the next node with its value\n if (\n isCombinatorNode(currentNode) &&\n isTagNode(nextNode)\n ) {\n nextNode.value = `${currentNode.spaces.before}${currentNode.value}${currentNode.spaces.after}${nextNode.value}`\n // make sure to also update the source position\n // references, those are used by the syntax highlighter\n if (\n nextNode.source?.start?.line &&\n currentNode.source?.start?.line\n ) {\n nextNode.source.start.line =\n currentNode.source.start.line\n }\n if (\n nextNode.source?.start?.column &&\n currentNode.source?.start?.column\n ) {\n nextNode.source.start.column =\n currentNode.source.start.column\n }\n // removes the current node from the selector node\n arr.splice(index, 1)\n }\n })\n // after removing combinator nodes, if we end up with multiple\n // tags in the selector node, we need to smush them together\n selector.nodes.reduce((acc, currentNode) => {\n if (currentNode === acc) return acc\n acc.value = `${acc.value}${currentNode.spaces.before}${currentNode.value}${currentNode.spaces.after}`\n // make sure to also update the source position refs\n if (\n currentNode.source?.end?.line &&\n acc.source?.end?.line\n ) {\n acc.source.end.line = currentNode.source.end.line\n }\n if (\n currentNode.source?.end?.column &&\n acc.source?.end?.column\n ) {\n acc.source.end.column = currentNode.source.end.column\n }\n return acc\n }, selector.first)\n // the selector wrapper node should have a single node\n selector.nodes.length = 1\n }\n }\n })\n }\n return postcssSelectorParser(transformAst).astSync(escapedQuery)\n}\n"]}
1
+ {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,MAAM,yBAAyB,CAAA;AAC3D,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,SAAS,GACV,MAAM,oBAAoB,CAAA;AAI3B;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,KAAa,EAAU,EAAE,CAChE,KAAK,CAAC,OAAO,CACX,oBAAoB,EACpB,CAAC,CAAC,EAAE,KAAa,EAAE,EAAE,CAA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AE,EAAE;wBACzC,IAAI,WAAW,KAAK,GAAG;4BAAE,OAAO,GAAG,CAAA;wBACnC,GAAG,CAAC,KAAK,GAAG,GAAG,GAAG,CAAC,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,MAAM,GAAG,WAAW,CAAC,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;wBACrG,oDAAoD;wBACpD,IACE,WAAW,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI;4BAC7B,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EACrB,CAAC;4BACD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,GAAG,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAA;wBACnD,CAAC;wBACD,IACE,WAAW,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM;4BAC/B,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EACvB,CAAC;4BACD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAA;wBACvD,CAAC;wBACD,OAAO,GAAG,CAAA;oBACZ,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAA;oBAClB,sDAAsD;oBACtD,QAAQ,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAA;gBAC3B,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;IACD,OAAO,qBAAqB,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;AAClE,CAAC,CAAA","sourcesContent":["import postcssSelectorParser from 'postcss-selector-parser'\nimport {\n asSelectorNode,\n isCombinatorNode,\n isPseudoNode,\n isTagNode,\n} from '@vltpkg/dss-parser'\nimport type { Pseudo, Root } from 'postcss-selector-parser'\nimport type { PostcssNode } from '@vltpkg/dss-parser'\n\n/**\n * Escapes forward slashes in specific patterns matching @scoped/name paths\n * This will allow usage of unescaped forward slashes necessary for scoped\n * package names in the id selector.\n */\nexport const escapeScopedNamesSlashes = (query: string): string =>\n query.replace(\n /(#@(\\w|-|\\.)+)\\//gm,\n (_, scope: string) => `${scope}\\\\/`,\n )\n\nexport const escapeDots = (query: string): string =>\n query.replaceAll('.', '\\\\.')\n\nexport const unescapeDots = (query: string): string =>\n query.replaceAll('\\\\.', '.')\n\nconst pseudoCleanUpNeeded = new Set([\n ':published',\n ':score',\n ':malware',\n ':severity',\n ':sev',\n ':squat',\n ':semver',\n ':v',\n])\n\nconst hasParamsToEscape = (node: Pseudo) =>\n pseudoCleanUpNeeded.has(node.value)\n\n/**\n * Parses a CSS selector string into an AST\n * Handles escaping of forward slashes in specific patterns\n */\nexport const parse = (query: string): Root => {\n const escapedQuery = escapeDots(escapeScopedNamesSlashes(query))\n const transformAst = (root: Root) => {\n root.walk((node: PostcssNode) => {\n // clean up the escaped dots\n if (node.value && typeof node.value === 'string') {\n node.value = unescapeDots(node.value)\n }\n if (isPseudoNode(node) && hasParamsToEscape(node)) {\n // these are pseudo nodes that should only take strings as\n // parameters, so in this preparse step we clean up anything\n // that was recognized as a postcss node and transform that\n // into something that can be most likely parsed as a string\n for (const n of node.nodes) {\n // the parameters have a selector node that wraps them up\n const selector = asSelectorNode(n)\n selector.nodes.forEach((currentNode, index, arr) => {\n // get the next node, we'll update it later\n const nextNode = arr[index + 1]\n // if the current node is a combinator node, we'll need to\n // escape it, we do so by removing the node entirely and\n // updating the contents of the next node with its value\n if (\n isCombinatorNode(currentNode) &&\n isTagNode(nextNode)\n ) {\n nextNode.value = `${currentNode.spaces.before}${currentNode.value}${currentNode.spaces.after}${nextNode.value}`\n // make sure to also update the source position\n // references, those are used by the syntax highlighter\n if (\n nextNode.source?.start?.line &&\n currentNode.source?.start?.line\n ) {\n nextNode.source.start.line =\n currentNode.source.start.line\n }\n if (\n nextNode.source?.start?.column &&\n currentNode.source?.start?.column\n ) {\n nextNode.source.start.column =\n currentNode.source.start.column\n }\n // removes the current node from the selector node\n arr.splice(index, 1)\n }\n })\n // after removing combinator nodes, if we end up with multiple\n // tags in the selector node, we need to smush them together\n selector.nodes.reduce((acc, currentNode) => {\n if (currentNode === acc) return acc\n acc.value = `${acc.value}${currentNode.spaces.before}${currentNode.value}${currentNode.spaces.after}`\n // make sure to also update the source position refs\n if (\n currentNode.source?.end?.line &&\n acc.source?.end?.line\n ) {\n acc.source.end.line = currentNode.source.end.line\n }\n if (\n currentNode.source?.end?.column &&\n acc.source?.end?.column\n ) {\n acc.source.end.column = currentNode.source.end.column\n }\n return acc\n }, selector.first)\n // the selector wrapper node should have a single node\n selector.nodes.length = 1\n }\n }\n })\n }\n return postcssSelectorParser(transformAst).astSync(escapedQuery)\n}\n"]}
@@ -1,4 +1,5 @@
1
- import type { ParserState, PostcssNode } from '../types.ts';
1
+ import type { ParserState } from '../types.ts';
2
+ import type { PostcssNode } from '@vltpkg/dss-parser';
2
3
  export type AttrInternals = {
3
4
  attribute: string;
4
5
  insensitive: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"attr.d.ts","sourceRoot":"","sources":["../../../src/pseudo/attr.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAO3D,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,OAAO,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,EAAE,CAAA;CACrB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,UAClB,WAAW,EAAE,KACnB,aA0BF,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,IAAI,UAAiB,WAAW,yBA8B5C,CAAA"}
1
+ {"version":3,"file":"attr.d.ts","sourceRoot":"","sources":["../../../src/pseudo/attr.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAErD,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,OAAO,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,EAAE,CAAA;CACrB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,UAClB,WAAW,EAAE,KACnB,aA0BF,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,IAAI,UAAiB,WAAW,yBA8B5C,CAAA"}
@@ -1,5 +1,5 @@
1
1
  import { error } from '@vltpkg/error-cause';
2
- import { asAttributeNode, asPostcssNodeWithChildren, asStringNode, asTagNode, isStringNode, } from "../types.js";
2
+ import { asAttributeNode, asPostcssNodeWithChildren, asStringNode, asTagNode, isStringNode, } from '@vltpkg/dss-parser';
3
3
  import { attributeSelectorsMap, filterAttributes, } from "../attribute.js";
4
4
  import { removeQuotes } from "./helpers.js";
5
5
  /**