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