@swagger-api/apidom-parser-adapter-yaml-1-2 0.68.1

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 (33) hide show
  1. package/CHANGELOG.md +373 -0
  2. package/LICENSES/Apache-2.0.txt +202 -0
  3. package/LICENSES/MIT.txt +9 -0
  4. package/NOTICE +57 -0
  5. package/README.md +97 -0
  6. package/cjs/adapter-browser.cjs +30 -0
  7. package/cjs/adapter-node.cjs +30 -0
  8. package/cjs/adapter.cjs +10 -0
  9. package/cjs/lexical-analysis/browser-patch.cjs +20 -0
  10. package/cjs/lexical-analysis/browser.cjs +42 -0
  11. package/cjs/lexical-analysis/node.cjs +21 -0
  12. package/cjs/media-types.cjs +14 -0
  13. package/cjs/syntactic-analysis/index.cjs +43 -0
  14. package/cjs/syntactic-analysis/visitors/CstVisitor.cjs +573 -0
  15. package/cjs/syntactic-analysis/visitors/YamlAstVisitor.cjs +177 -0
  16. package/dist/apidom-parser-adapter-yaml-1-2.browser.js +32701 -0
  17. package/dist/apidom-parser-adapter-yaml1-2.browser.min.js +2 -0
  18. package/dist/apidom-parser-adapter-yaml1-2.browser.min.js.LICENSE.txt +6 -0
  19. package/dist/d396281e11774e0afa7a40d620779b6d.wasm +0 -0
  20. package/dist/fba0b3cc0d7ee926ea482deee298a5fe.wasm +0 -0
  21. package/es/adapter-browser.js +20 -0
  22. package/es/adapter-node.js +20 -0
  23. package/es/adapter.js +3 -0
  24. package/es/lexical-analysis/browser-patch.js +17 -0
  25. package/es/lexical-analysis/browser.js +36 -0
  26. package/es/lexical-analysis/node.js +14 -0
  27. package/es/media-types.js +8 -0
  28. package/es/syntactic-analysis/index.js +36 -0
  29. package/es/syntactic-analysis/visitors/CstVisitor.js +566 -0
  30. package/es/syntactic-analysis/visitors/YamlAstVisitor.js +171 -0
  31. package/package.json +80 -0
  32. package/types/dist.d.ts +39 -0
  33. package/wasm/tree-sitter-yaml.wasm +0 -0
@@ -0,0 +1,171 @@
1
+ import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
2
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+ import stampit from 'stampit';
5
+ import { getNodeType as getCSTNodeType, isNode as isCSTNode, YamlStyle } from '@swagger-api/apidom-ast';
6
+ import { ParseResultElement, AnnotationElement, CommentElement, SourceMapElement, MemberElement, ObjectElement, ArrayElement, isPrimitiveElement, isElement, keyMap as keyMapApiDOM, getNodeType as getNodeTypeApiDOM, createNamespace } from '@swagger-api/apidom-core';
7
+ export const keyMap = _objectSpread({
8
+ stream: ['children'],
9
+ document: ['children'],
10
+ mapping: ['children'],
11
+ keyValuePair: ['children'],
12
+ sequence: ['children'],
13
+ error: ['children']
14
+ }, keyMapApiDOM);
15
+ export const getNodeType = node => {
16
+ if (isElement(node)) {
17
+ return getNodeTypeApiDOM(node);
18
+ }
19
+ return getCSTNodeType(node);
20
+ };
21
+ export const isNode = node => isElement(node) || isCSTNode(node) || Array.isArray(node);
22
+
23
+ /* eslint-disable no-underscore-dangle */
24
+
25
+ const YamlAstVisitor = stampit({
26
+ props: {
27
+ sourceMap: false,
28
+ processedDocumentCount: 0,
29
+ annotations: [],
30
+ namespace: null
31
+ },
32
+ init() {
33
+ /**
34
+ * Private API.
35
+ */
36
+
37
+ const maybeAddSourceMap = (node, element) => {
38
+ if (!this.sourceMap) {
39
+ return;
40
+ }
41
+ const sourceMap = new SourceMapElement();
42
+ // @ts-ignore
43
+ sourceMap.position = node.position;
44
+ // @ts-ignore
45
+ sourceMap.astNode = node;
46
+ element.meta.set('sourceMap', sourceMap);
47
+ };
48
+
49
+ /**
50
+ * Public API.
51
+ */
52
+
53
+ this.namespace = createNamespace();
54
+ this.annotations = [];
55
+ this.stream = {
56
+ leave(node) {
57
+ const element = new ParseResultElement();
58
+ // @ts-ignore
59
+ element._content = node.children.flat(1);
60
+
61
+ // mark first-non Annotation element as result
62
+ // @ts-ignore
63
+ const elements = element.findElements(isPrimitiveElement);
64
+ if (elements.length > 0) {
65
+ const resultElement = elements[0];
66
+ resultElement.classes.push('result');
67
+ }
68
+
69
+ // provide annotations
70
+ this.annotations.forEach(annotationElement => {
71
+ element.push(annotationElement);
72
+ });
73
+ this.annotations = [];
74
+ return element;
75
+ }
76
+ };
77
+ this.comment = function comment(node) {
78
+ const isStreamComment = this.processedDocumentCount === 0;
79
+
80
+ // we're only interested of stream comments before the first document
81
+ if (isStreamComment) {
82
+ // @ts-ignore
83
+ const element = new CommentElement(node.content);
84
+ maybeAddSourceMap(node, element);
85
+ return element;
86
+ }
87
+ return null;
88
+ };
89
+ this.document = function document(node) {
90
+ const shouldWarnAboutMoreDocuments = this.processedDocumentCount === 1;
91
+ const shouldSkipVisitingMoreDocuments = this.processedDocumentCount >= 1;
92
+ if (shouldWarnAboutMoreDocuments) {
93
+ const message = 'Only first document within YAML stream will be used. Rest will be discarded.';
94
+ const element = new AnnotationElement(message);
95
+ element.classes.push('warning');
96
+ maybeAddSourceMap(node, element);
97
+ this.annotations.push(element);
98
+ }
99
+ if (shouldSkipVisitingMoreDocuments) {
100
+ return null;
101
+ }
102
+ this.processedDocumentCount += 1;
103
+ return node.children;
104
+ };
105
+ this.mapping = function mapping(node) {
106
+ const element = new ObjectElement();
107
+ // @ts-ignore
108
+ element._content = node.children;
109
+ maybeAddSourceMap(node, element);
110
+ return element;
111
+ };
112
+ this.keyValuePair = function keyValuePair(node) {
113
+ const element = new MemberElement();
114
+
115
+ // @ts-ignore
116
+ element.content.key = node.key;
117
+ // @ts-ignore
118
+ element.content.value = node.value;
119
+ maybeAddSourceMap(node, element);
120
+
121
+ // process possible errors here that may be present in property node children as we're using direct field access
122
+ node.children.filter(child => child.type === 'error').forEach(errorNode => {
123
+ this.error(errorNode, node, [], [node]);
124
+ });
125
+ return element;
126
+ };
127
+ this.sequence = function sequence(node) {
128
+ const element = new ArrayElement();
129
+ // @ts-ignore
130
+ element._content = node.children;
131
+ maybeAddSourceMap(node, element);
132
+ return element;
133
+ };
134
+ this.scalar = function scalar(node) {
135
+ const element = this.namespace.toElement(node.content);
136
+
137
+ // translate style information about empty nodes
138
+ if (node.content === '' && node.style === YamlStyle.Plain) {
139
+ element.classes.push('yaml-e-node');
140
+ element.classes.push('yaml-e-scalar');
141
+ }
142
+ maybeAddSourceMap(node, element);
143
+ return element;
144
+ };
145
+ this.literal = function literal(node) {
146
+ if (node.isMissing) {
147
+ const message = `(Missing ${node.value})`;
148
+ const element = new AnnotationElement(message);
149
+ element.classes.push('warning');
150
+ maybeAddSourceMap(node, element);
151
+ this.annotations.push(element);
152
+ }
153
+ return null;
154
+ };
155
+ this.error = function error(node, key, parent, path) {
156
+ const message = node.isUnexpected ? `(Unexpected ${node.value})` : `(Error ${node.value})`;
157
+ const element = new AnnotationElement(message);
158
+ element.classes.push('error');
159
+ maybeAddSourceMap(node, element);
160
+ if (path.length === 0) {
161
+ // no document to visit, only error is present in CST
162
+ const parseResultElement = new ParseResultElement();
163
+ parseResultElement.push(element);
164
+ return parseResultElement;
165
+ }
166
+ this.annotations.push(element);
167
+ return null;
168
+ };
169
+ }
170
+ });
171
+ export default YamlAstVisitor;
package/package.json ADDED
@@ -0,0 +1,80 @@
1
+ {
2
+ "name": "@swagger-api/apidom-parser-adapter-yaml-1-2",
3
+ "version": "0.68.1",
4
+ "description": "Parser adapter for parsing YAML documents into base namespace.",
5
+ "publishConfig": {
6
+ "access": "public",
7
+ "registry": "https://registry.npmjs.org"
8
+ },
9
+ "type": "module",
10
+ "sideEffects": [
11
+ "./es/lexical-analysis/browser-patch.js",
12
+ "./cjs/lexical-analysis/browser-patch.cjs"
13
+ ],
14
+ "unpkg": "./dist/apidom-parser-apdater-yaml-1-2.browser.min.js",
15
+ "main": "./cjs/adapter-node.cjs",
16
+ "exports": {
17
+ "types": "./types/dist.d.ts",
18
+ "node": {
19
+ "import": "./es/adapter-node.js",
20
+ "require": "./cjs/adapter-node.cjs"
21
+ },
22
+ "browser": {
23
+ "import": "./es/adapter-browser.js"
24
+ },
25
+ "default": "./cjs/adapter-node.cjs"
26
+ },
27
+ "types": "./types/dist.d.ts",
28
+ "scripts": {
29
+ "build": "npm run clean && run-p --max-parallel ${CPU_CORES:-2} typescript:declaration build:es build:cjs build:umd:browser",
30
+ "build:es": "npm run build:wasm && npm run build:wasm:copy && cross-env BABEL_ENV=es babel src --out-dir es --extensions '.ts' --root-mode 'upward'",
31
+ "build:cjs": "npm run build:wasm && npm run build:wasm:copy && BABEL_ENV=cjs babel src --out-dir cjs --extensions '.ts' --out-file-extension '.cjs' --root-mode 'upward'",
32
+ "build:umd:browser": "npm run build:wasm && npm run build:wasm:copy && cross-env BABEL_ENV=browser BROWSERSLIST_ENV=production webpack --config config/webpack/browser.config.js --progress",
33
+ "build:wasm": "node ../../scripts/file-exists.js ../../node_modules/tree-sitter-yaml/tree-sitter-yaml.wasm && exit 0 || cd ../../node_modules/tree-sitter-yaml && cross-env BABEL_ENV=cjs NODE_OPTIONS='-r core-js/stable @babel/register' tree-sitter generate --abi=13 ./grammar.js && tree-sitter build-wasm && node-gyp rebuild",
34
+ "build:wasm:copy": "copyfiles -u 4 ../../node_modules/tree-sitter-yaml/tree-sitter-yaml.wasm wasm",
35
+ "lint": "eslint ./",
36
+ "lint:fix": "eslint ./ --fix",
37
+ "clean": "rimraf ./es ./cjs ./dist ./types",
38
+ "typescript:check-types": "tsc --noEmit",
39
+ "typescript:declaration": "tsc -p declaration.tsconfig.json && rollup -c config/rollup/types.dist.js",
40
+ "test": "cross-env NODE_ENV=test BABEL_ENV=cjs mocha",
41
+ "perf": "cross-env NODE_ENV=test BABEL_ENV=cjs node ./test/perf/index.cjs",
42
+ "perf:parse": "cross-env NODE_ENV=test BABEL_ENV=cjs node ./test/perf/parse.cjs",
43
+ "perf:lexical-analysis": "cross-env NODE_ENV=test BABEL_ENV=cjs node ./test/perf/lexical-analysis.cjs",
44
+ "prepack": "copyfiles -u 3 ../../LICENSES/* LICENSES && copyfiles -u 2 ../../NOTICE .",
45
+ "postpack": "rimraf NOTICE LICENSES"
46
+ },
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git+https://github.com/swagger-api/apidom.git"
50
+ },
51
+ "author": "Vladimir Gorej",
52
+ "license": "Apache-2.0",
53
+ "dependencies": {
54
+ "@babel/runtime-corejs3": "^7.20.7",
55
+ "@swagger-api/apidom-ast": "^0.68.0",
56
+ "@swagger-api/apidom-core": "^0.68.1",
57
+ "@types/ramda": "=0.28.23",
58
+ "ramda": "=0.28.0",
59
+ "ramda-adjunct": "=3.4.0",
60
+ "stampit": "=4.3.2",
61
+ "tree-sitter": "=0.20.1",
62
+ "tree-sitter-yaml": "=0.5.0",
63
+ "web-tree-sitter": "=0.20.7"
64
+ },
65
+ "devDependencies": {
66
+ "tree-sitter-cli": "=0.20.7"
67
+ },
68
+ "files": [
69
+ "cjs/",
70
+ "dist/",
71
+ "es/",
72
+ "types/dist.d.ts",
73
+ "wasm/",
74
+ "LICENSES",
75
+ "NOTICE",
76
+ "README.md",
77
+ "CHANGELOG.md"
78
+ ],
79
+ "gitHead": "d2bc706671f1b9a593b8f0c5bca8c501ad0e4cff"
80
+ }
@@ -0,0 +1,39 @@
1
+ import * as _swagger_api_apidom_core from '@swagger-api/apidom-core';
2
+ import { ParseResultElement, MediaTypes } from '@swagger-api/apidom-core';
3
+ import { Tree as Tree$1 } from 'web-tree-sitter';
4
+ import { Tree as Tree$2 } from 'tree-sitter';
5
+
6
+ /**
7
+ * Lexical Analysis of source string using WebTreeSitter.
8
+ * This is WebAssembly version of TreeSitters Lexical Analysis.
9
+ *
10
+ * Given JavaScript doesn't support true parallelism, this
11
+ * code should be as lazy as possible and temporal safety should be fine.
12
+ */
13
+ declare const analyze$1: (source: string) => Promise<Tree$1>;
14
+
15
+ type Tree = Tree$1 | Tree$2;
16
+ /**
17
+ * This version of syntactic analysis does following transformations:
18
+ * TreeSitter CST -> YAML AST -> ApiDOM
19
+ * Two traversals passes are needed to get from CST to ApiDOM.
20
+ */
21
+ declare const analyze: (cst: Tree, { sourceMap }?: {
22
+ sourceMap?: boolean | undefined;
23
+ }) => ParseResultElement;
24
+
25
+ declare class YamlMediaTypes extends MediaTypes<string> {
26
+ latest(): string;
27
+ }
28
+ declare const mediaTypes: YamlMediaTypes;
29
+
30
+ declare const namespace: _swagger_api_apidom_core.Namespace;
31
+
32
+ declare const detect: (source: string) => Promise<boolean>;
33
+ interface ParseFunctionOptions {
34
+ sourceMap?: boolean;
35
+ }
36
+ type ParseFunction = (source: string, options?: ParseFunctionOptions) => Promise<ParseResultElement>;
37
+ declare const parse: ParseFunction;
38
+
39
+ export { detect, analyze$1 as lexicalAnalysis, mediaTypes, namespace, parse, analyze as syntacticAnalysis };
Binary file