@domainlang/language
v0.1.82
Published
Core language library for DomainLang - parse, validate, and query Domain-Driven Design models programmatically
Maintainers
Readme
@domainlang/language
Core language library for DomainLang - a Domain-Driven Design modeling language built with Langium.
Features
- 🔤 Parser - Full DomainLang grammar with error recovery
- ✅ Validation - Semantic validation for DDD best practices
- 🔗 Linking - Cross-reference resolution across files and packages
- 🔍 Model Query SDK - Programmatic access to DDD models with fluent queries
- 🌐 Browser Support - Works in Node.js and browser environments
Installation
npm install @domainlang/languageQuick Start
Parse and Query Models
import { loadModelFromText } from '@domainlang/language/sdk';
const { query } = await loadModelFromText(`
Domain Sales {
vision: "Enable seamless commerce"
}
bc OrderContext for Sales as Core by SalesTeam {
description: "Handles order lifecycle"
}
`);
// Query bounded contexts
const coreContexts = query.boundedContexts()
.withRole('Core')
.toArray();
console.log(coreContexts[0].name); // 'OrderContext'Load from File (Node.js)
import { loadModel } from '@domainlang/language/sdk/loader-node';
const { model, query } = await loadModel('./my-model.dlang');
// Access domains
for (const domain of query.domains()) {
console.log(`${domain.name}: ${domain.vision}`);
}API Overview
Entry Points
| Function | Environment | Use Case |
| -------- | ----------- | -------- |
| loadModelFromText(text) | Browser & Node | Parse inline DSL text |
| loadModel(file) | Node.js only | Load from file system |
| fromDocument(doc) | LSP integration | Zero-copy from Langium document |
| fromModel(model) | Advanced | Direct AST wrapping |
Query Builder
The SDK provides fluent query builders with lazy evaluation:
// Find all bounded contexts owned by a team
const teamContexts = query.boundedContexts()
.withTeam('PaymentsTeam')
.toArray();
// Get context maps containing specific contexts
const maps = query.contextMaps()
.containing('OrderContext')
.toArray();Direct Property Access
// Direct AST properties
const desc = boundedContext.description;
const vision = domain.vision;
// SDK-augmented properties (with precedence resolution)
const role = boundedContext.effectiveRole; // Header 'as' wins over body 'role:'
const team = boundedContext.effectiveTeam; // Header 'by' wins over body 'team:'DomainLang Syntax
DomainLang models Domain-Driven Design concepts:
// Define domains with vision
Domain Sales {
vision: "Drive revenue through great customer experience"
}
// Bounded contexts with ownership
bc OrderContext for Sales as Core by SalesTeam {
description: "Order lifecycle management"
}
bc PaymentContext for Sales as Supporting by PaymentsTeam
// Context maps showing integrations
ContextMap SalesIntegration {
contains OrderContext, PaymentContext
[OHS,PL] OrderContext -> [CF] PaymentContext
}Package Structure
| Path | Purpose |
| ---- | ------- |
| src/domain-lang.langium | Grammar definition |
| src/generated/ | Auto-generated AST (do not edit) |
| src/validation/ | Semantic validation rules |
| src/lsp/ | LSP features (hover, completion, formatting) |
| src/sdk/ | Model Query SDK |
Related Packages
- @domainlang/cli - Command-line interface
- DomainLang VS Code Extension - IDE support
Documentation
Development
From the workspace root (dsl/domain-lang/):
# After editing the grammar
npm run langium:generate
# Build this package
npm run build --workspace packages/language
# Run tests
npm test --workspace packages/languageLicense
Apache-2.0
