diff --git a/packages/apidom-ast/config/api-extractor/api-extractor.json b/packages/apidom-ast/config/api-extractor/api-extractor.json new file mode 100644 index 0000000000..7de0d99447 --- /dev/null +++ b/packages/apidom-ast/config/api-extractor/api-extractor.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", + "extends": "../../../../api-extractor.json" +} diff --git a/packages/apidom-ast/config/rollup/types.dist.js b/packages/apidom-ast/config/rollup/types.dist.js deleted file mode 100644 index 8fe05a1782..0000000000 --- a/packages/apidom-ast/config/rollup/types.dist.js +++ /dev/null @@ -1,12 +0,0 @@ -import dts from 'rollup-plugin-dts'; - -const config = [ - { - input: './types/index.d.ts', - output: [{ file: 'types/dist.d.ts', format: 'es' }], - plugins: [dts()], - external: ['Function/Curry'], - }, -]; - -export default config; diff --git a/packages/apidom-ast/package.json b/packages/apidom-ast/package.json index 0c8a294af5..51f3e6d6e4 100644 --- a/packages/apidom-ast/package.json +++ b/packages/apidom-ast/package.json @@ -11,11 +11,11 @@ "unpkg": "./dist/apidom.ast.min.js", "main": "./src/index.cjs", "exports": { - "types": "./types/dist.d.ts", + "types": "./types/apidom-ast.d.ts", "import": "./src/index.mjs", "require": "./src/index.cjs" }, - "types": "./types/dist.d.ts", + "types": "./types/apidom-ast.d.ts", "scripts": { "build": "npm run clean && run-p --max-parallel ${CPU_CORES:-2} typescript:declaration build:es build:cjs build:umd:browser", "build:es": "cross-env BABEL_ENV=es babel src --out-dir src --extensions '.ts' --out-file-extension '.mjs' --root-mode 'upward'", @@ -26,7 +26,7 @@ "clean": "rimraf --glob 'src/**/*.mjs' 'src/**/*.cjs' 'test/**/*.mjs' ./dist ./types", "test": "npm run build:es && cross-env BABEL_ENV=es babel test --out-dir test --extensions '.ts' --out-file-extension '.mjs' --root-mode 'upward' && cross-env NODE_ENV=test mocha", "typescript:check-types": "tsc --noEmit", - "typescript:declaration": "tsc -p tsconfig.declaration.json && rollup -c config/rollup/types.dist.js", + "typescript:declaration": "tsc -p tsconfig.declaration.json && api-extractor run -l -c ./config/api-extractor/api-extractor.json", "prepack": "copyfiles -u 3 ../../LICENSES/* LICENSES && copyfiles -u 2 ../../NOTICE .", "postpack": "rimraf NOTICE LICENSES" }, @@ -52,7 +52,7 @@ "src/**/*.mjs", "src/**/*.cjs", "dist/", - "types/dist.d.ts", + "types/apidom-ast.d.ts", "LICENSES", "NOTICE", "README.md", diff --git a/packages/apidom-ast/src/Error.ts b/packages/apidom-ast/src/Error.ts index 0060d9d5a7..9b4ead182b 100644 --- a/packages/apidom-ast/src/Error.ts +++ b/packages/apidom-ast/src/Error.ts @@ -1,11 +1,17 @@ import Node from './Node.ts'; import type { NodeOptions } from './Node.ts'; +/** + * @public + */ export interface ErrorOptions extends NodeOptions { readonly value?: unknown; readonly isUnexpected?: boolean; } +/** + * @public + */ class Error extends Node { public static readonly type: string = 'error'; diff --git a/packages/apidom-ast/src/Literal.ts b/packages/apidom-ast/src/Literal.ts index e597c9dd78..583e7abf4a 100644 --- a/packages/apidom-ast/src/Literal.ts +++ b/packages/apidom-ast/src/Literal.ts @@ -1,10 +1,16 @@ import Node from './Node.ts'; import type { NodeOptions } from './Node.ts'; +/** + * @public + */ export interface LiteralOptions extends NodeOptions { readonly value?: unknown; } +/** + * @public + */ class Literal extends Node { public static readonly type: string = 'literal'; diff --git a/packages/apidom-ast/src/Node.ts b/packages/apidom-ast/src/Node.ts index feb4e5b6e6..18023b43d8 100644 --- a/packages/apidom-ast/src/Node.ts +++ b/packages/apidom-ast/src/Node.ts @@ -1,11 +1,17 @@ import Position from './Position.ts'; +/** + * @public + */ export interface NodeOptions { readonly children?: unknown[]; readonly position?: Position; readonly isMissing?: boolean; } +/** + * @public + */ class Node { public static readonly type: string = 'node'; diff --git a/packages/apidom-ast/src/ParseResult.ts b/packages/apidom-ast/src/ParseResult.ts index 28c04a600f..0650e1b514 100644 --- a/packages/apidom-ast/src/ParseResult.ts +++ b/packages/apidom-ast/src/ParseResult.ts @@ -2,6 +2,9 @@ import { head } from 'ramda'; import Node from './Node.ts'; +/** + * @public + */ class ParseResult extends Node { public static readonly type: string = 'parseResult'; diff --git a/packages/apidom-ast/src/Position.ts b/packages/apidom-ast/src/Position.ts index 24bf907515..64cdc3c667 100644 --- a/packages/apidom-ast/src/Position.ts +++ b/packages/apidom-ast/src/Position.ts @@ -1,11 +1,17 @@ /* eslint-disable max-classes-per-file */ -interface PointOptions { +/** + * @public + */ +export interface PointOptions { readonly row: number; readonly column: number; readonly char: number; } +/** + * @public + */ export class Point { public static readonly type: string = 'point'; @@ -24,11 +30,17 @@ export class Point { } } -interface PositionOptions { +/** + * @public + */ +export interface PositionOptions { readonly start: Point; readonly end: Point; } +/** + * @public + */ class Position { public static readonly type: string = 'position'; diff --git a/packages/apidom-ast/src/index.ts b/packages/apidom-ast/src/index.ts index 6764487d4a..f411bafbf3 100644 --- a/packages/apidom-ast/src/index.ts +++ b/packages/apidom-ast/src/index.ts @@ -3,8 +3,10 @@ export { default as JsonNode } from './json/nodes/JsonNode.ts'; export { default as JsonDocument } from './json/nodes/JsonDocument.ts'; export { default as JsonObject } from './json/nodes/JsonObject.ts'; export { default as JsonProperty } from './json/nodes/JsonProperty.ts'; +export type { JsonValue as JsonValueType } from './json/nodes/JsonProperty.ts'; export { default as JsonArray } from './json/nodes/JsonArray.ts'; export { default as JsonValue } from './json/nodes/JsonValue.ts'; +export type { JsonValueOptions } from './json/nodes/JsonValue.ts'; export { default as JsonKey } from './json/nodes/JsonKey.ts'; export { default as JsonString } from './json/nodes/JsonString.ts'; export { default as JsonStringContent } from './json/nodes/JsonStringContent.ts'; @@ -29,18 +31,26 @@ export { } from './json/nodes/predicates.ts'; // YAML AST related exports export { default as YamlAlias } from './yaml/nodes/YamlAlias.ts'; +export type { YamlAliasOptions } from './yaml/nodes/YamlAlias.ts'; export { default as YamlCollection } from './yaml/nodes/YamlCollection.ts'; export { default as YamlComment } from './yaml/nodes/YamlComment.ts'; +export type { YamlCommentOptions } from './yaml/nodes/YamlComment.ts'; export { default as YamlDirective } from './yaml/nodes/YamlDirective.ts'; +export type { YamlDirectiveOptions, YamlDirectiveParameters } from './yaml/nodes/YamlDirective.ts'; export { default as YamlDocument } from './yaml/nodes/YamlDocument.ts'; export { default as YamlKeyValuePair } from './yaml/nodes/YamlKeyValuePair.ts'; +export type { YamlKeyValuePairOptions } from './yaml/nodes/YamlKeyValuePair.ts'; export { default as YamlMapping } from './yaml/nodes/YamlMapping.ts'; export { default as YamlNode } from './yaml/nodes/YamlNode.ts'; +export type { YamlNodeOptions } from './yaml/nodes/YamlNode.ts'; export { default as YamlScalar } from './yaml/nodes/YamlScalar.ts'; +export type { YamlScalarOptions } from './yaml/nodes/YamlScalar.ts'; export { default as YamlSequence } from './yaml/nodes/YamlSequence.ts'; export { default as YamlStream } from './yaml/nodes/YamlStream.ts'; export { default as YamlTag, YamlNodeKind } from './yaml/nodes/YamlTag.ts'; +export type { YamlTagOptions } from './yaml/nodes/YamlTag.ts'; export { default as YamlAnchor } from './yaml/nodes/YamlAnchor.ts'; +export type { YamlAnchorOptions } from './yaml/nodes/YamlAnchor.ts'; export { YamlStyle, YamlStyleGroup } from './yaml/nodes/YamlStyle.ts'; export { default as YamlFailsafeSchema } from './yaml/schemas/failsafe/index.ts'; export { default as YamlJsonSchema } from './yaml/schemas/json/index.ts'; @@ -64,9 +74,13 @@ export { default as YamlSchemaError } from './yaml/errors/YamlSchemaError.ts'; export { default as YamlTagError } from './yaml/errors/YamlTagError.ts'; export type { YamlTagErrorOptions } from './yaml/errors/YamlTagError.ts'; // generic AST related exports +export type { default as Node, NodeOptions } from './Node.ts'; export { default as Literal } from './Literal.ts'; +export type { LiteralOptions } from './Literal.ts'; export { Point, default as Position } from './Position.ts'; +export type { PointOptions, PositionOptions } from './Position.ts'; export { default as Error } from './Error.ts'; +export type { ErrorOptions } from './Error.ts'; export { default as ParseResult } from './ParseResult.ts'; export { isParseResult, isLiteral, isPoint, isPosition } from './predicates.ts'; // AST traversal related exports diff --git a/packages/apidom-ast/src/json/nodes/JsonArray.ts b/packages/apidom-ast/src/json/nodes/JsonArray.ts index 805a3a6eb8..068166a968 100644 --- a/packages/apidom-ast/src/json/nodes/JsonArray.ts +++ b/packages/apidom-ast/src/json/nodes/JsonArray.ts @@ -1,6 +1,9 @@ import JsonNode from './JsonNode.ts'; import { isFalse, isTrue, isNull, isNumber, isString, isArray, isObject } from './predicates.ts'; +/** + * @public + */ class JsonArray extends JsonNode { public static readonly type = 'array'; diff --git a/packages/apidom-ast/src/json/nodes/JsonDocument.ts b/packages/apidom-ast/src/json/nodes/JsonDocument.ts index fbfdcf6b04..1a1dbe14f2 100644 --- a/packages/apidom-ast/src/json/nodes/JsonDocument.ts +++ b/packages/apidom-ast/src/json/nodes/JsonDocument.ts @@ -2,6 +2,9 @@ import { head } from 'ramda'; import JsonNode from './JsonNode.ts'; +/** + * @public + */ class JsonDocument extends JsonNode { public static readonly type = 'document'; diff --git a/packages/apidom-ast/src/json/nodes/JsonEscapeSequence.ts b/packages/apidom-ast/src/json/nodes/JsonEscapeSequence.ts index 2648f97e89..999467d896 100644 --- a/packages/apidom-ast/src/json/nodes/JsonEscapeSequence.ts +++ b/packages/apidom-ast/src/json/nodes/JsonEscapeSequence.ts @@ -1,5 +1,8 @@ import JsonValue from './JsonValue.ts'; +/** + * @public + */ class JsonEscapeSequence extends JsonValue { public static readonly type = 'escapeSequence'; } diff --git a/packages/apidom-ast/src/json/nodes/JsonFalse.ts b/packages/apidom-ast/src/json/nodes/JsonFalse.ts index c2db6762a7..10b0f9ee21 100644 --- a/packages/apidom-ast/src/json/nodes/JsonFalse.ts +++ b/packages/apidom-ast/src/json/nodes/JsonFalse.ts @@ -1,5 +1,8 @@ import JsonValue from './JsonValue.ts'; +/** + * @public + */ class JsonFalse extends JsonValue { public static readonly type = 'false'; } diff --git a/packages/apidom-ast/src/json/nodes/JsonKey.ts b/packages/apidom-ast/src/json/nodes/JsonKey.ts index 8fdb7db1c9..d253c57fb5 100644 --- a/packages/apidom-ast/src/json/nodes/JsonKey.ts +++ b/packages/apidom-ast/src/json/nodes/JsonKey.ts @@ -1,5 +1,8 @@ import JsonString from './JsonString.ts'; +/** + * @public + */ class JsonKey extends JsonString { public static readonly type = 'key'; } diff --git a/packages/apidom-ast/src/json/nodes/JsonNode.ts b/packages/apidom-ast/src/json/nodes/JsonNode.ts index 79f916f81a..592540bc4b 100644 --- a/packages/apidom-ast/src/json/nodes/JsonNode.ts +++ b/packages/apidom-ast/src/json/nodes/JsonNode.ts @@ -1,5 +1,8 @@ import Node from '../../Node.ts'; +/** + * @public + */ class JsonNode extends Node {} export default JsonNode; diff --git a/packages/apidom-ast/src/json/nodes/JsonNull.ts b/packages/apidom-ast/src/json/nodes/JsonNull.ts index 99c6eac3e5..14c4e30c0e 100644 --- a/packages/apidom-ast/src/json/nodes/JsonNull.ts +++ b/packages/apidom-ast/src/json/nodes/JsonNull.ts @@ -1,5 +1,8 @@ import JsonValue from './JsonValue.ts'; +/** + * @public + */ class JsonNull extends JsonValue { public static readonly type = 'null'; } diff --git a/packages/apidom-ast/src/json/nodes/JsonNumber.ts b/packages/apidom-ast/src/json/nodes/JsonNumber.ts index 719a472d8d..a67c6a294e 100644 --- a/packages/apidom-ast/src/json/nodes/JsonNumber.ts +++ b/packages/apidom-ast/src/json/nodes/JsonNumber.ts @@ -1,5 +1,8 @@ import JsonValue from './JsonValue.ts'; +/** + * @public + */ class JsonNumber extends JsonValue { public static readonly type = 'number'; } diff --git a/packages/apidom-ast/src/json/nodes/JsonObject.ts b/packages/apidom-ast/src/json/nodes/JsonObject.ts index 4f3601db50..9320a38686 100644 --- a/packages/apidom-ast/src/json/nodes/JsonObject.ts +++ b/packages/apidom-ast/src/json/nodes/JsonObject.ts @@ -2,6 +2,9 @@ import JsonNode from './JsonNode.ts'; import { isProperty } from './predicates.ts'; import type JsonProperty from './JsonProperty.ts'; +/** + * @public + */ class JsonObject extends JsonNode { public static readonly type = 'object'; diff --git a/packages/apidom-ast/src/json/nodes/JsonProperty.ts b/packages/apidom-ast/src/json/nodes/JsonProperty.ts index 86c51519c9..774aedd63f 100644 --- a/packages/apidom-ast/src/json/nodes/JsonProperty.ts +++ b/packages/apidom-ast/src/json/nodes/JsonProperty.ts @@ -18,8 +18,21 @@ import type JsonNumber from './JsonNumber.ts'; import type JsonArray from './JsonArray.ts'; import type JsonObject from './JsonObject.ts'; -type JsonValue = JsonFalse | JsonTrue | JsonNull | JsonNumber | JsonString | JsonArray | JsonObject; +/** + * @public + */ +export type JsonValue = + | JsonFalse + | JsonTrue + | JsonNull + | JsonNumber + | JsonString + | JsonArray + | JsonObject; +/** + * @public + */ class JsonProperty extends JsonNode { public static readonly type = 'property'; diff --git a/packages/apidom-ast/src/json/nodes/JsonString.ts b/packages/apidom-ast/src/json/nodes/JsonString.ts index 0f54c09a73..ecc1dd6de8 100644 --- a/packages/apidom-ast/src/json/nodes/JsonString.ts +++ b/packages/apidom-ast/src/json/nodes/JsonString.ts @@ -5,6 +5,9 @@ import { isEscapeSequence, isStringContent } from './predicates.ts'; type JsonStringLike = JsonStringContent | JsonEscapeSequence; +/** + * @public + */ class JsonString extends JsonNode { public static readonly type: string = 'string'; diff --git a/packages/apidom-ast/src/json/nodes/JsonStringContent.ts b/packages/apidom-ast/src/json/nodes/JsonStringContent.ts index a08e77fc69..afe7abd010 100644 --- a/packages/apidom-ast/src/json/nodes/JsonStringContent.ts +++ b/packages/apidom-ast/src/json/nodes/JsonStringContent.ts @@ -1,5 +1,8 @@ import JsonValue from './JsonValue.ts'; +/** + * @public + */ class JsonStringContent extends JsonValue { public static readonly type = 'stringContent'; } diff --git a/packages/apidom-ast/src/json/nodes/JsonTrue.ts b/packages/apidom-ast/src/json/nodes/JsonTrue.ts index 208c4d8277..b30afcddf0 100644 --- a/packages/apidom-ast/src/json/nodes/JsonTrue.ts +++ b/packages/apidom-ast/src/json/nodes/JsonTrue.ts @@ -1,5 +1,8 @@ import JsonValue from './JsonValue.ts'; +/** + * @public + */ class JsonTrue extends JsonValue { public static readonly type = 'true'; } diff --git a/packages/apidom-ast/src/json/nodes/JsonValue.ts b/packages/apidom-ast/src/json/nodes/JsonValue.ts index fb9cc97e46..92739f633f 100644 --- a/packages/apidom-ast/src/json/nodes/JsonValue.ts +++ b/packages/apidom-ast/src/json/nodes/JsonValue.ts @@ -1,10 +1,16 @@ import JsonNode from './JsonNode.ts'; import type { NodeOptions } from '../../Node.ts'; +/** + * @public + */ export interface JsonValueOptions extends NodeOptions { value: string; } +/** + * @public + */ class JsonValue extends JsonNode { public static readonly type: string = 'value'; diff --git a/packages/apidom-ast/src/json/nodes/predicates.ts b/packages/apidom-ast/src/json/nodes/predicates.ts index dbc0f5e4be..781a73f55b 100644 --- a/packages/apidom-ast/src/json/nodes/predicates.ts +++ b/packages/apidom-ast/src/json/nodes/predicates.ts @@ -12,28 +12,64 @@ import type JsonEscapeSequence from './JsonEscapeSequence.ts'; import type JsonProperty from './JsonProperty.ts'; import type JsonKey from './JsonKey.ts'; +/** + * @public + */ export const isDocument = (node: unknown): node is JsonDocument => isNodeType('document', node); +/** + * @public + */ export const isString = (node: unknown): node is JsonString => isNodeType('string', node); +/** + * @public + */ export const isFalse = (node: unknown): node is JsonFalse => isNodeType('false', node); +/** + * @public + */ export const isTrue = (node: unknown): node is JsonTrue => isNodeType('true', node); +/** + * @public + */ export const isNull = (node: unknown): node is JsonNull => isNodeType('null', node); +/** + * @public + */ export const isNumber = (node: unknown): node is JsonNumber => isNodeType('number', node); +/** + * @public + */ export const isArray = (node: unknown): node is JsonArray => isNodeType('array', node); +/** + * @public + */ export const isObject = (node: unknown): node is JsonObject => isNodeType('object', node); +/** + * @public + */ export const isStringContent = (node: unknown): node is JsonStringContent => isNodeType('stringContent', node); +/** + * @public + */ export const isEscapeSequence = (node: unknown): node is JsonEscapeSequence => isNodeType('escapeSequence', node); +/** + * @public + */ export const isProperty = (node: unknown): node is JsonProperty => isNodeType('property', node); +/** + * @public + */ export const isKey = (node: unknown): node is JsonKey => isNodeType('key', node); diff --git a/packages/apidom-ast/src/predicates.ts b/packages/apidom-ast/src/predicates.ts index 6e0fd67761..cb194c6e6e 100644 --- a/packages/apidom-ast/src/predicates.ts +++ b/packages/apidom-ast/src/predicates.ts @@ -2,13 +2,29 @@ import type Literal from './Literal.ts'; import Position, { Point } from './Position.ts'; import ParseResult from './ParseResult.ts'; +/** + * @public + */ export const isNodeType = (type: string, node: unknown): boolean => node != null && typeof node === 'object' && 'type' in node && node.type === type; +/** + * @public + */ export const isLiteral = (node: unknown): node is Literal => isNodeType('literal', node); + +/** + * @public + */ export const isPosition = (node: unknown): node is Position => isNodeType('position', node); +/** + * @public + */ export const isPoint = (node: unknown): node is Point => isNodeType('point', node); +/** + * @public + */ export const isParseResult = (node: unknown): node is ParseResult => isNodeType('parseResult', node); diff --git a/packages/apidom-ast/src/traversal/visitor.ts b/packages/apidom-ast/src/traversal/visitor.ts index a5d7c422c5..a6a08d39e8 100644 --- a/packages/apidom-ast/src/traversal/visitor.ts +++ b/packages/apidom-ast/src/traversal/visitor.ts @@ -6,8 +6,15 @@ import { ApiDOMStructuredError } from '@swagger-api/apidom-error'; * SPDX-License-Identifier: MIT */ -// getVisitFn :: (Visitor, String, Boolean) -> Function -export const getVisitFn = (visitor: any, type: string, isLeaving: boolean) => { +/** + * @public + */ +export const getVisitFn = ( + visitor: any, + type: string | undefined, + isLeaving: boolean, +): ((...args: any[]) => any) | null => { + // @ts-ignore const typeVisitor = visitor[type]; if (typeVisitor != null) { @@ -27,6 +34,7 @@ export const getVisitFn = (visitor: any, type: string, isLeaving: boolean) => { // { enter() {}, leave() {} } return specificVisitor; } + // @ts-ignore const specificTypeVisitor = specificVisitor[type]; if (typeof specificTypeVisitor === 'function') { // { enter: { Type() {} }, leave: { Type() {} } } @@ -38,15 +46,24 @@ export const getVisitFn = (visitor: any, type: string, isLeaving: boolean) => { return null; }; +/** + * @public + */ export const BREAK = {}; -// getNodeType :: Node -> String -export const getNodeType = (node: any) => node?.type; +/** + * @public + */ +export const getNodeType = (node: any): string | undefined => node?.type; -// isNode :: Node -> Boolean +/** + * @public + */ export const isNode = (node: any) => typeof getNodeType(node) === 'string'; -// cloneNode :: a -> a +/** + * @public + */ export const cloneNode = (node: any) => Object.create(Object.getPrototypeOf(node), Object.getOwnPropertyDescriptors(node)); @@ -56,6 +73,7 @@ export const cloneNode = (node: any) => * * If a prior visitor edits a node, no following visitors will see that node. * `exposeEdits=true` can be used to expose the edited node from the previous visitors. + * @public */ export interface MergeAllSync { @@ -76,6 +94,9 @@ export interface MergeAllSync { [key: symbol]: MergeAllAsync; } +/** + * @public + */ export interface MergeAllAsync { ( visitors: any[], @@ -93,6 +114,9 @@ export interface MergeAllAsync { }; } +/** + * @public + */ export const mergeAll: MergeAllSync = (( visitors: any[], { @@ -335,9 +359,11 @@ mergeAll[Symbol.for('nodejs.util.promisify.custom')] = mergeAllAsync; * a new version of the AST with the changes applied will be returned from the * visit function. * + * @example + * ``` * const editedAST = visit(ast, { * enter(node, key, parent, path, ancestors) { - * // @return + * // return * // undefined: no action * // false: skip visiting this node * // BREAK: stop visiting altogether @@ -345,7 +371,7 @@ mergeAll[Symbol.for('nodejs.util.promisify.custom')] = mergeAllAsync; * // any value: replace this node with the returned value * }, * leave(node, key, parent, path, ancestors) { - * // @return + * // return * // undefined: no action * // false: no action * // BREAK: stop visiting altogether @@ -353,23 +379,23 @@ mergeAll[Symbol.for('nodejs.util.promisify.custom')] = mergeAllAsync; * // any value: replace this node with the returned value * } * }); - * + *``` * Alternatively to providing enter() and leave() functions, a visitor can * instead provide functions named the same as the kinds of AST nodes, or * enter/leave visitors at a named key, leading to four permutations of * visitor API: * * 1) Named visitors triggered when entering a node a specific kind. - * + * ``` * visit(ast, { * Kind(node) { * // enter the "Kind" node * } * }) - * + * ``` * 2) Named visitors that trigger upon entering and leaving a node of * a specific kind. - * + * ``` * visit(ast, { * Kind: { * enter(node) { @@ -380,9 +406,9 @@ mergeAll[Symbol.for('nodejs.util.promisify.custom')] = mergeAllAsync; * } * } * }) - * + * ``` * 3) Generic visitors that trigger upon entering and leaving any node. - * + * ``` * visit(ast, { * enter(node) { * // enter any node @@ -391,9 +417,9 @@ mergeAll[Symbol.for('nodejs.util.promisify.custom')] = mergeAllAsync; * // leave any node * } * }) - * + * ``` * 4) Parallel visitors for entering and leaving nodes of a specific kind. - * + * ``` * visit(ast, { * enter: { * Kind(node) { @@ -406,9 +432,12 @@ mergeAll[Symbol.for('nodejs.util.promisify.custom')] = mergeAllAsync; * } * } * }) + * ``` + * sig `visit :: (Node, Visitor, Options)` + * + * sig `Options = { keyMap: Object, state: Object }` * - * @sig visit :: (Node, Visitor, Options) - * @sig Options = { keyMap: Object, state: Object } + * @public */ export const visit = ( // @ts-ignore diff --git a/packages/apidom-ast/src/yaml/anchors-aliases/ReferenceManager.ts b/packages/apidom-ast/src/yaml/anchors-aliases/ReferenceManager.ts index f5fea7b44e..bbf475c265 100644 --- a/packages/apidom-ast/src/yaml/anchors-aliases/ReferenceManager.ts +++ b/packages/apidom-ast/src/yaml/anchors-aliases/ReferenceManager.ts @@ -6,6 +6,9 @@ import { isAnchor } from '../nodes/predicates.ts'; import { YamlStyle, YamlStyleGroup } from '../nodes/YamlStyle.ts'; /* eslint-disable class-methods-use-this */ +/** + * @public + */ class ReferenceManager { addAnchor(node: YamlNode): void { if (!isAnchor(node.anchor)) { diff --git a/packages/apidom-ast/src/yaml/errors/YamlError.ts b/packages/apidom-ast/src/yaml/errors/YamlError.ts index 0f4f135ab1..911e86e9f8 100644 --- a/packages/apidom-ast/src/yaml/errors/YamlError.ts +++ b/packages/apidom-ast/src/yaml/errors/YamlError.ts @@ -1,5 +1,8 @@ import { ApiDOMStructuredError } from '@swagger-api/apidom-error'; +/** + * @public + */ class YamlError extends ApiDOMStructuredError {} export default YamlError; diff --git a/packages/apidom-ast/src/yaml/errors/YamlReferenceError.ts b/packages/apidom-ast/src/yaml/errors/YamlReferenceError.ts index 0c89e89eab..c3e326c4e7 100644 --- a/packages/apidom-ast/src/yaml/errors/YamlReferenceError.ts +++ b/packages/apidom-ast/src/yaml/errors/YamlReferenceError.ts @@ -1,5 +1,8 @@ import YamlError from './YamlError.ts'; +/** + * @public + */ class YamlReferenceError extends YamlError {} export default YamlReferenceError; diff --git a/packages/apidom-ast/src/yaml/errors/YamlSchemaError.ts b/packages/apidom-ast/src/yaml/errors/YamlSchemaError.ts index 082a0b1e28..c7ba12c965 100644 --- a/packages/apidom-ast/src/yaml/errors/YamlSchemaError.ts +++ b/packages/apidom-ast/src/yaml/errors/YamlSchemaError.ts @@ -1,5 +1,8 @@ import YamlError from './YamlError.ts'; +/** + * @public + */ class YamlSchemaError extends YamlError {} export default YamlSchemaError; diff --git a/packages/apidom-ast/src/yaml/errors/YamlTagError.ts b/packages/apidom-ast/src/yaml/errors/YamlTagError.ts index 70c9c95c57..2248b261ec 100644 --- a/packages/apidom-ast/src/yaml/errors/YamlTagError.ts +++ b/packages/apidom-ast/src/yaml/errors/YamlTagError.ts @@ -4,6 +4,9 @@ import YamlSchemaError from './YamlSchemaError.ts'; import Position from '../../Position.ts'; import Node from '../../Node.ts'; +/** + * @public + */ export interface YamlTagErrorOptions extends ApiDOMErrorOptions { readonly specificTagName: string; readonly explicitTagName: string; @@ -13,6 +16,9 @@ export interface YamlTagErrorOptions extends ApiDOMErrorO readonly node?: T; } +/** + * @public + */ class YamlTagError extends YamlSchemaError { public readonly specificTagName!: string; diff --git a/packages/apidom-ast/src/yaml/nodes/YamlAlias.ts b/packages/apidom-ast/src/yaml/nodes/YamlAlias.ts index 5605230579..d6e46564b0 100644 --- a/packages/apidom-ast/src/yaml/nodes/YamlAlias.ts +++ b/packages/apidom-ast/src/yaml/nodes/YamlAlias.ts @@ -1,10 +1,16 @@ import Node from '../../Node.ts'; import type { NodeOptions } from '../../Node.ts'; +/** + * @public + */ export interface YamlAliasOptions extends NodeOptions { readonly content: string; } +/** + * @public + */ class YamlAlias extends Node { public static readonly type = 'alias'; diff --git a/packages/apidom-ast/src/yaml/nodes/YamlAnchor.ts b/packages/apidom-ast/src/yaml/nodes/YamlAnchor.ts index 4a9178e3f7..2b2ec0ef26 100644 --- a/packages/apidom-ast/src/yaml/nodes/YamlAnchor.ts +++ b/packages/apidom-ast/src/yaml/nodes/YamlAnchor.ts @@ -1,10 +1,16 @@ import Node from '../../Node.ts'; import type { NodeOptions } from '../../Node.ts'; +/** + * @public + */ export interface YamlAnchorOptions extends NodeOptions { readonly name: string; } +/** + * @public + */ class YamlAnchor extends Node { public static readonly type = 'anchor'; diff --git a/packages/apidom-ast/src/yaml/nodes/YamlCollection.ts b/packages/apidom-ast/src/yaml/nodes/YamlCollection.ts index 50ac56a685..7a20585edd 100644 --- a/packages/apidom-ast/src/yaml/nodes/YamlCollection.ts +++ b/packages/apidom-ast/src/yaml/nodes/YamlCollection.ts @@ -1,5 +1,8 @@ import YamlNode from './YamlNode.ts'; +/** + * @public + */ class YamlCollection extends YamlNode {} export default YamlCollection; diff --git a/packages/apidom-ast/src/yaml/nodes/YamlComment.ts b/packages/apidom-ast/src/yaml/nodes/YamlComment.ts index e5753d3aba..f6109426f4 100644 --- a/packages/apidom-ast/src/yaml/nodes/YamlComment.ts +++ b/packages/apidom-ast/src/yaml/nodes/YamlComment.ts @@ -1,10 +1,16 @@ import Node from '../../Node.ts'; import type { NodeOptions } from '../../Node.ts'; +/** + * @public + */ export interface YamlCommentOptions extends NodeOptions { readonly content: string; } +/** + * @public + */ class YamlComment extends Node { public static readonly type = 'comment'; diff --git a/packages/apidom-ast/src/yaml/nodes/YamlDirective.ts b/packages/apidom-ast/src/yaml/nodes/YamlDirective.ts index 79b4b978d1..6af987ba05 100644 --- a/packages/apidom-ast/src/yaml/nodes/YamlDirective.ts +++ b/packages/apidom-ast/src/yaml/nodes/YamlDirective.ts @@ -3,17 +3,26 @@ import { mergeRight } from 'ramda'; import Node from '../../Node.ts'; import type { NodeOptions } from '../../Node.ts'; -interface YamlDirectiveParameters { +/** + * @public + */ +export interface YamlDirectiveParameters { readonly version?: string; readonly handle?: string; readonly prefix?: string; } +/** + * @public + */ export interface YamlDirectiveOptions extends NodeOptions { readonly name?: string; readonly parameters: YamlDirectiveParameters; } +/** + * @public + */ class YamlDirective extends Node { public static readonly type = 'directive'; diff --git a/packages/apidom-ast/src/yaml/nodes/YamlDocument.ts b/packages/apidom-ast/src/yaml/nodes/YamlDocument.ts index c9d47c6ba5..3e89421623 100644 --- a/packages/apidom-ast/src/yaml/nodes/YamlDocument.ts +++ b/packages/apidom-ast/src/yaml/nodes/YamlDocument.ts @@ -1,5 +1,8 @@ import Node from '../../Node.ts'; +/** + * @public + */ class YamlDocument extends Node { public static readonly type = 'document'; } diff --git a/packages/apidom-ast/src/yaml/nodes/YamlKeyValuePair.ts b/packages/apidom-ast/src/yaml/nodes/YamlKeyValuePair.ts index a699761240..cfa87fc0da 100644 --- a/packages/apidom-ast/src/yaml/nodes/YamlKeyValuePair.ts +++ b/packages/apidom-ast/src/yaml/nodes/YamlKeyValuePair.ts @@ -4,10 +4,16 @@ import YamlScalar from './YamlScalar.ts'; import type { YamlStyleGroup } from './YamlStyle.ts'; import { isScalar, isMapping, isSequence, isAlias } from './predicates.ts'; +/** + * @public + */ export interface YamlKeyValuePairOptions extends NodeOptions { readonly styleGroup: YamlStyleGroup; } +/** + * @public + */ class YamlKeyValuePair extends Node { public static readonly type = 'keyValuePair'; diff --git a/packages/apidom-ast/src/yaml/nodes/YamlMapping.ts b/packages/apidom-ast/src/yaml/nodes/YamlMapping.ts index 10f9be045a..336555dd8a 100644 --- a/packages/apidom-ast/src/yaml/nodes/YamlMapping.ts +++ b/packages/apidom-ast/src/yaml/nodes/YamlMapping.ts @@ -2,6 +2,9 @@ import YamlCollection from './YamlCollection.ts'; import { isKeyValuePair } from './predicates.ts'; import YamlKeyValuePair from './YamlKeyValuePair.ts'; +/** + * @public + */ class YamlMapping extends YamlCollection { public static readonly type = 'mapping'; } diff --git a/packages/apidom-ast/src/yaml/nodes/YamlNode.ts b/packages/apidom-ast/src/yaml/nodes/YamlNode.ts index 3c2fddffbf..43ca895618 100644 --- a/packages/apidom-ast/src/yaml/nodes/YamlNode.ts +++ b/packages/apidom-ast/src/yaml/nodes/YamlNode.ts @@ -4,6 +4,9 @@ import YamlTag from './YamlTag.ts'; import YamlAnchor from './YamlAnchor.ts'; import { YamlStyle, YamlStyleGroup } from './YamlStyle.ts'; +/** + * @public + */ export interface YamlNodeOptions extends NodeOptions { readonly anchor?: YamlAnchor; readonly tag?: YamlTag; @@ -11,6 +14,9 @@ export interface YamlNodeOptions extends NodeOptions { readonly styleGroup: YamlStyleGroup; } +/** + * @public + */ class YamlNode extends Node { public readonly anchor?: YamlAnchor; diff --git a/packages/apidom-ast/src/yaml/nodes/YamlScalar.ts b/packages/apidom-ast/src/yaml/nodes/YamlScalar.ts index 7e7cd2b216..d2745a6c0b 100644 --- a/packages/apidom-ast/src/yaml/nodes/YamlScalar.ts +++ b/packages/apidom-ast/src/yaml/nodes/YamlScalar.ts @@ -1,10 +1,16 @@ import YamlNode from './YamlNode.ts'; import type { YamlNodeOptions } from './YamlNode.ts'; +/** + * @public + */ export interface YamlScalarOptions extends YamlNodeOptions { readonly content: string; } +/** + * @public + */ class YamlScalar extends YamlNode { public static readonly type = 'scalar'; diff --git a/packages/apidom-ast/src/yaml/nodes/YamlSequence.ts b/packages/apidom-ast/src/yaml/nodes/YamlSequence.ts index 18e08beaa9..5ca0123681 100644 --- a/packages/apidom-ast/src/yaml/nodes/YamlSequence.ts +++ b/packages/apidom-ast/src/yaml/nodes/YamlSequence.ts @@ -4,6 +4,9 @@ import YamlScalar from './YamlScalar.ts'; import YamlAlias from './YamlAlias.ts'; import { isMapping, isScalar, isSequence, isAlias } from './predicates.ts'; +/** + * @public + */ class YamlSequence extends YamlCollection { public static readonly type = 'sequence'; } diff --git a/packages/apidom-ast/src/yaml/nodes/YamlStream.ts b/packages/apidom-ast/src/yaml/nodes/YamlStream.ts index 4ea9f5f197..12c46181bf 100644 --- a/packages/apidom-ast/src/yaml/nodes/YamlStream.ts +++ b/packages/apidom-ast/src/yaml/nodes/YamlStream.ts @@ -3,6 +3,9 @@ import YamlDocument from './YamlDocument.ts'; import YamlComment from './YamlComment.ts'; import { isComment, isDocument } from './predicates.ts'; +/** + * @public + */ class YamlStream extends Node { public static readonly type = 'stream'; } diff --git a/packages/apidom-ast/src/yaml/nodes/YamlStyle.ts b/packages/apidom-ast/src/yaml/nodes/YamlStyle.ts index 595bb60e9d..b93a3a509e 100644 --- a/packages/apidom-ast/src/yaml/nodes/YamlStyle.ts +++ b/packages/apidom-ast/src/yaml/nodes/YamlStyle.ts @@ -1,3 +1,6 @@ +/** + * @public + */ export enum YamlStyle { Plain = 'Plain', SingleQuoted = 'SingleQuoted', @@ -10,6 +13,9 @@ export enum YamlStyle { InLine = 'InLine', } +/** + * @public + */ export enum YamlStyleGroup { Flow = 'Flow', Block = 'Block', diff --git a/packages/apidom-ast/src/yaml/nodes/YamlTag.ts b/packages/apidom-ast/src/yaml/nodes/YamlTag.ts index 22fb4c175f..1f7129106d 100644 --- a/packages/apidom-ast/src/yaml/nodes/YamlTag.ts +++ b/packages/apidom-ast/src/yaml/nodes/YamlTag.ts @@ -1,17 +1,26 @@ import Node from '../../Node.ts'; import type { NodeOptions } from '../../Node.ts'; +/** + * @public + */ export enum YamlNodeKind { Scalar = 'Scalar', Sequence = 'Sequence', Mapping = 'Mapping', } +/** + * @public + */ export interface YamlTagOptions extends NodeOptions { readonly explicitName: string; readonly kind: YamlNodeKind; } +/** + * @public + */ class YamlTag extends Node { public static readonly type = 'tag'; diff --git a/packages/apidom-ast/src/yaml/nodes/predicates.ts b/packages/apidom-ast/src/yaml/nodes/predicates.ts index 19271d7507..0ef58fe68c 100644 --- a/packages/apidom-ast/src/yaml/nodes/predicates.ts +++ b/packages/apidom-ast/src/yaml/nodes/predicates.ts @@ -11,25 +11,58 @@ import type YamlDirective from './YamlDirective.ts'; import type YamlComment from './YamlComment.ts'; import { isNodeType } from '../../predicates.ts'; +/** + * @public + */ export const isStream = (node: unknown): node is YamlStream => isNodeType('stream', node); +/** + * @public + */ export const isDocument = (node: unknown): node is YamlDocument => isNodeType('document', node); +/** + * @public + */ export const isMapping = (node: unknown): node is YamlMapping => isNodeType('mapping', node); +/** + * @public + */ export const isSequence = (node: unknown): node is YamlSequence => isNodeType('sequence', node); +/** + * @public + */ export const isKeyValuePair = (node: unknown): node is YamlKeyValuePair => isNodeType('keyValuePair', node); +/** + * @public + */ export const isTag = (node: unknown): node is YamlTag => isNodeType('tag', node); +/** + * @public + */ export const isAnchor = (node: unknown): node is YamlAnchor => isNodeType('anchor', node); +/** + * @public + */ export const isScalar = (node: unknown): node is YamlScalar => isNodeType('scalar', node); +/** + * @public + */ export const isAlias = (node: unknown): node is YamlAlias => isNodeType('alias', node); +/** + * @public + */ export const isDirective = (node: unknown): node is YamlDirective => isNodeType('directive', node); +/** + * @public + */ export const isComment = (node: unknown): node is YamlComment => isNodeType('comment', node); diff --git a/packages/apidom-ast/src/yaml/schemas/failsafe/index.ts b/packages/apidom-ast/src/yaml/schemas/failsafe/index.ts index 62c77f935f..d0a4524e4c 100644 --- a/packages/apidom-ast/src/yaml/schemas/failsafe/index.ts +++ b/packages/apidom-ast/src/yaml/schemas/failsafe/index.ts @@ -8,6 +8,9 @@ import GenericSequenceTag from './GenericSequence.ts'; import GenericStringTag from './GenericString.ts'; import ScalarTag from '../ScalarTag.ts'; +/** + * @public + */ class FailsafeSchema { public tags: any[]; diff --git a/packages/apidom-ast/src/yaml/schemas/json/index.ts b/packages/apidom-ast/src/yaml/schemas/json/index.ts index 651b31ea88..daebc60f6e 100644 --- a/packages/apidom-ast/src/yaml/schemas/json/index.ts +++ b/packages/apidom-ast/src/yaml/schemas/json/index.ts @@ -7,6 +7,9 @@ import { YamlNodeKind } from '../../nodes/YamlTag.ts'; import GenericSequence from '../failsafe/GenericSequence.ts'; import GenericMapping from '../failsafe/GenericMapping.ts'; +/** + * @public + */ class JsonSchema extends FailsafeSchema { constructor() { super();