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