import type { Node } from 'web-tree-sitter'; import type { ExecutableDefinitionNode } from './executable_definition.js'; import type { TypeSystemDefinitionNode } from './type_system_definition.js'; import type { TypeSystemExtensionNode } from './type_system_extension.js'; const TYPE = 'definition' as const; // ================================================================ // ================================================================ // // DefinitionNode // // GraphQL definition node // // ================================================================ // ================================================================ /** * Represents a definition in the GraphQL AST. * * Children: * {@link ExecutableDefinitionNode}, {@link TypeSystemDefinitionNode}, {@link TypeSystemExtensionNode} * */ export interface DefinitionNode extends Node { type: typeof TYPE; } // ================================================================ // ================================================================ // // Type Guard // // ================================================================ // ================================================================ /** * Type guard to check if a node is a {@link DefinitionNode}. * * @param node - The node to check * @returns True if the node is a {@link DefinitionNode} * * @example * ```typescript * if (isDefinitionNode(node)) { * // TypeScript now knows node is DefinitionNode * console.log(node.type); // 'definition' * } * ``` */ export function isDefinitionNode(node: unknown): node is DefinitionNode { return (node as any)?.type === TYPE; } // ================================================================ // ================================================================ // // Constructor // // ================================================================ // ================================================================ /** * Creates a new {@link DefinitionNode} with the specified properties. * * @param props - The node properties * @param props.executabledefinition - {@link ExecutableDefinitionNode} * @param props.typesystemdefinition - {@link TypeSystemDefinitionNode} * @param props.typesystemextension - {@link TypeSystemExtensionNode} * @returns A new {@link DefinitionNode} * * @example * ```typescript * const node = DefinitionNode({ * // properties... * }); * ``` */ export function DefinitionNode(props: Omit): DefinitionNode { return { type: TYPE, ...props }; }