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