import type { Node } from 'web-tree-sitter'; import type { BooleanValueNode } from './boolean_value.js'; import type { EnumValueNode } from './enum_value.js'; import type { FloatValueNode } from './float_value.js'; import type { IntValueNode } from './int_value.js'; import type { ListValueNode } from './list_value.js'; import type { NullValueNode } from './null_value.js'; import type { ObjectValueNode } from './object_value.js'; import type { StringValueNode } from './string_value.js'; import type { VariableNode } from './variable.js'; const TYPE = 'value' as const; // ================================================================ // ================================================================ // // ValueNode // // GraphQL value node // // ================================================================ // ================================================================ /** * Represents a value in the GraphQL AST. * * Children: * {@link BooleanValueNode}, {@link EnumValueNode}, {@link FloatValueNode}, {@link IntValueNode}, {@link ListValueNode}, {@link NullValueNode}, {@link ObjectValueNode}, {@link StringValueNode}, {@link VariableNode} * */ export interface ValueNode extends Node { type: typeof TYPE; } // ================================================================ // ================================================================ // // Type Guard // // ================================================================ // ================================================================ /** * Type guard to check if a node is a {@link ValueNode}. * * @param node - The node to check * @returns True if the node is a {@link ValueNode} * * @example * ```typescript * if (isValueNode(node)) { * // TypeScript now knows node is ValueNode * console.log(node.type); // 'value' * } * ``` */ export function isValueNode(node: unknown): node is ValueNode { return (node as any)?.type === TYPE; } // ================================================================ // ================================================================ // // Constructor // // ================================================================ // ================================================================ /** * Creates a new {@link ValueNode} with the specified properties. * * @param props - The node properties * @param props.booleanvalue - {@link BooleanValueNode} * @param props.enumvalue - {@link EnumValueNode} * @param props.floatvalue - {@link FloatValueNode} * @param props.intvalue - {@link IntValueNode} * @param props.listvalue - {@link ListValueNode} * @param props.nullvalue - {@link NullValueNode} * @param props.objectvalue - {@link ObjectValueNode} * @param props.stringvalue - {@link StringValueNode} * @param props.variable - {@link VariableNode} * @returns A new {@link ValueNode} * * @example * ```typescript * const node = ValueNode({ * // properties... * }); * ``` */ export function ValueNode(props: Omit): ValueNode { return { type: TYPE, ...props }; }