import type { Node } from 'web-tree-sitter'; import type { StringValueNode } from './string_value.js'; const TYPE = 'description' as const; // ================================================================ // ================================================================ // // DescriptionNode // // GraphQL description node // // ================================================================ // ================================================================ /** * Represents a description in the GraphQL AST. * * Children: * {@link StringValueNode} * */ export interface DescriptionNode extends Node { type: typeof TYPE; } // ================================================================ // ================================================================ // // Type Guard // // ================================================================ // ================================================================ /** * Type guard to check if a node is a {@link DescriptionNode}. * * @param node - The node to check * @returns True if the node is a {@link DescriptionNode} * * @example * ```typescript * if (isDescriptionNode(node)) { * // TypeScript now knows node is DescriptionNode * console.log(node.type); // 'description' * } * ``` */ export function isDescriptionNode(node: unknown): node is DescriptionNode { return (node as any)?.type === TYPE; } // ================================================================ // ================================================================ // // Constructor // // ================================================================ // ================================================================ /** * Creates a new {@link DescriptionNode} with the specified properties. * * @param props - The node properties * @param props.stringvalue - {@link StringValueNode} * @returns A new {@link DescriptionNode} * * @example * ```typescript * const node = DescriptionNode({ * // properties... * }); * ``` */ export function DescriptionNode(props: Omit): DescriptionNode { return { type: TYPE, ...props }; }