import type { Node } from 'web-tree-sitter'; import type { EnumTypeExtensionNode } from './enum_type_extension.js'; import type { InputObjectTypeExtensionNode } from './input_object_type_extension.js'; import type { InterfaceTypeExtensionNode } from './interface_type_extension.js'; import type { ObjectTypeExtensionNode } from './object_type_extension.js'; import type { ScalarTypeExtensionNode } from './scalar_type_extension.js'; import type { UnionTypeExtensionNode } from './union_type_extension.js'; const TYPE = 'type_extension' as const; // ================================================================ // ================================================================ // // TypeExtensionNode // // GraphQL type extension node // // ================================================================ // ================================================================ /** * Represents a type extension in the GraphQL AST. * * Children: * {@link EnumTypeExtensionNode}, {@link InputObjectTypeExtensionNode}, {@link InterfaceTypeExtensionNode}, {@link ObjectTypeExtensionNode}, {@link ScalarTypeExtensionNode}, {@link UnionTypeExtensionNode} * */ export interface TypeExtensionNode extends Node { type: typeof TYPE; } // ================================================================ // ================================================================ // // Type Guard // // ================================================================ // ================================================================ /** * Type guard to check if a node is a {@link TypeExtensionNode}. * * @param node - The node to check * @returns True if the node is a {@link TypeExtensionNode} * * @example * ```typescript * if (isTypeExtensionNode(node)) { * // TypeScript now knows node is TypeExtensionNode * console.log(node.type); // 'type_extension' * } * ``` */ export function isTypeExtensionNode(node: unknown): node is TypeExtensionNode { return (node as any)?.type === TYPE; } // ================================================================ // ================================================================ // // Constructor // // ================================================================ // ================================================================ /** * Creates a new {@link TypeExtensionNode} with the specified properties. * * @param props - The node properties * @param props.enumtypeextension - {@link EnumTypeExtensionNode} * @param props.inputobjecttypeextension - {@link InputObjectTypeExtensionNode} * @param props.interfacetypeextension - {@link InterfaceTypeExtensionNode} * @param props.objecttypeextension - {@link ObjectTypeExtensionNode} * @param props.scalartypeextension - {@link ScalarTypeExtensionNode} * @param props.uniontypeextension - {@link UnionTypeExtensionNode} * @returns A new {@link TypeExtensionNode} * * @example * ```typescript * const node = TypeExtensionNode({ * // properties... * }); * ``` */ export function TypeExtensionNode(props: Omit): TypeExtensionNode { return { type: TYPE, ...props }; }