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