/** * Browser-safe loader for in-memory model parsing. * * This module provides `loadModelFromText()` which works in both * browser and Node.js environments by using Langium's EmptyFileSystem. * * For repeated parsing (e.g., web playgrounds, REPLs), use `createModelLoader()` * to reuse Langium services across multiple parse calls: * ```typescript * const loader = createModelLoader(); * const result1 = await loader.loadFromText('Domain A {}'); * const result2 = await loader.loadFromText('Domain B {}'); * ``` * * For file-based loading in Node.js CLI tools, use: * ```typescript * import { loadModel } from '@domainlang/language/sdk/loader-node'; * ``` * * For LSP/validation code that already has a linked AST, use the sync entry points: * - `fromDocument()` - from a LangiumDocument * - `fromModel()` - from a Model AST node * - `fromServices()` - from DomainLangServices container * * @module sdk/loader */ import type { DomainLangServices } from './bootstrap.js'; import type { LoadOptions, QueryContext } from './types.js'; /** * A reusable model loader that maintains Langium services across multiple parse calls. * * Use this when calling `loadFromText()` repeatedly (e.g., web playgrounds, REPLs, * batch processing) to avoid the overhead of recreating Langium services each time. */ export interface ModelLoader { /** * Loads a DomainLang model from a text string, reusing internal services. * * Each call creates a fresh document but shares the underlying parser, * linker, and validator infrastructure. * * @param text - DomainLang source code * @returns QueryContext with model and query API * @throws Error if parsing fails */ loadFromText(text: string): Promise; /** The underlying DomainLang services (for advanced use). */ readonly services: DomainLangServices; } /** * Creates a reusable model loader that shares Langium services across parse calls. * * **Browser-safe** - uses in-memory file system (EmptyFileSystem). * * For applications that parse multiple texts (web playgrounds, REPLs, batch tools), * this avoids the overhead of creating new Langium services for each parse call. * * @returns A ModelLoader instance that can be used repeatedly * * @example * ```typescript * import { createModelLoader } from '@domainlang/language/sdk'; * * const loader = createModelLoader(); * * // Parse multiple texts efficiently - services are reused * const result1 = await loader.loadFromText('Domain Sales { vision: "Sales" }'); * const result2 = await loader.loadFromText('Domain Billing { vision: "Billing" }'); * ``` */ export declare function createModelLoader(): ModelLoader; /** * Loads a DomainLang model from a text string. * * **Browser-safe** - uses in-memory file system (EmptyFileSystem). * * For repeated parsing, prefer {@link createModelLoader} to reuse services. * * Useful for: * - Testing * - One-off parsing * - Any environment without file system access * * @param text - DomainLang source code * @param options - Optional load configuration * @returns QueryContext with model and query API * @throws Error if parsing fails * * @example * ```typescript * import { loadModelFromText } from '@domainlang/language/sdk'; * * const { query } = await loadModelFromText(` * Domain Sales { vision: "Handle sales" } * bc OrderContext for Sales * `); * * const sales = query.domain('Sales'); * console.log(sales?.resolvedVision); * ``` */ export declare function loadModelFromText(text: string, options?: LoadOptions): Promise;