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