@vltpkg/query 0.0.0-0.1730724342581 → 0.0.0-3
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 +8 -0
- package/dist/esm/attribute.d.ts +2 -2
- package/dist/esm/attribute.d.ts.map +1 -1
- package/dist/esm/attribute.js +11 -4
- package/dist/esm/attribute.js.map +1 -1
- package/dist/esm/class.d.ts +1 -1
- package/dist/esm/class.d.ts.map +1 -1
- package/dist/esm/class.js +2 -1
- package/dist/esm/class.js.map +1 -1
- package/dist/esm/combinator.d.ts +1 -1
- package/dist/esm/combinator.d.ts.map +1 -1
- package/dist/esm/combinator.js +2 -1
- package/dist/esm/combinator.js.map +1 -1
- package/dist/esm/id.d.ts +1 -1
- package/dist/esm/id.d.ts.map +1 -1
- package/dist/esm/id.js +2 -2
- package/dist/esm/id.js.map +1 -1
- package/dist/esm/index.d.ts +7 -5
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +20 -9
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/pseudo/attr.d.ts +18 -0
- package/dist/esm/pseudo/attr.d.ts.map +1 -0
- package/dist/esm/pseudo/attr.js +50 -0
- package/dist/esm/pseudo/attr.js.map +1 -0
- package/dist/esm/pseudo/helpers.d.ts +15 -0
- package/dist/esm/pseudo/helpers.d.ts.map +1 -0
- package/dist/esm/pseudo/helpers.js +24 -0
- package/dist/esm/pseudo/helpers.js.map +1 -0
- package/dist/esm/pseudo/outdated.d.ts +54 -0
- package/dist/esm/pseudo/outdated.d.ts.map +1 -0
- package/dist/esm/pseudo/outdated.js +201 -0
- package/dist/esm/pseudo/outdated.js.map +1 -0
- package/dist/esm/pseudo/semver.d.ts +16 -0
- package/dist/esm/pseudo/semver.d.ts.map +1 -0
- package/dist/esm/pseudo/semver.js +180 -0
- package/dist/esm/pseudo/semver.js.map +1 -0
- package/dist/esm/pseudo.d.ts +1 -8
- package/dist/esm/pseudo.d.ts.map +1 -1
- package/dist/esm/pseudo.js +14 -63
- package/dist/esm/pseudo.js.map +1 -1
- package/dist/esm/types.d.ts +8 -2
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +13 -0
- package/dist/esm/types.js.map +1 -1
- package/package.json +25 -17
package/README.md
CHANGED
|
@@ -88,7 +88,15 @@ e.g: `#foo` is the same as `[name=foo]`
|
|
|
88
88
|
- `:has(<selector-list>)` Matches only packages that have valid results for the selector expression used. As an example, here is a query that matches all packages that have a peer dependency on `react`: `:has(.peer[name=react])`
|
|
89
89
|
- `:is(<forgiving-selector-list>)` Useful for writing large selectors in a more compact form, the `:is()` pseudo-class takes a selector list as its arguments and selects any element that can be selected by one of the selectors in that list. As an example, let's say I want to select packages named `a` & `b` that are direct dependencies of my project root: `:root > [name=a], :root > [name=b]` using the `:is()` pseudo-class, that same expression can be shortened to: `:root > :is([name=a], [name=b])`. Similar to the css pseudo-class of the same name, this selector has a forgiving behavior regarding its nested selector list ignoring any usage of non-existing ids, classes, combinators, operators and pseudo-selectors.
|
|
90
90
|
- `:not(<selector-list>)` Negation pseudo-class, select packages that do not match a list of selectors.
|
|
91
|
+
- `:outdated(<type>)` Matches packages that are outdated, the type parameter is optional and can be one of the following:
|
|
92
|
+
- `any` (default) a version exists that is greater than the current one
|
|
93
|
+
- `in-range` a version exists that is greater than the current one, and satisfies at least one if its parent's dependencies
|
|
94
|
+
- `out-of-range` a version exists that is greater than the current one, does not satisfy at least one of its parent's dependencies
|
|
95
|
+
- `major` a version exists that is a semver major greater than the current one
|
|
96
|
+
- `minor` a version exists that is a semver minor greater than the current one
|
|
97
|
+
- `patch` a version exists that is a semver patch greater than the current one
|
|
91
98
|
- `:private` Matches packages that have the property `private` set on their `package.json` file.
|
|
99
|
+
- `:semver(<value>, <function>, <custom-attribute-selector>)` Matches packages based on a semver value, e.g, to retrieve all packages that have a `version` satisfied by the semver value `^1.0.0`: `:semver(^1.0.0)`. It's also possible to define the type of semver comparison function to use by defining a second parameter, e.g: `:semver(^1.0.0, eq)` for an exact match, valid comparison types are: `eq`, `neq`, `gt`, `gte`, `lt`, `lte`, `satisfies` (default). A third parameter allows for specifying a different `package.json` property to use for the comparison, e.g: `:semver(^22, satisfies, :attr(engines, [node]))` for comparing the value of `engines.node`.
|
|
92
100
|
- `:type(registry|file|git|remote|workspace)` Matches packages based on their type, e.g, to retrieve all git dependencies: `:type(git)`.
|
|
93
101
|
|
|
94
102
|
### Pseudo Elements
|
package/dist/esm/attribute.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { NodeLike } from '@vltpkg/graph';
|
|
2
|
+
import type { ParserState } from './types.ts';
|
|
3
3
|
export type ComparatorFn = (attr: string, value?: string) => boolean;
|
|
4
4
|
/**
|
|
5
5
|
* Retrieve the {@link Manifest} values found at the given `properties`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attribute.d.ts","sourceRoot":"","sources":["../../src/attribute.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
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"}
|
package/dist/esm/attribute.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { error } from '@vltpkg/error-cause';
|
|
2
|
-
import { asAttributeNode } from
|
|
2
|
+
import { asAttributeNode } from "./types.js";
|
|
3
|
+
// JSONField has a mapped type constituent that would coerce to [object Object]
|
|
4
|
+
// when stringified, which is what we want in this case.
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
6
|
+
const jsonFieldToString = (v) => String(v);
|
|
3
7
|
/**
|
|
4
8
|
* Retrieve the {@link Manifest} values found at the given `properties`
|
|
5
9
|
* location for a given {@link Node}.
|
|
@@ -55,11 +59,11 @@ export const getManifestPropertyValues = (node, properties, attribute) => {
|
|
|
55
59
|
for (const prop of props) {
|
|
56
60
|
if (Array.isArray(prop)) {
|
|
57
61
|
for (const p of prop) {
|
|
58
|
-
collect.add(p ?
|
|
62
|
+
collect.add(p ? jsonFieldToString(p) : '');
|
|
59
63
|
}
|
|
60
64
|
}
|
|
61
65
|
else {
|
|
62
|
-
collect.add(
|
|
66
|
+
collect.add(jsonFieldToString(prop));
|
|
63
67
|
}
|
|
64
68
|
}
|
|
65
69
|
return [...collect];
|
|
@@ -67,7 +71,9 @@ export const getManifestPropertyValues = (node, properties, attribute) => {
|
|
|
67
71
|
// decorator style of function that will filter `ParserState` results
|
|
68
72
|
// based on a provided `comparator` function
|
|
69
73
|
export const filterAttributes = (state, comparator, value, propertyName, insensitive, prefixProperties = []) => {
|
|
70
|
-
const check = (attr) => comparator?.(insensitive ?
|
|
74
|
+
const check = (attr) => comparator?.(insensitive ?
|
|
75
|
+
jsonFieldToString(attr).toLowerCase()
|
|
76
|
+
: jsonFieldToString(attr), insensitive ? value.toLowerCase() : value);
|
|
71
77
|
const deleteNode = (node) => {
|
|
72
78
|
for (const edge of node.edgesIn) {
|
|
73
79
|
state.partial.edges.delete(edge);
|
|
@@ -115,6 +121,7 @@ export const attributeSelectorsMap = new Map(Object.entries(attributeSelectors))
|
|
|
115
121
|
* Parse attributes selectors, e.g: `[name]`, `[name=value]`, etc
|
|
116
122
|
*/
|
|
117
123
|
export const attribute = async (state) => {
|
|
124
|
+
await state.cancellable();
|
|
118
125
|
const curr = asAttributeNode(state.current);
|
|
119
126
|
const operatorFn = attributeSelectorsMap.get(String(curr.operator));
|
|
120
127
|
if (!operatorFn) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attribute.js","sourceRoot":"","sources":["../../src/attribute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAG3C,OAAO,EAAE,eAAe,EAAoB,MAAM,YAAY,CAAA;AAI9D;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,IAAc,EACd,UAAoB,EACpB,SAAiB,EACK,EAAE;IACxB,IAAI,CAAC,IAAI,CAAC,QAAQ;QAAE,OAAM;IAE1B,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAY,CAAC,IAAI,CAAC,QAAqB,CAAC,CAAC,CAAA;IACjE,MAAM,KAAK,GAAG,IAAI,GAAG,EAAa,CAAA;IAClC,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;QAC7B,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;YAC5B,4CAA4C;YAC5C,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,MAAM,KAAK,CAAC,yCAAyC,EAAE;oBACrD,KAAK,EAAE,UAAU;iBAClB,CAAC,CAAA;YACJ,CAAC;YACD,oBAAoB;YAEpB,wDAAwD;YACxD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;gBACxB,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;oBACrB,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;gB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,CAAA;AACD,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAC1C,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,CACnC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAC5B,KAAkB,EACI,EAAE;IACxB,MAAM,IAAI,GAAG,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAC3C,MAAM,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,IAAI,KAAK,CACb,mCAAmC,IAAI,CAAC,QAAQ,EAAE,CACnD,CAAA;IACH,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, type Manifest } from '@vltpkg/types'\nimport { asAttributeNode, type ParserState } from './types.js'\n\nexport type ComparatorFn = (attr: string, value?: string) => boolean\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 ? String(p) : '')\n }\n } else {\n collect.add(String(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 ? String(attr).toLowerCase() : String(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 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 new Error(\n `Unsupported attribute operator: ${curr.operator}`,\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,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAG3C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAK5C,+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,CAAC,IAAI,CAAC,Q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AC,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 new Error(\n `Unsupported attribute operator: ${curr.operator}`,\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"]}
|
package/dist/esm/class.d.ts
CHANGED
package/dist/esm/class.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"class.d.ts","sourceRoot":"","sources":["../../src/class.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"class.d.ts","sourceRoot":"","sources":["../../src/class.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAY,WAAW,EAAE,MAAM,YAAY,CAAA;AAoHvD;;GAEG;AACH,eAAO,MAAM,OAAO,UAAiB,WAAW,yBAa/C,CAAA"}
|
package/dist/esm/class.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { asClassNode
|
|
1
|
+
import { asClassNode } from "./types.js";
|
|
2
2
|
const classSelectors = {
|
|
3
3
|
prod: async (state) => {
|
|
4
4
|
for (const edge of state.partial.edges) {
|
|
@@ -114,6 +114,7 @@ const classSelectorsMap = new Map(Object.entries(classSelectors));
|
|
|
114
114
|
* Parse classes, e.g: `.prod`, `.dev`, `.optional`, etc
|
|
115
115
|
*/
|
|
116
116
|
export const classFn = async (state) => {
|
|
117
|
+
await state.cancellable();
|
|
117
118
|
const curr = asClassNode(state.current);
|
|
118
119
|
const comparatorFn = curr.value && classSelectorsMap.get(curr.value);
|
|
119
120
|
if (!comparatorFn) {
|
package/dist/esm/class.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"class.js","sourceRoot":"","sources":["../../src/class.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"class.js","sourceRoot":"","sources":["../../src/class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAGxC,MAAM,cAAc,GAA6B;IAC/C,IAAI,EAAE,KAAK,EAAE,KAAkB,EAAE,EAAE;QACjC,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YACvC,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;gBAC1C,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;YAClC,CAAC;QACH,CAAC;QACD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YACvC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;gBACvB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;gBAChC,SAAQ;YACV,CAAC;YACD,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;YACtC,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;gBAC5B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;oBACnC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;gBACvB,CAAC;YACH,CAAC;YACD,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;gBACnB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;YAClC,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CA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AAC,cAAc,CAAC,CAC/B,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,EAAE,KAAkB,EAAE,EAAE;IAClD,MAAM,KAAK,CAAC,WAAW,EAAE,CAAA;IAEzB,MAAM,IAAI,GAAG,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACvC,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,IAAI,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACpE,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YAChB,OAAO,KAAK,CAAA;QACd,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,sBAAsB,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAA;IAC9D,CAAC;IACD,OAAO,YAAY,CAAC,KAAK,CAAC,CAAA;AAC5B,CAAC,CAAA","sourcesContent":["import { asClassNode } from './types.ts'\nimport type { ParserFn, ParserState } from './types.ts'\n\nconst classSelectors: Record<string, ParserFn> = {\n prod: async (state: ParserState) => {\n for (const edge of state.partial.edges) {\n if (edge.type !== 'prod' || edge.from.dev) {\n state.partial.edges.delete(edge)\n }\n }\n for (const node of state.partial.nodes) {\n if (!node.edgesIn.size) {\n state.partial.nodes.delete(node)\n continue\n }\n const iterator = new Set(node.edgesIn)\n for (const edge of iterator) {\n if (!state.partial.edges.has(edge)) {\n iterator.delete(edge)\n }\n }\n if (!iterator.size) {\n state.partial.nodes.delete(node)\n }\n }\n return state\n },\n dev: async (state: ParserState) => {\n for (const edge of state.partial.edges) {\n if (edge.type !== 'dev' && !edge.from.dev) {\n state.partial.edges.delete(edge)\n }\n }\n for (const node of state.partial.nodes) {\n if (!node.edgesIn.size) {\n state.partial.nodes.delete(node)\n continue\n }\n const iterator = new Set(node.edgesIn)\n for (const edge of iterator) {\n if (!state.partial.edges.has(edge)) {\n iterator.delete(edge)\n }\n }\n if (!iterator.size) {\n state.partial.nodes.delete(node)\n }\n }\n return state\n },\n optional: async (state: ParserState) => {\n for (const edge of state.partial.edges) {\n if (edge.type !== 'optional' && !edge.from.optional) {\n state.partial.edges.delete(edge)\n }\n }\n for (const node of state.partial.nodes) {\n if (!node.edgesIn.size) {\n state.partial.nodes.delete(node)\n continue\n }\n const iterator = new Set(node.edgesIn)\n for (const edge of iterator) {\n if (!state.partial.edges.has(edge)) {\n iterator.delete(edge)\n }\n }\n if (!iterator.size) {\n state.partial.nodes.delete(node)\n }\n }\n return state\n },\n peer: async (state: ParserState) => {\n for (const edge of state.partial.edges) {\n if (edge.type !== 'peer') {\n state.partial.edges.delete(edge)\n }\n }\n for (const node of state.partial.nodes) {\n if (!node.edgesIn.size) {\n state.partial.nodes.delete(node)\n continue\n }\n for (const e of node.edgesIn) {\n if (!state.partial.edges.has(e)) {\n state.partial.nodes.delete(node)\n }\n }\n }\n return state\n },\n workspace: async (state: ParserState) => {\n for (const node of state.partial.nodes) {\n if (!node.importer || node.mainImporter) {\n state.partial.nodes.delete(node)\n }\n }\n for (const edge of state.partial.edges) {\n // workspaces can't be missing\n if (!edge.to) {\n state.partial.edges.delete(edge)\n // keep only edges that are linking to preivously kept nodes\n } else if (!state.partial.nodes.has(edge.to)) {\n state.partial.edges.delete(edge)\n }\n }\n return state\n },\n // TBD: all things bundled\n // bundled: () => false,\n}\n\nconst classSelectorsMap = new Map<string, ParserFn>(\n Object.entries(classSelectors),\n)\n\n/**\n * Parse classes, e.g: `.prod`, `.dev`, `.optional`, etc\n */\nexport const classFn = async (state: ParserState) => {\n await state.cancellable()\n\n const curr = asClassNode(state.current)\n const comparatorFn = curr.value && classSelectorsMap.get(curr.value)\n if (!comparatorFn) {\n if (state.loose) {\n return state\n }\n\n throw new Error(`Unsupported class: ${state.current.value}`)\n }\n return comparatorFn(state)\n}\n"]}
|
package/dist/esm/combinator.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"combinator.d.ts","sourceRoot":"","sources":["../../src/combinator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"combinator.d.ts","sourceRoot":"","sources":["../../src/combinator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAY,MAAM,YAAY,CAAA;AA6GvD;;GAEG;AACH,eAAO,MAAM,UAAU,UAAiB,WAAW,yBAclD,CAAA"}
|
package/dist/esm/combinator.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { asCombinatorNode
|
|
1
|
+
import { asCombinatorNode } from "./types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Returns a new set of nodes, containing all direct dependencies
|
|
4
4
|
* of the current list of nodes used.
|
|
@@ -95,6 +95,7 @@ const combinatorSelectorsMap = new Map(Object.entries(combinatorSelectors));
|
|
|
95
95
|
* Parse css-style combinators, e.g: `>`, `~` and ` `
|
|
96
96
|
*/
|
|
97
97
|
export const combinator = async (state) => {
|
|
98
|
+
await state.cancellable();
|
|
98
99
|
const curr = asCombinatorNode(state.current);
|
|
99
100
|
const parserFn = curr.value && combinatorSelectorsMap.get(curr.value);
|
|
100
101
|
if (!parserFn) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"combinator.js","sourceRoot":"","sources":["../../src/combinator.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"combinator.js","sourceRoot":"","sources":["../../src/combinator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAG7C;;;;;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,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ED,MAAM,mBAAmB,GAAG;IAC1B,GAAG,EAAE,eAAe;IACpB,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,IAAI,KAAK,CAAC,2BAA2B,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAA;IACnE,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'\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 new Error(`Unsupported combinator: ${state.current.value}`)\n }\n return parserFn(state)\n}\n"]}
|
package/dist/esm/id.d.ts
CHANGED
package/dist/esm/id.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../../src/id.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../../src/id.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAM7C;;GAEG;AACH,eAAO,MAAM,EAAE,UAAiB,WAAW,yBAc1C,CAAA"}
|
package/dist/esm/id.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { error } from '@vltpkg/error-cause';
|
|
2
|
-
import { asIdentifierNode } from
|
|
3
|
-
import { attributeSelectorsMap, filterAttributes, } from
|
|
2
|
+
import { asIdentifierNode } from "./types.js";
|
|
3
|
+
import { attributeSelectorsMap, filterAttributes, } from "./attribute.js";
|
|
4
4
|
/**
|
|
5
5
|
* Parse ids, e.g: `#foo`
|
|
6
6
|
*/
|
package/dist/esm/id.js.map
CHANGED
|
@@ -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,
|
|
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;AAE7C,OAAO,EACL,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,gBAAgB,CAAA;AAEvB;;GAEG;AACH,MAAM,CAAC,MAAM,EAAE,GAAG,KAAK,EAAE,KAAkB,EAAE,EAAE;IAC7C,MAAM,EAAE,KAAK,EAAE,GAAG,gBAAgB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACjD,MAAM,UAAU,GAAG,qBAAqB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAEjD,8CAA8C;IAC9C,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,KAAK,CAAC,yBAAyB,CAAC,CAAA;IACxC,CAAC;IACD,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,KAAK,CAAC,8CAA8C,CAAC,CAAA;IAC7D,CAAC;IACD,oBAAoB;IAEpB,OAAO,gBAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,CAAA;AACjE,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport { asIdentifierNode } from './types.ts'\nimport type { ParserState } from './types.ts'\nimport {\n attributeSelectorsMap,\n filterAttributes,\n} from './attribute.ts'\n\n/**\n * Parse ids, e.g: `#foo`\n */\nexport const id = async (state: ParserState) => {\n const { value } = asIdentifierNode(state.current)\n const comparator = attributeSelectorsMap.get('=')\n\n /* c8 ignore start - should not be possible */\n if (!value) {\n throw error('Missing identifier name')\n }\n if (!comparator) {\n throw error('Could not find attribute selector comparator')\n }\n /* c8 ignore stop */\n\n return filterAttributes(state, comparator, value, 'name', true)\n}\n"]}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import type { GraphLike } from '@vltpkg/graph';
|
|
2
|
+
import type { SpecOptions } from '@vltpkg/spec/browser';
|
|
3
|
+
import type { ParserState, QueryResponse } from './types.ts';
|
|
4
|
+
export * from './types.ts';
|
|
4
5
|
export declare const walk: (state: ParserState) => Promise<ParserState>;
|
|
5
6
|
export type QueryOptions = {
|
|
6
7
|
graph: GraphLike;
|
|
8
|
+
specOptions: SpecOptions;
|
|
7
9
|
};
|
|
8
10
|
export declare class Query {
|
|
9
11
|
#private;
|
|
10
|
-
constructor({ graph }: QueryOptions);
|
|
11
|
-
search(query: string): Promise<QueryResponse>;
|
|
12
|
+
constructor({ graph, specOptions }: QueryOptions);
|
|
13
|
+
search(query: string, signal?: AbortSignal): Promise<QueryResponse>;
|
|
12
14
|
}
|
|
13
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
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;AAYvD,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,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,SAAS,CAAA;IAChB,WAAW,EAAE,WAAW,CAAA;CACzB,CAAA;AAED,qBAAa,KAAK;;gBAKJ,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,YAAY;IAM1C,MAAM,CACV,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,aAAa,CAAC;CAkD1B"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { error } from '@vltpkg/error-cause';
|
|
2
2
|
import postcssSelectorParser from 'postcss-selector-parser';
|
|
3
|
-
import { attribute } from
|
|
4
|
-
import { classFn } from
|
|
5
|
-
import { combinator } from
|
|
6
|
-
import { id } from
|
|
7
|
-
import { pseudo } from
|
|
8
|
-
import { isPostcssNodeWithChildren, asPostcssNodeWithChildren, isSelectorNode, } from
|
|
9
|
-
export * from
|
|
3
|
+
import { attribute } from "./attribute.js";
|
|
4
|
+
import { classFn } from "./class.js";
|
|
5
|
+
import { combinator } from "./combinator.js";
|
|
6
|
+
import { id } from "./id.js";
|
|
7
|
+
import { pseudo } from "./pseudo.js";
|
|
8
|
+
import { isPostcssNodeWithChildren, asPostcssNodeWithChildren, isSelectorNode, } from "./types.js";
|
|
9
|
+
export * from "./types.js";
|
|
10
10
|
const noopFn = async (state) => state;
|
|
11
11
|
const selectors = {
|
|
12
12
|
attribute,
|
|
@@ -35,6 +35,7 @@ const selectors = {
|
|
|
35
35
|
};
|
|
36
36
|
const selectorsMap = new Map(Object.entries(selectors));
|
|
37
37
|
export const walk = async (state) => {
|
|
38
|
+
await state.cancellable();
|
|
38
39
|
const parserFn = selectorsMap.get(state.current.type);
|
|
39
40
|
if (!parserFn) {
|
|
40
41
|
if (state.loose) {
|
|
@@ -76,11 +77,13 @@ export const walk = async (state) => {
|
|
|
76
77
|
export class Query {
|
|
77
78
|
#cache;
|
|
78
79
|
#graph;
|
|
79
|
-
|
|
80
|
+
#specOptions;
|
|
81
|
+
constructor({ graph, specOptions }) {
|
|
80
82
|
this.#cache = new Map();
|
|
81
83
|
this.#graph = graph;
|
|
84
|
+
this.#specOptions = specOptions;
|
|
82
85
|
}
|
|
83
|
-
async search(query) {
|
|
86
|
+
async search(query, signal) {
|
|
84
87
|
if (typeof query !== 'string') {
|
|
85
88
|
throw new TypeError('Query search argument needs to be a string');
|
|
86
89
|
}
|
|
@@ -95,6 +98,12 @@ export class Query {
|
|
|
95
98
|
// builds initial state and walks over it,
|
|
96
99
|
// retrieving the collected result
|
|
97
100
|
const { collect } = await walk({
|
|
101
|
+
cancellable: async () => {
|
|
102
|
+
await new Promise(resolve => {
|
|
103
|
+
setTimeout(resolve, 0);
|
|
104
|
+
});
|
|
105
|
+
signal?.throwIfAborted();
|
|
106
|
+
},
|
|
98
107
|
current: postcssSelectorParser().astSync(query),
|
|
99
108
|
initial: {
|
|
100
109
|
nodes: new Set(nodes),
|
|
@@ -105,6 +114,8 @@ export class Query {
|
|
|
105
114
|
edges: new Set(),
|
|
106
115
|
},
|
|
107
116
|
partial: { nodes, edges },
|
|
117
|
+
signal,
|
|
118
|
+
specOptions: this.#specOptions,
|
|
108
119
|
walk,
|
|
109
120
|
});
|
|
110
121
|
const res = {
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAG3C,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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AI,OAAO,CAAC,OAAO,CAAC,EAAE;oBAC1B,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;gBACxB,CAAC,CAAC,CAAA;gBACF,MAAM,EAAE,cAAc,EAAE,CAAA;YAC1B,CAAC;YACD,OAAO,EAAE,qBAAqB,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;YAC/C,OAAO,EAAE;gBACP,KAAK,EAAE,IAAI,GAAG,CAAC,KAAK,CAAC;gBACrB,KAAK,EAAE,IAAI,GAAG,CAAC,KAAK,CAAC;aACtB;YACD,OAAO,EAAE;gBACP,KAAK,EAAE,IAAI,GAAG,EAAY;gBAC1B,KAAK,EAAE,IAAI,GAAG,EAAY;aAC3B;YACD,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE;YACzB,MAAM;YACN,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 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}\n\nexport class Query {\n #cache: Map<string, QueryResponse>\n #graph: GraphLike\n #specOptions: SpecOptions\n\n constructor({ graph, specOptions }: QueryOptions) {\n this.#cache = new Map()\n this.#graph = graph\n this.#specOptions = specOptions\n }\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 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,18 @@
|
|
|
1
|
+
import type { ParserState, PostcssNode } from '../types.ts';
|
|
2
|
+
export type AttrInternals = {
|
|
3
|
+
attribute: string;
|
|
4
|
+
insensitive: boolean;
|
|
5
|
+
operator?: string;
|
|
6
|
+
value?: string;
|
|
7
|
+
properties: string[];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Parses the internal / nested selectors of a `:attr` selector.
|
|
11
|
+
*/
|
|
12
|
+
export declare const parseInternals: (nodes: PostcssNode[]) => AttrInternals;
|
|
13
|
+
/**
|
|
14
|
+
* :attr Pseudo-Selector, allows for retrieving nodes based on nested
|
|
15
|
+
* properties of the `package.json` metadata.
|
|
16
|
+
*/
|
|
17
|
+
export declare const attr: (state: ParserState) => Promise<ParserState>;
|
|
18
|
+
//# sourceMappingURL=attr.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attr.d.ts","sourceRoot":"","sources":["../../../src/pseudo/attr.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAM3D,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,aAsBF,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,IAAI,UAAiB,WAAW,yBA8B5C,CAAA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { error } from '@vltpkg/error-cause';
|
|
2
|
+
import { asAttributeNode, asPostcssNodeWithChildren, asTagNode, } from "../types.js";
|
|
3
|
+
import { attributeSelectorsMap, filterAttributes, } from "../attribute.js";
|
|
4
|
+
/**
|
|
5
|
+
* Parses the internal / nested selectors of a `:attr` selector.
|
|
6
|
+
*/
|
|
7
|
+
export const parseInternals = (nodes) => {
|
|
8
|
+
// the last part is the attribute selector
|
|
9
|
+
const attributeSelector = asAttributeNode(asPostcssNodeWithChildren(nodes.pop()).nodes[0]);
|
|
10
|
+
// all preppending selectors are naming nested properties
|
|
11
|
+
const properties = [];
|
|
12
|
+
for (const selector of nodes) {
|
|
13
|
+
properties.push(asTagNode(asPostcssNodeWithChildren(selector).nodes[0]).value);
|
|
14
|
+
}
|
|
15
|
+
// include the attribute selector as the last part of the property lookup
|
|
16
|
+
properties.push(attributeSelector.attribute);
|
|
17
|
+
return {
|
|
18
|
+
attribute: attributeSelector.attribute,
|
|
19
|
+
insensitive: attributeSelector.insensitive || false,
|
|
20
|
+
operator: attributeSelector.operator,
|
|
21
|
+
value: attributeSelector.value,
|
|
22
|
+
properties,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* :attr Pseudo-Selector, allows for retrieving nodes based on nested
|
|
27
|
+
* properties of the `package.json` metadata.
|
|
28
|
+
*/
|
|
29
|
+
export const attr = async (state) => {
|
|
30
|
+
// Parses and retrieves the values for the nested selectors
|
|
31
|
+
let internals;
|
|
32
|
+
try {
|
|
33
|
+
internals = parseInternals(asPostcssNodeWithChildren(state.current).nodes);
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
throw error('Failed to parse :attr selector', {
|
|
37
|
+
cause: err,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
// reuses the attribute selector logic to filter the nodes
|
|
41
|
+
const comparator = internals.operator ?
|
|
42
|
+
attributeSelectorsMap.get(internals.operator)
|
|
43
|
+
: undefined;
|
|
44
|
+
const value = internals.value || '';
|
|
45
|
+
const propertyName = internals.attribute;
|
|
46
|
+
const insensitive = internals.insensitive;
|
|
47
|
+
const prefixProperties = internals.properties;
|
|
48
|
+
return filterAttributes(state, comparator, value, propertyName, insensitive, prefixProperties);
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=attr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attr.js","sourceRoot":"","sources":["../../../src/pseudo/attr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EACL,eAAe,EACf,yBAAyB,EACzB,SAAS,GACV,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,iBAAiB,CAAA;AAUxB;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,KAAoB,EACL,EAAE;IACjB,0CAA0C;IAC1C,MAAM,iBAAiB,GAAG,eAAe,CACvC,yBAAyB,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAChD,CAAA;IACD,y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G,SAAS,CAAC,UAAU,CAAA;IAC7C,OAAO,gBAAgB,CACrB,KAAK,EACL,UAAU,EACV,KAAK,EACL,YAAY,EACZ,WAAW,EACX,gBAAgB,CACjB,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport {\n asAttributeNode,\n asPostcssNodeWithChildren,\n asTagNode,\n} from '../types.ts'\nimport type { ParserState, PostcssNode } from '../types.ts'\nimport {\n attributeSelectorsMap,\n filterAttributes,\n} from '../attribute.ts'\n\nexport type AttrInternals = {\n attribute: string\n insensitive: boolean\n operator?: string\n value?: string\n properties: string[]\n}\n\n/**\n * Parses the internal / nested selectors of a `:attr` selector.\n */\nexport const parseInternals = (\n nodes: PostcssNode[],\n): AttrInternals => {\n // the last part is the attribute selector\n const attributeSelector = asAttributeNode(\n asPostcssNodeWithChildren(nodes.pop()).nodes[0],\n )\n // all preppending selectors are naming nested properties\n const properties: string[] = []\n for (const selector of nodes) {\n properties.push(\n asTagNode(asPostcssNodeWithChildren(selector).nodes[0]).value,\n )\n }\n // include the attribute selector as the last part of the property lookup\n properties.push(attributeSelector.attribute)\n\n return {\n attribute: attributeSelector.attribute,\n insensitive: attributeSelector.insensitive || false,\n operator: attributeSelector.operator,\n value: attributeSelector.value,\n properties,\n }\n}\n\n/**\n * :attr Pseudo-Selector, allows for retrieving nodes based on nested\n * properties of the `package.json` metadata.\n */\nexport const attr = async (state: ParserState) => {\n // Parses and retrieves the values for the nested selectors\n let internals\n try {\n internals = parseInternals(\n asPostcssNodeWithChildren(state.current).nodes,\n )\n } catch (err) {\n throw error('Failed to parse :attr selector', {\n cause: err,\n })\n }\n\n // reuses the attribute selector logic to filter the nodes\n const comparator =\n internals.operator ?\n attributeSelectorsMap.get(internals.operator)\n : undefined\n const value = internals.value || ''\n const propertyName = internals.attribute\n const insensitive = internals.insensitive\n const prefixProperties = internals.properties\n return filterAttributes(\n state,\n comparator,\n value,\n propertyName,\n insensitive,\n prefixProperties,\n )\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { NodeLike } from '@vltpkg/graph';
|
|
2
|
+
import type { ParserState } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Removes a node and its incoming edges from the results.
|
|
5
|
+
*/
|
|
6
|
+
export declare const removeNode: (state: ParserState, node: NodeLike) => void;
|
|
7
|
+
/**
|
|
8
|
+
* Removes any edges that have no destination node from the results.
|
|
9
|
+
*/
|
|
10
|
+
export declare const removeDanglingEdges: (state: ParserState) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Removes quotes from a string value.
|
|
13
|
+
*/
|
|
14
|
+
export declare const removeQuotes: (value: string) => string;
|
|
15
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/pseudo/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C;;GAEG;AACH,eAAO,MAAM,UAAU,UAAW,WAAW,QAAQ,QAAQ,SAK5D,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,mBAAmB,UAAW,WAAW,SAMrD,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,UAAW,MAAM,WACR,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes a node and its incoming edges from the results.
|
|
3
|
+
*/
|
|
4
|
+
export const removeNode = (state, node) => {
|
|
5
|
+
for (const edge of node.edgesIn) {
|
|
6
|
+
state.partial.edges.delete(edge);
|
|
7
|
+
}
|
|
8
|
+
state.partial.nodes.delete(node);
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Removes any edges that have no destination node from the results.
|
|
12
|
+
*/
|
|
13
|
+
export const removeDanglingEdges = (state) => {
|
|
14
|
+
for (const edge of state.partial.edges) {
|
|
15
|
+
if (!edge.to) {
|
|
16
|
+
state.partial.edges.delete(edge);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Removes quotes from a string value.
|
|
22
|
+
*/
|
|
23
|
+
export const removeQuotes = (value) => value.replace(/^"(.*?)"$/, '$1');
|
|
24
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/pseudo/helpers.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAkB,EAAE,IAAc,EAAE,EAAE;IAC/D,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QAChC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAClC,CAAC;IACD,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;AAClC,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAAkB,EAAE,EAAE;IACxD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACvC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACb,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QAClC,CAAC;IACH,CAAC;AACH,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAa,EAAE,EAAE,CAC5C,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA","sourcesContent":["import type { NodeLike } from '@vltpkg/graph'\nimport type { ParserState } from '../types.js'\n\n/**\n * Removes a node and its incoming edges from the results.\n */\nexport const removeNode = (state: ParserState, 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/**\n * Removes any edges that have no destination node from the results.\n */\nexport const removeDanglingEdges = (state: ParserState) => {\n for (const edge of state.partial.edges) {\n if (!edge.to) {\n state.partial.edges.delete(edge)\n }\n }\n}\n\n/**\n * Removes quotes from a string value.\n */\nexport const removeQuotes = (value: string) =>\n value.replace(/^\"(.*?)\"$/, '$1')\n"]}
|