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