import type { Node } from 'web-tree-sitter'; import type { DirectiveDefinitionNode } from './directive_definition.js'; import type { SchemaDefinitionNode } from './schema_definition.js'; import type { TypeDefinitionNode } from './type_definition.js'; const TYPE = 'type_system_definition' as const; // ================================================================ // ================================================================ // // TypeSystemDefinitionNode // // GraphQL type system definition node // // ================================================================ // ================================================================ /** * Represents a type system definition in the GraphQL AST. * * Children: * {@link DirectiveDefinitionNode}, {@link SchemaDefinitionNode}, {@link TypeDefinitionNode} * */ export interface TypeSystemDefinitionNode extends Node { type: typeof TYPE; } // ================================================================ // ================================================================ // // Type Guard // // ================================================================ // ================================================================ /** * Type guard to check if a node is a {@link TypeSystemDefinitionNode}. * * @param node - The node to check * @returns True if the node is a {@link TypeSystemDefinitionNode} * * @example * ```typescript * if (isTypeSystemDefinitionNode(node)) { * // TypeScript now knows node is TypeSystemDefinitionNode * console.log(node.type); // 'type_system_definition' * } * ``` */ export function isTypeSystemDefinitionNode(node: unknown): node is TypeSystemDefinitionNode { return (node as any)?.type === TYPE; } // ================================================================ // ================================================================ // // Constructor // // ================================================================ // ================================================================ /** * Creates a new {@link TypeSystemDefinitionNode} with the specified properties. * * @param props - The node properties * @param props.directivedefinition - {@link DirectiveDefinitionNode} * @param props.schemadefinition - {@link SchemaDefinitionNode} * @param props.typedefinition - {@link TypeDefinitionNode} * @returns A new {@link TypeSystemDefinitionNode} * * @example * ```typescript * const node = TypeSystemDefinitionNode({ * // properties... * }); * ``` */ export function TypeSystemDefinitionNode(props: Omit): TypeSystemDefinitionNode { return { type: TYPE, ...props }; }