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