@vltpkg/query 0.0.0-0.1730239248325
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/LICENSE +15 -0
- package/README.md +90 -0
- package/dist/esm/attribute.d.ts +15 -0
- package/dist/esm/attribute.d.ts.map +1 -0
- package/dist/esm/attribute.js +131 -0
- package/dist/esm/attribute.js.map +1 -0
- package/dist/esm/class.d.ts +6 -0
- package/dist/esm/class.d.ts.map +1 -0
- package/dist/esm/class.js +127 -0
- package/dist/esm/class.js.map +1 -0
- package/dist/esm/combinator.d.ts +6 -0
- package/dist/esm/combinator.d.ts.map +1 -0
- package/dist/esm/combinator.js +108 -0
- package/dist/esm/combinator.js.map +1 -0
- package/dist/esm/id.d.ts +6 -0
- package/dist/esm/id.d.ts.map +1 -0
- package/dist/esm/id.js +20 -0
- package/dist/esm/id.js.map +1 -0
- package/dist/esm/index.d.ts +13 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +118 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/pseudo.d.ts +13 -0
- package/dist/esm/pseudo.d.ts.map +1 -0
- package/dist/esm/pseudo.js +365 -0
- package/dist/esm/pseudo.js.map +1 -0
- package/dist/esm/types.d.ts +40 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +93 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { error } from '@vltpkg/error-cause';
|
|
2
|
+
export const isPostcssNodeWithChildren = (node) => 'type' in node && 'nodes' in node;
|
|
3
|
+
export const asPostcssNodeWithChildren = (node) => {
|
|
4
|
+
if (!node) {
|
|
5
|
+
throw error('Expected a query node');
|
|
6
|
+
}
|
|
7
|
+
if (!isPostcssNodeWithChildren(node)) {
|
|
8
|
+
throw error('Not a query selector node with children', {
|
|
9
|
+
found: node,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
return node;
|
|
13
|
+
};
|
|
14
|
+
export const isAttributeNode = (node) => node.attribute && node.type === 'attribute';
|
|
15
|
+
export const asAttributeNode = (node) => {
|
|
16
|
+
if (!node) {
|
|
17
|
+
throw error('Expected a query node');
|
|
18
|
+
}
|
|
19
|
+
if (!isAttributeNode(node)) {
|
|
20
|
+
throw error('Mismatching query node', {
|
|
21
|
+
wanted: 'attribute',
|
|
22
|
+
found: node.type,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return node;
|
|
26
|
+
};
|
|
27
|
+
export const isClassNode = (node) => node.value && node.type === 'class';
|
|
28
|
+
export const asClassNode = (node) => {
|
|
29
|
+
if (!node) {
|
|
30
|
+
throw error('Expected a query node');
|
|
31
|
+
}
|
|
32
|
+
if (!isClassNode(node)) {
|
|
33
|
+
throw error('Mismatching query node', {
|
|
34
|
+
wanted: 'class',
|
|
35
|
+
found: node.type,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return node;
|
|
39
|
+
};
|
|
40
|
+
export const isCombinatorNode = (node) => node.value && node.type === 'combinator';
|
|
41
|
+
export const asCombinatorNode = (node) => {
|
|
42
|
+
if (!node) {
|
|
43
|
+
throw error('Expected a query node');
|
|
44
|
+
}
|
|
45
|
+
if (!isCombinatorNode(node)) {
|
|
46
|
+
throw error('Mismatching query node', {
|
|
47
|
+
wanted: 'combinator',
|
|
48
|
+
found: node.type,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return node;
|
|
52
|
+
};
|
|
53
|
+
export const isIdentifierNode = (node) => node.value && node.type === 'id';
|
|
54
|
+
export const asIdentifierNode = (node) => {
|
|
55
|
+
if (!node) {
|
|
56
|
+
throw error('Expected a query node');
|
|
57
|
+
}
|
|
58
|
+
if (!isIdentifierNode(node)) {
|
|
59
|
+
throw error('Mismatching query node', {
|
|
60
|
+
wanted: 'id',
|
|
61
|
+
found: node.type,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return node;
|
|
65
|
+
};
|
|
66
|
+
export const isSelectorNode = (node) => isPostcssNodeWithChildren(node) && node.type === 'selector';
|
|
67
|
+
export const isPseudoNode = (node) => node.value && node.type === 'pseudo';
|
|
68
|
+
export const asPseudoNode = (node) => {
|
|
69
|
+
if (!node) {
|
|
70
|
+
throw error('Expected a query node');
|
|
71
|
+
}
|
|
72
|
+
if (!isPseudoNode(node)) {
|
|
73
|
+
throw error('Mismatching query node', {
|
|
74
|
+
wanted: 'pseudo',
|
|
75
|
+
found: node.type,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return node;
|
|
79
|
+
};
|
|
80
|
+
export const isTagNode = (node) => node.value && node.type === 'tag';
|
|
81
|
+
export const asTagNode = (node) => {
|
|
82
|
+
if (!node) {
|
|
83
|
+
throw error('Expected a query node');
|
|
84
|
+
}
|
|
85
|
+
if (!isTagNode(node)) {
|
|
86
|
+
throw error('Mismatching query node', {
|
|
87
|
+
wanted: 'tag',
|
|
88
|
+
found: node.type,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return node;
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAyD3C,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,IAAS,EACwB,EAAE,CACnC,MAAM,IAAI,IAAI,IAAI,OAAO,IAAI,IAAI,CAAA;AAEnC,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,IAAkB,EACO,EAAE;IAC3B,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,KAAK,CAAC,uBAAuB,CAAC,CAAA;IACtC,CAAC;IAED,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,EAAE,CAAC;QACrC,MAAM,KAAK,CAAC,yCAAyC,EAAE;YACr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AAI,EAAE,CAAC;QACV,MAAM,KAAK,CAAC,uBAAuB,CAAC,CAAA;IACtC,CAAC;IAED,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,MAAM,KAAK,CAAC,wBAAwB,EAAE;YACpC,MAAM,EAAE,QAAQ;YAChB,KAAK,EAAE,IAAI,CAAC,IAAI;SACjB,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAS,EAAe,EAAE,CAClD,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,CAAA;AAEnC,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAkB,EAAO,EAAE;IACnD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,KAAK,CAAC,uBAAuB,CAAC,CAAA;IACtC,CAAC;IAED,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;QACrB,MAAM,KAAK,CAAC,wBAAwB,EAAE;YACpC,MAAM,EAAE,KAAK;YACb,KAAK,EAAE,IAAI,CAAC,IAAI;SACjB,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport type { EdgeLike, NodeLike } from '@vltpkg/graph'\nimport type {\n Tag,\n String,\n Selector,\n Root,\n Pseudo,\n Nesting,\n Identifier,\n Comment,\n Combinator,\n ClassName,\n Attribute,\n Universal,\n} from 'postcss-selector-parser'\n\nexport type PostcssNode =\n | Tag\n | String\n | Selector\n | Root\n | Pseudo\n | Nesting\n | Identifier\n | Comment\n | Combinator\n | ClassName\n | Attribute\n | Universal\n\nexport type PostcssNodeWithChildren = Selector | Root | Pseudo\n\nexport type GraphSelectionState = {\n nodes: Set<NodeLike>\n edges: Set<EdgeLike>\n}\n\nexport type ParserState = {\n collect: GraphSelectionState\n current: PostcssNode\n initial: GraphSelectionState\n loose?: boolean\n next?: PostcssNode\n prev?: PostcssNode\n result?: NodeLike[]\n walk: ParserFn\n partial: GraphSelectionState\n}\n\nexport type QueryResponse = {\n edges: EdgeLike[]\n nodes: NodeLike[]\n}\n\nexport type ParserFn = (opt: ParserState) => Promise<ParserState>\n\nexport const isPostcssNodeWithChildren = (\n node: any,\n): node is PostcssNodeWithChildren =>\n 'type' in node && 'nodes' in node\n\nexport const asPostcssNodeWithChildren = (\n node?: PostcssNode,\n): PostcssNodeWithChildren => {\n if (!node) {\n throw error('Expected a query node')\n }\n\n if (!isPostcssNodeWithChildren(node)) {\n throw error('Not a query selector node with children', {\n found: node,\n })\n }\n return node\n}\n\nexport const isAttributeNode = (node: any): node is Attribute =>\n node.attribute && node.type === 'attribute'\n\nexport const asAttributeNode = (node?: PostcssNode): Attribute => {\n if (!node) {\n throw error('Expected a query node')\n }\n\n if (!isAttributeNode(node)) {\n throw error('Mismatching query node', {\n wanted: 'attribute',\n found: node.type,\n })\n }\n return node\n}\n\nexport const isClassNode = (node: any): node is ClassName =>\n node.value && node.type === 'class'\n\nexport const asClassNode = (node?: PostcssNode): ClassName => {\n if (!node) {\n throw error('Expected a query node')\n }\n\n if (!isClassNode(node)) {\n throw error('Mismatching query node', {\n wanted: 'class',\n found: node.type,\n })\n }\n return node\n}\n\nexport const isCombinatorNode = (node: any): node is Combinator =>\n node.value && node.type === 'combinator'\n\nexport const asCombinatorNode = (node?: PostcssNode): Combinator => {\n if (!node) {\n throw error('Expected a query node')\n }\n\n if (!isCombinatorNode(node)) {\n throw error('Mismatching query node', {\n wanted: 'combinator',\n found: node.type,\n })\n }\n return node\n}\n\nexport const isIdentifierNode = (node: any): node is Identifier =>\n node.value && node.type === 'id'\n\nexport const asIdentifierNode = (node?: PostcssNode): Identifier => {\n if (!node) {\n throw error('Expected a query node')\n }\n\n if (!isIdentifierNode(node)) {\n throw error('Mismatching query node', {\n wanted: 'id',\n found: node.type,\n })\n }\n return node\n}\n\nexport const isSelectorNode = (node: any): node is Selector =>\n isPostcssNodeWithChildren(node) && node.type === 'selector'\n\nexport const isPseudoNode = (node: any): node is Pseudo =>\n node.value && node.type === 'pseudo'\n\nexport const asPseudoNode = (node?: PostcssNode): Pseudo => {\n if (!node) {\n throw error('Expected a query node')\n }\n\n if (!isPseudoNode(node)) {\n throw error('Mismatching query node', {\n wanted: 'pseudo',\n found: node.type,\n })\n }\n return node\n}\n\nexport const isTagNode = (node: any): node is Tag =>\n node.value && node.type === 'tag'\n\nexport const asTagNode = (node?: PostcssNode): Tag => {\n if (!node) {\n throw error('Expected a query node')\n }\n\n if (!isTagNode(node)) {\n throw error('Mismatching query node', {\n wanted: 'tag',\n found: node.type,\n })\n }\n\n return node\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vltpkg/query",
|
|
3
|
+
"description": "Query syntax parser that retrieves items from a graph",
|
|
4
|
+
"version": "0.0.0-0.1730239248325",
|
|
5
|
+
"tshy": {
|
|
6
|
+
"selfLink": false,
|
|
7
|
+
"dialects": [
|
|
8
|
+
"esm"
|
|
9
|
+
],
|
|
10
|
+
"exports": {
|
|
11
|
+
"./package.json": "./package.json",
|
|
12
|
+
".": "./src/index.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"postcss-selector-parser": "^6.1.2",
|
|
17
|
+
"@vltpkg/dep-id": "0.0.0-0.1730239248325",
|
|
18
|
+
"@vltpkg/error-cause": "0.0.0-0.1730239248325",
|
|
19
|
+
"@vltpkg/graph": "0.0.0-0.1730239248325",
|
|
20
|
+
"@vltpkg/types": "0.0.0-0.1730239248325"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@eslint/js": "^9.8.0",
|
|
24
|
+
"@types/eslint__js": "^8.42.3",
|
|
25
|
+
"@types/node": "^22.4.1",
|
|
26
|
+
"eslint": "^9.8.0",
|
|
27
|
+
"prettier": "^3.3.2",
|
|
28
|
+
"tap": "^21.0.1",
|
|
29
|
+
"tshy": "^3.0.2",
|
|
30
|
+
"typescript": "^5.5.4",
|
|
31
|
+
"typescript-eslint": "^8.0.1",
|
|
32
|
+
"@vltpkg/spec": "0.0.0-0.1730239248325"
|
|
33
|
+
},
|
|
34
|
+
"license": "BSD-2-Clause-Patent",
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": "20 || >=22"
|
|
37
|
+
},
|
|
38
|
+
"tap": {
|
|
39
|
+
"extends": "../../tap-config.yaml"
|
|
40
|
+
},
|
|
41
|
+
"prettier": "../../.prettierrc.js",
|
|
42
|
+
"module": "./dist/esm/index.js",
|
|
43
|
+
"type": "module",
|
|
44
|
+
"exports": {
|
|
45
|
+
"./package.json": "./package.json",
|
|
46
|
+
".": {
|
|
47
|
+
"import": {
|
|
48
|
+
"types": "./dist/esm/index.d.ts",
|
|
49
|
+
"default": "./dist/esm/index.js"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"files": [
|
|
54
|
+
"dist"
|
|
55
|
+
],
|
|
56
|
+
"scripts": {
|
|
57
|
+
"format": "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
|
|
58
|
+
"format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
|
|
59
|
+
"lint": "eslint . --fix",
|
|
60
|
+
"lint:check": "eslint .",
|
|
61
|
+
"presnap": "tshy",
|
|
62
|
+
"snap": "tap",
|
|
63
|
+
"pretest": "tshy",
|
|
64
|
+
"test": "tap"
|
|
65
|
+
}
|
|
66
|
+
}
|