/** * AST Serialization Utilities * * Converts Langium AST nodes to plain JSON objects suitable for: * - LSP custom requests (JSON-RPC transport) * - MCP tool responses (stdio JSON) * - CLI output (JSON/YAML formats) * * ## Strategy * * Rather than maintaining a parallel DTO type hierarchy (DomainDto, BoundedContextDto, etc.), * we use a **generic serializer** that: * - Strips Langium internal properties ($container, $cstNode, $document) * - Preserves $type for discriminated output * - Resolves Reference to referenced name strings * - Resolves MultiReference to arrays of names * - Recursively serializes child AstNodes * - Adds FQN for named elements via Query * * For types with SDK-augmented properties (computed values not on raw AST), * use augmentation functions that enrich the generic output. * * @packageDocumentation */ import type { AstNode, Reference } from 'langium'; import type { Query, RelationshipView } from './types.js'; /** * Canonical entity types that can be queried. * Moved from CLI to SDK for sharing with LSP tools. */ export type QueryEntityType = 'domains' | 'bcs' | 'teams' | 'classifications' | 'relationships' | 'context-maps' | 'domain-maps'; /** * All accepted entity type names, including aliases. * Aliases are normalized to canonical types before query execution. */ export type QueryEntityInput = QueryEntityType | 'bounded-contexts' | 'contexts' | 'rels' | 'cmaps' | 'dmaps'; /** * Query filter options. * Moved from CLI to SDK for sharing with LSP tools. */ export interface QueryFilters { /** Filter by name (string or regex) */ name?: string; /** Filter by fully qualified name */ fqn?: string; /** Filter BCs by domain */ domain?: string; /** Filter BCs by team */ team?: string; /** Filter BCs by classification */ classification?: string; /** Filter BCs by metadata key=value */ metadata?: string; } /** * Map of entity type aliases to their canonical form. */ export declare const ENTITY_ALIASES: Record; /** * Normalize an entity type input (which may be an alias) to its canonical form. * Throws for unknown entity types. */ export declare function normalizeEntityType(input: string): QueryEntityType; /** * Serialize any Langium AST node to a plain JSON object. * * - Strips $-prefixed internal properties ($container, $cstNode, $document) * - Preserves $type for discriminated output * - Resolves Reference to the referenced name (string) * - Resolves MultiReference to an array of names * - Recursively serializes child AstNode properties * - Serializes arrays of AstNodes/values * - Adds FQN for named elements * * @param node - AST node to serialize * @param query - Query instance for FQN resolution * @returns Plain JSON object */ export declare function serializeNode(node: AstNode, query: Query): Record; /** * Augment a serialized RelationshipView with computed properties. * * RelationshipView is already a clean DTO (not an AstNode), but we format it * consistently with other serialized types. * * @param view - RelationshipView from query.relationships() * @returns Serialized relationship object */ export declare function serializeRelationship(view: RelationshipView): Record; /** * Resolve a MultiReference (array of items with refs) to an array of names. * Filters out unresolved references. * * @param multiRef - Array of items with ref property * @returns Array of resolved names */ export declare function resolveMultiReference; }>(multiRef: T[] | undefined): string[];