diff --git a/apidom/package-lock.json b/apidom/package-lock.json index 66aaeeec16..62d7846152 100644 --- a/apidom/package-lock.json +++ b/apidom/package-lock.json @@ -3621,7 +3621,7 @@ "ramda-adjunct": "=2.27.0", "stampit": "=4.3.1", "tree-sitter": "=0.17.0", - "tree-sitter-yaml": "=0.1.0", + "tree-sitter-yaml": "=0.2.0", "web-tree-sitter": "=0.17.0" } }, @@ -13365,9 +13365,9 @@ } }, "tree-sitter-yaml": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/tree-sitter-yaml/-/tree-sitter-yaml-0.1.0.tgz", - "integrity": "sha512-/ed3jIHQ0fMTKpl7fen+xkzHUMHS2ZMfxqfyTLfr9aHaExQ6VGy1ZcOV0c5/s2IgOQdUrnTu3otMELY6+B07tQ==", + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/tree-sitter-yaml/-/tree-sitter-yaml-0.2.0.tgz", + "integrity": "sha512-T5IjAZLPH1kR/PVrfQsjfFoNI1C35gfWeOH4E8bq3qH6mbmC4YoDDpCp+S+O70D9OAQ0kuYhYGWfdL4Hj0ogmQ==", "requires": { "nan": "^2.14.0" } diff --git a/apidom/packages/apidom-ast/package.json b/apidom/packages/apidom-ast/package.json index 9f4f5707ab..c54f73bf04 100644 --- a/apidom/packages/apidom-ast/package.json +++ b/apidom/packages/apidom-ast/package.json @@ -40,7 +40,7 @@ "stampit": "=4.3.1" }, "devDependencies": { - "tree-sitter": "=0.16.2", + "tree-sitter": "=0.17.0", "tree-sitter-json": "=0.16.0" } } diff --git a/apidom/packages/apidom-ast/src/index.ts b/apidom/packages/apidom-ast/src/index.ts index 3c9b55d12c..d5773e5918 100644 --- a/apidom/packages/apidom-ast/src/index.ts +++ b/apidom/packages/apidom-ast/src/index.ts @@ -26,6 +26,30 @@ export { isString as isJsonString, isTrue as isJsonTrue, } from './nodes/json/predicates'; +// YAML AST related exports +export { default as YamlAlias } from './nodes/yaml/YamlAlias'; +export { default as YamlCollection } from './nodes/yaml/YamlCollection'; +export { default as YamlComment } from './nodes/yaml/YamlComment'; +export { default as YamlDirective } from './nodes/yaml/YamlDirective'; +export { default as YamlDocument } from './nodes/yaml/YamlDocument'; +export { default as YamlKeyValuePair } from './nodes/yaml/YamlKeyValuePair'; +export { default as YamlMapping } from './nodes/yaml/YamlMapping'; +export { default as YamlNode } from './nodes/yaml/YamlNode'; +export { default as YamlScalar } from './nodes/yaml/YamlScalar'; +export { default as YamlSequence } from './nodes/yaml/YamlSequence'; +export { default as YamlStream } from './nodes/yaml/YamlStream'; +export { default as YamlTag } from './nodes/yaml/YamlTag'; +export { + isAlias as isYamlAlias, + isKeyValuePair as isYamlKeyValuePair, + isDirective as isYamlDirective, + isDocument as isYamlDocument, + isMapping as isYamlMapping, + isScalar as isYamlScalar, + isSequence as isYamlSequence, + isStream as isYamlStream, + isTag as isYamlTag, +} from './nodes/yaml/predicates'; // generic AST related exports export { default as Literal } from './Literal'; export { Point, default as Position } from './Position'; diff --git a/apidom/packages/apidom-ast/src/nodes/json/JsonArray.ts b/apidom/packages/apidom-ast/src/nodes/json/JsonArray.ts index 6bf218826c..bd8a77a2be 100644 --- a/apidom/packages/apidom-ast/src/nodes/json/JsonArray.ts +++ b/apidom/packages/apidom-ast/src/nodes/json/JsonArray.ts @@ -4,7 +4,7 @@ import { anyPass } from 'ramda'; import JsonNode from './JsonNode'; import { isFalse, isTrue, isNull, isNumber, isString, isArray, isObject } from './predicates'; -type JsonArray = Node; +type JsonArray = JsonNode; const JsonArray: stampit.Stamp = stampit(JsonNode, { statics: { diff --git a/apidom/packages/apidom-ast/src/nodes/json/JsonDocument.ts b/apidom/packages/apidom-ast/src/nodes/json/JsonDocument.ts index 315b4607ce..35bcb7f1f4 100644 --- a/apidom/packages/apidom-ast/src/nodes/json/JsonDocument.ts +++ b/apidom/packages/apidom-ast/src/nodes/json/JsonDocument.ts @@ -3,7 +3,7 @@ import { head } from 'ramda'; import JsonNode from './JsonNode'; -interface JsonDocument extends Node { +interface JsonDocument extends JsonNode { child: unknown | null; } diff --git a/apidom/packages/apidom-ast/src/nodes/json/JsonObject.ts b/apidom/packages/apidom-ast/src/nodes/json/JsonObject.ts index 04d925aed5..7a445ade90 100644 --- a/apidom/packages/apidom-ast/src/nodes/json/JsonObject.ts +++ b/apidom/packages/apidom-ast/src/nodes/json/JsonObject.ts @@ -1,6 +1,7 @@ import stampit from 'stampit'; import JsonNode from './JsonNode'; +import JsonProperty from './JsonProperty'; import { isProperty } from './predicates'; type JsonObject = JsonNode; @@ -10,7 +11,7 @@ const JsonObject: stampit.Stamp = stampit(JsonNode, { type: 'object', }, methods: { - get properties(): unknown[] { + get properties(): Array { // @ts-ignore return this.children.filter(isProperty); }, diff --git a/apidom/packages/apidom-ast/src/nodes/json/JsonProperty.ts b/apidom/packages/apidom-ast/src/nodes/json/JsonProperty.ts index 010a8ad188..fcd1269d55 100644 --- a/apidom/packages/apidom-ast/src/nodes/json/JsonProperty.ts +++ b/apidom/packages/apidom-ast/src/nodes/json/JsonProperty.ts @@ -14,7 +14,7 @@ import { isTrue, } from './predicates'; -interface JsonProperty extends Node { +interface JsonProperty extends JsonNode { key: JsonKey; value: unknown; } diff --git a/apidom/packages/apidom-ast/src/nodes/json/JsonString.ts b/apidom/packages/apidom-ast/src/nodes/json/JsonString.ts index f1870d6a3a..73d910805f 100644 --- a/apidom/packages/apidom-ast/src/nodes/json/JsonString.ts +++ b/apidom/packages/apidom-ast/src/nodes/json/JsonString.ts @@ -6,7 +6,7 @@ import JsonStringContent from './JsonStringContent'; import JsonEscapeSequence from './JsonEscapeSequence'; import { isEscapeSequence, isStringContent } from './predicates'; -interface JsonString extends Node { +interface JsonString extends JsonNode { value: string; } diff --git a/apidom/packages/apidom-ast/src/nodes/yaml/YamlAlias.ts b/apidom/packages/apidom-ast/src/nodes/yaml/YamlAlias.ts new file mode 100644 index 0000000000..11565ff8ab --- /dev/null +++ b/apidom/packages/apidom-ast/src/nodes/yaml/YamlAlias.ts @@ -0,0 +1,22 @@ +import stampit from 'stampit'; + +import Node from '../../Node'; + +interface YamlAlias extends Node { + type: 'alias'; + content: string | null; +} + +const YamlAlias: stampit.Stamp = stampit(Node, { + statics: { + type: 'alias', + }, + props: { + content: null, + }, + init({ content = null } = {}) { + this.content = content; + }, +}); + +export default YamlAlias; diff --git a/apidom/packages/apidom-ast/src/nodes/yaml/YamlCollection.ts b/apidom/packages/apidom-ast/src/nodes/yaml/YamlCollection.ts new file mode 100644 index 0000000000..a00233cf5c --- /dev/null +++ b/apidom/packages/apidom-ast/src/nodes/yaml/YamlCollection.ts @@ -0,0 +1,11 @@ +import stampit from 'stampit'; + +import YamlNode from './YamlNode'; + +interface YamlCollection extends YamlNode { + readonly children: Array; +} + +const YamlCollection: stampit.Stamp = stampit(YamlNode, {}); + +export default YamlCollection; diff --git a/apidom/packages/apidom-ast/src/nodes/yaml/YamlComment.ts b/apidom/packages/apidom-ast/src/nodes/yaml/YamlComment.ts new file mode 100644 index 0000000000..ce697f71d3 --- /dev/null +++ b/apidom/packages/apidom-ast/src/nodes/yaml/YamlComment.ts @@ -0,0 +1,22 @@ +import stampit from 'stampit'; + +import Node from '../../Node'; + +interface YamlComment extends Node { + type: 'comment'; + content: string | null; +} + +const YamlComment: stampit.Stamp = stampit(Node, { + statics: { + type: 'comment', + }, + props: { + content: null, + }, + init({ content = null } = {}) { + this.content = content; + }, +}); + +export default YamlComment; diff --git a/apidom/packages/apidom-ast/src/nodes/yaml/YamlDirective.ts b/apidom/packages/apidom-ast/src/nodes/yaml/YamlDirective.ts new file mode 100644 index 0000000000..9a0b2079e3 --- /dev/null +++ b/apidom/packages/apidom-ast/src/nodes/yaml/YamlDirective.ts @@ -0,0 +1,39 @@ +import stampit from 'stampit'; +import { mergeRight } from 'ramda'; + +import Node from '../../Node'; + +interface YamlDirectiveParameters { + version: string | null; + handle: string | null; + prefix: string | null; +} + +interface YamlDirective extends Node { + type: 'directive'; + name: string | null; + parameters: YamlDirectiveParameters; +} + +const YamlDirective: stampit.Stamp = stampit(Node, { + statics: { + type: 'directive', + }, + props: { + name: null, + parameters: null, + }, + init({ name = null, parameters = {} } = {}) { + this.name = name; + this.parameters = mergeRight( + { + version: null, + handle: null, + prefix: null, + }, + parameters, + ); + }, +}); + +export default YamlDirective; diff --git a/apidom/packages/apidom-ast/src/nodes/yaml/YamlDocument.ts b/apidom/packages/apidom-ast/src/nodes/yaml/YamlDocument.ts new file mode 100644 index 0000000000..08c2d96ff4 --- /dev/null +++ b/apidom/packages/apidom-ast/src/nodes/yaml/YamlDocument.ts @@ -0,0 +1,15 @@ +import stampit from 'stampit'; + +import Node from '../../Node'; + +interface YamlDocument extends Node { + type: 'document'; +} + +const YamlDocument: stampit.Stamp = stampit(Node, { + statics: { + type: 'document', + }, +}); + +export default YamlDocument; diff --git a/apidom/packages/apidom-ast/src/nodes/yaml/YamlKeyValuePair.ts b/apidom/packages/apidom-ast/src/nodes/yaml/YamlKeyValuePair.ts new file mode 100644 index 0000000000..a6cce57a65 --- /dev/null +++ b/apidom/packages/apidom-ast/src/nodes/yaml/YamlKeyValuePair.ts @@ -0,0 +1,14 @@ +import stampit from 'stampit'; +import YamlNode from './YamlNode'; + +interface YamlKeyValuePair extends YamlNode { + type: 'keyValuePair'; +} + +const YamlKeyValuePair: stampit.Stamp = stampit(YamlNode, { + statics: { + type: 'keyValuePair', + }, +}); + +export default YamlKeyValuePair; diff --git a/apidom/packages/apidom-ast/src/nodes/yaml/YamlMapping.ts b/apidom/packages/apidom-ast/src/nodes/yaml/YamlMapping.ts new file mode 100644 index 0000000000..61bdcee3c1 --- /dev/null +++ b/apidom/packages/apidom-ast/src/nodes/yaml/YamlMapping.ts @@ -0,0 +1,24 @@ +import stampit from 'stampit'; +import { isArray } from 'ramda-adjunct'; + +import YamlCollection from './YamlCollection'; +import { isKeyValuePair } from './predicates'; +import YamlKeyValuePair from './YamlKeyValuePair'; + +interface YamlMapping extends YamlCollection { + type: 'mapping'; + readonly content: Array; +} + +const YamlMapping: stampit.Stamp = stampit(YamlCollection, { + statics: { + type: 'mapping', + }, + methods: { + get content(): Array { + return isArray(this.children) ? this.children.filter(isKeyValuePair) : []; + }, + }, +}); + +export default YamlMapping; diff --git a/apidom/packages/apidom-ast/src/nodes/yaml/YamlNode.ts b/apidom/packages/apidom-ast/src/nodes/yaml/YamlNode.ts new file mode 100644 index 0000000000..d87a898d7f --- /dev/null +++ b/apidom/packages/apidom-ast/src/nodes/yaml/YamlNode.ts @@ -0,0 +1,24 @@ +import stampit from 'stampit'; + +import Node from '../../Node'; + +interface YamlNode extends Node { + content: unknown | null; + anchor: unknown | null; + tag: unknown | null; +} + +const YamlNode: stampit.Stamp = stampit(Node, { + props: { + content: null, + anchor: null, + tag: null, + }, + init({ content = null, anchor = null, tag = null } = {}) { + this.content = content; + this.anchor = anchor; + this.tag = tag; + }, +}); + +export default YamlNode; diff --git a/apidom/packages/apidom-ast/src/nodes/yaml/YamlScalar.ts b/apidom/packages/apidom-ast/src/nodes/yaml/YamlScalar.ts new file mode 100644 index 0000000000..91638283a8 --- /dev/null +++ b/apidom/packages/apidom-ast/src/nodes/yaml/YamlScalar.ts @@ -0,0 +1,16 @@ +import stampit from 'stampit'; + +import YamlNode from './YamlNode'; + +interface YamlScalar extends YamlNode { + type: 'scalar'; + content: string | null; +} + +const YamlScalar: stampit.Stamp = stampit(YamlNode, { + statics: { + type: 'scalar', + }, +}); + +export default YamlScalar; diff --git a/apidom/packages/apidom-ast/src/nodes/yaml/YamlSequence.ts b/apidom/packages/apidom-ast/src/nodes/yaml/YamlSequence.ts new file mode 100644 index 0000000000..7a9085ed47 --- /dev/null +++ b/apidom/packages/apidom-ast/src/nodes/yaml/YamlSequence.ts @@ -0,0 +1,29 @@ +import stampit from 'stampit'; +import { anyPass } from 'ramda'; +import { isArray } from 'ramda-adjunct'; + +import YamlCollection from './YamlCollection'; +import YamlMapping from './YamlMapping'; +import YamlScalar from './YamlScalar'; +import YamlAlias from './YamlAlias'; +import { isMapping, isScalar, isSequence, isAlias } from './predicates'; + +interface YamlSequence extends YamlCollection { + type: 'sequence'; + readonly content: Array; +} + +const YamlSequence: stampit.Stamp = stampit(YamlCollection, { + statics: { + type: 'sequence', + }, + methods: { + get content(): Array { + return isArray(this.children) + ? this.children.filter(anyPass([isSequence, isMapping, isScalar, isAlias])) + : []; + }, + }, +}); + +export default YamlSequence; diff --git a/apidom/packages/apidom-ast/src/nodes/yaml/YamlStream.ts b/apidom/packages/apidom-ast/src/nodes/yaml/YamlStream.ts new file mode 100644 index 0000000000..c63165ce07 --- /dev/null +++ b/apidom/packages/apidom-ast/src/nodes/yaml/YamlStream.ts @@ -0,0 +1,17 @@ +import stampit from 'stampit'; + +import Node from '../../Node'; +import YamlDocument from './YamlDocument'; + +interface YamlStream extends Node { + type: 'stream'; + children: Array; +} + +const YamlStream: stampit.Stamp = stampit(Node, { + statics: { + type: 'stream', + }, +}); + +export default YamlStream; diff --git a/apidom/packages/apidom-ast/src/nodes/yaml/YamlTag.ts b/apidom/packages/apidom-ast/src/nodes/yaml/YamlTag.ts new file mode 100644 index 0000000000..3bee814679 --- /dev/null +++ b/apidom/packages/apidom-ast/src/nodes/yaml/YamlTag.ts @@ -0,0 +1,31 @@ +import stampit from 'stampit'; + +import Node from '../../Node'; + +enum YamlNodeKind { + Scalar = 'Scalar', + Sequence = 'Sequence', + Mapping = 'Mapping', +} + +interface YamlTag { + type: 'tag'; + name: string | null; + kind: YamlNodeKind | null; +} + +const YamlTag: stampit.Stamp = stampit(Node, { + statics: { + type: 'tag', + }, + props: { + name: null, + kind: null, + }, + init({ name = null, kind = null } = {}) { + this.name = name; + this.kind = kind; + }, +}); + +export default YamlTag; diff --git a/apidom/packages/apidom-ast/src/nodes/yaml/predicates.ts b/apidom/packages/apidom-ast/src/nodes/yaml/predicates.ts new file mode 100644 index 0000000000..f4dc3027d4 --- /dev/null +++ b/apidom/packages/apidom-ast/src/nodes/yaml/predicates.ts @@ -0,0 +1,19 @@ +import { isNodeType } from '../../predicates'; + +export const isStream = isNodeType('stream'); + +export const isDocument = isNodeType('document'); + +export const isMapping = isNodeType('mapping'); + +export const isSequence = isNodeType('sequence'); + +export const isKeyValuePair = isNodeType('keyValuePair'); + +export const isTag = isNodeType('tag'); + +export const isScalar = isNodeType('scalar'); + +export const isAlias = isNodeType('alias'); + +export const isDirective = isNodeType('directive'); diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-json/src/parser/visitors/generics/index.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-json/src/parser/visitors/generics/index.ts index cce132960c..f441d3f4e8 100644 --- a/apidom/packages/apidom-parser-adapter-asyncapi2-0-json/src/parser/visitors/generics/index.ts +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-json/src/parser/visitors/generics/index.ts @@ -216,7 +216,7 @@ export const ValueVisitor = stampit(SpecificationVisitor, { }, null(nullNode: JsonNull) { - const nullElement = new this.namespace.elements.Null(nullNode.value); + const nullElement = new this.namespace.elements.Null(); this.element = this.maybeAddSourceMap(nullNode, nullElement); return BREAK; }, diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-json/src/parser/visitors/generics/index.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-json/src/parser/visitors/generics/index.ts index 0972145b97..4c3aa6f528 100644 --- a/apidom/packages/apidom-parser-adapter-openapi3-1-json/src/parser/visitors/generics/index.ts +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-json/src/parser/visitors/generics/index.ts @@ -216,7 +216,7 @@ export const ValueVisitor = stampit(SpecificationVisitor, { }, null(nullNode: JsonNull) { - const nullElement = new this.namespace.elements.Null(nullNode.value); + const nullElement = new this.namespace.elements.Null(); this.element = this.maybeAddSourceMap(nullNode, nullElement); return BREAK; }, diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/package.json b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/package.json index 38cb737b9a..4b1190c218 100644 --- a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/package.json +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/package.json @@ -32,7 +32,7 @@ "ramda-adjunct": "=2.27.0", "stampit": "=4.3.1", "tree-sitter": "=0.17.0", - "tree-sitter-yaml": "=0.1.0", + "tree-sitter-yaml": "=0.2.0", "web-tree-sitter": "=0.17.0" }, "devDependencies": {