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