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