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