@domainlang/language 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +163 -0
- package/out/ast-augmentation.d.ts +6 -0
- package/out/ast-augmentation.js +2 -0
- package/out/ast-augmentation.js.map +1 -0
- package/out/domain-lang-module.d.ts +57 -0
- package/out/domain-lang-module.js +67 -0
- package/out/domain-lang-module.js.map +1 -0
- package/out/generated/ast.d.ts +759 -0
- package/out/generated/ast.js +556 -0
- package/out/generated/ast.js.map +1 -0
- package/out/generated/grammar.d.ts +6 -0
- package/out/generated/grammar.js +2407 -0
- package/out/generated/grammar.js.map +1 -0
- package/out/generated/module.d.ts +13 -0
- package/out/generated/module.js +21 -0
- package/out/generated/module.js.map +1 -0
- package/out/index.d.ts +16 -0
- package/out/index.js +22 -0
- package/out/index.js.map +1 -0
- package/out/lsp/domain-lang-code-actions.d.ts +55 -0
- package/out/lsp/domain-lang-code-actions.js +143 -0
- package/out/lsp/domain-lang-code-actions.js.map +1 -0
- package/out/lsp/domain-lang-completion.d.ts +37 -0
- package/out/lsp/domain-lang-completion.js +452 -0
- package/out/lsp/domain-lang-completion.js.map +1 -0
- package/out/lsp/domain-lang-formatter.d.ts +15 -0
- package/out/lsp/domain-lang-formatter.js +43 -0
- package/out/lsp/domain-lang-formatter.js.map +1 -0
- package/out/lsp/domain-lang-naming.d.ts +34 -0
- package/out/lsp/domain-lang-naming.js +49 -0
- package/out/lsp/domain-lang-naming.js.map +1 -0
- package/out/lsp/domain-lang-scope.d.ts +59 -0
- package/out/lsp/domain-lang-scope.js +102 -0
- package/out/lsp/domain-lang-scope.js.map +1 -0
- package/out/lsp/domain-lang-workspace-manager.d.ts +21 -0
- package/out/lsp/domain-lang-workspace-manager.js +93 -0
- package/out/lsp/domain-lang-workspace-manager.js.map +1 -0
- package/out/lsp/hover/ddd-pattern-explanations.d.ts +50 -0
- package/out/lsp/hover/ddd-pattern-explanations.js +196 -0
- package/out/lsp/hover/ddd-pattern-explanations.js.map +1 -0
- package/out/lsp/hover/domain-lang-hover.d.ts +19 -0
- package/out/lsp/hover/domain-lang-hover.js +302 -0
- package/out/lsp/hover/domain-lang-hover.js.map +1 -0
- package/out/lsp/hover/domain-lang-keywords.d.ts +13 -0
- package/out/lsp/hover/domain-lang-keywords.js +47 -0
- package/out/lsp/hover/domain-lang-keywords.js.map +1 -0
- package/out/lsp/manifest-diagnostics.d.ts +82 -0
- package/out/lsp/manifest-diagnostics.js +230 -0
- package/out/lsp/manifest-diagnostics.js.map +1 -0
- package/out/main-browser.d.ts +1 -0
- package/out/main-browser.js +11 -0
- package/out/main-browser.js.map +1 -0
- package/out/main.d.ts +1 -0
- package/out/main.js +74 -0
- package/out/main.js.map +1 -0
- package/out/sdk/ast-augmentation.d.ts +136 -0
- package/out/sdk/ast-augmentation.js +62 -0
- package/out/sdk/ast-augmentation.js.map +1 -0
- package/out/sdk/index.d.ts +94 -0
- package/out/sdk/index.js +97 -0
- package/out/sdk/index.js.map +1 -0
- package/out/sdk/indexes.d.ts +16 -0
- package/out/sdk/indexes.js +97 -0
- package/out/sdk/indexes.js.map +1 -0
- package/out/sdk/loader-node.d.ts +51 -0
- package/out/sdk/loader-node.js +119 -0
- package/out/sdk/loader-node.js.map +1 -0
- package/out/sdk/loader.d.ts +49 -0
- package/out/sdk/loader.js +85 -0
- package/out/sdk/loader.js.map +1 -0
- package/out/sdk/patterns.d.ts +93 -0
- package/out/sdk/patterns.js +123 -0
- package/out/sdk/patterns.js.map +1 -0
- package/out/sdk/query.d.ts +90 -0
- package/out/sdk/query.js +679 -0
- package/out/sdk/query.js.map +1 -0
- package/out/sdk/resolution.d.ts +52 -0
- package/out/sdk/resolution.js +68 -0
- package/out/sdk/resolution.js.map +1 -0
- package/out/sdk/types.d.ts +280 -0
- package/out/sdk/types.js +8 -0
- package/out/sdk/types.js.map +1 -0
- package/out/services/dependency-analyzer.d.ts +58 -0
- package/out/services/dependency-analyzer.js +254 -0
- package/out/services/dependency-analyzer.js.map +1 -0
- package/out/services/dependency-resolver.d.ts +146 -0
- package/out/services/dependency-resolver.js +452 -0
- package/out/services/dependency-resolver.js.map +1 -0
- package/out/services/git-url-resolver.browser.d.ts +10 -0
- package/out/services/git-url-resolver.browser.js +19 -0
- package/out/services/git-url-resolver.browser.js.map +1 -0
- package/out/services/git-url-resolver.d.ts +158 -0
- package/out/services/git-url-resolver.js +416 -0
- package/out/services/git-url-resolver.js.map +1 -0
- package/out/services/governance-validator.d.ts +44 -0
- package/out/services/governance-validator.js +153 -0
- package/out/services/governance-validator.js.map +1 -0
- package/out/services/import-resolver.d.ts +77 -0
- package/out/services/import-resolver.js +240 -0
- package/out/services/import-resolver.js.map +1 -0
- package/out/services/performance-optimizer.d.ts +60 -0
- package/out/services/performance-optimizer.js +140 -0
- package/out/services/performance-optimizer.js.map +1 -0
- package/out/services/relationship-inference.d.ts +11 -0
- package/out/services/relationship-inference.js +98 -0
- package/out/services/relationship-inference.js.map +1 -0
- package/out/services/semver.d.ts +98 -0
- package/out/services/semver.js +195 -0
- package/out/services/semver.js.map +1 -0
- package/out/services/types.d.ts +340 -0
- package/out/services/types.js +46 -0
- package/out/services/types.js.map +1 -0
- package/out/services/workspace-manager.d.ts +123 -0
- package/out/services/workspace-manager.js +489 -0
- package/out/services/workspace-manager.js.map +1 -0
- package/out/syntaxes/domain-lang.monarch.d.ts +76 -0
- package/out/syntaxes/domain-lang.monarch.js +29 -0
- package/out/syntaxes/domain-lang.monarch.js.map +1 -0
- package/out/utils/import-utils.d.ts +49 -0
- package/out/utils/import-utils.js +128 -0
- package/out/utils/import-utils.js.map +1 -0
- package/out/validation/bounded-context.d.ts +11 -0
- package/out/validation/bounded-context.js +79 -0
- package/out/validation/bounded-context.js.map +1 -0
- package/out/validation/classification.d.ts +3 -0
- package/out/validation/classification.js +3 -0
- package/out/validation/classification.js.map +1 -0
- package/out/validation/constants.d.ts +180 -0
- package/out/validation/constants.js +235 -0
- package/out/validation/constants.js.map +1 -0
- package/out/validation/domain-lang-validator.d.ts +2 -0
- package/out/validation/domain-lang-validator.js +27 -0
- package/out/validation/domain-lang-validator.js.map +1 -0
- package/out/validation/domain.d.ts +11 -0
- package/out/validation/domain.js +63 -0
- package/out/validation/domain.js.map +1 -0
- package/out/validation/import.d.ts +68 -0
- package/out/validation/import.js +237 -0
- package/out/validation/import.js.map +1 -0
- package/out/validation/manifest.d.ts +144 -0
- package/out/validation/manifest.js +327 -0
- package/out/validation/manifest.js.map +1 -0
- package/out/validation/maps.d.ts +21 -0
- package/out/validation/maps.js +60 -0
- package/out/validation/maps.js.map +1 -0
- package/out/validation/metadata.d.ts +7 -0
- package/out/validation/metadata.js +16 -0
- package/out/validation/metadata.js.map +1 -0
- package/out/validation/model.d.ts +12 -0
- package/out/validation/model.js +29 -0
- package/out/validation/model.js.map +1 -0
- package/out/validation/relationships.d.ts +12 -0
- package/out/validation/relationships.js +94 -0
- package/out/validation/relationships.js.map +1 -0
- package/out/validation/shared.d.ts +6 -0
- package/out/validation/shared.js +12 -0
- package/out/validation/shared.js.map +1 -0
- package/package.json +110 -0
- package/src/ast-augmentation.ts +5 -0
- package/src/domain-lang-module.ts +112 -0
- package/src/domain-lang.langium +351 -0
- package/src/generated/ast.ts +986 -0
- package/src/generated/grammar.ts +2409 -0
- package/src/generated/module.ts +25 -0
- package/src/index.ts +24 -0
- package/src/lsp/domain-lang-code-actions.ts +189 -0
- package/src/lsp/domain-lang-completion.ts +514 -0
- package/src/lsp/domain-lang-formatter.ts +51 -0
- package/src/lsp/domain-lang-naming.ts +56 -0
- package/src/lsp/domain-lang-scope.ts +137 -0
- package/src/lsp/domain-lang-workspace-manager.ts +104 -0
- package/src/lsp/hover/ddd-pattern-explanations.ts +237 -0
- package/src/lsp/hover/domain-lang-hover.ts +338 -0
- package/src/lsp/hover/domain-lang-keywords.ts +50 -0
- package/src/lsp/manifest-diagnostics.ts +290 -0
- package/src/main-browser.ts +15 -0
- package/src/main.ts +85 -0
- package/src/sdk/README.md +297 -0
- package/src/sdk/ast-augmentation.ts +157 -0
- package/src/sdk/index.ts +126 -0
- package/src/sdk/indexes.ts +155 -0
- package/src/sdk/loader-node.ts +146 -0
- package/src/sdk/loader.ts +99 -0
- package/src/sdk/patterns.ts +147 -0
- package/src/sdk/query.ts +802 -0
- package/src/sdk/resolution.ts +78 -0
- package/src/sdk/types.ts +323 -0
- package/src/services/dependency-analyzer.ts +321 -0
- package/src/services/dependency-resolver.ts +551 -0
- package/src/services/git-url-resolver.browser.ts +26 -0
- package/src/services/git-url-resolver.ts +517 -0
- package/src/services/governance-validator.ts +177 -0
- package/src/services/import-resolver.ts +292 -0
- package/src/services/performance-optimizer.ts +170 -0
- package/src/services/relationship-inference.ts +121 -0
- package/src/services/semver.ts +213 -0
- package/src/services/types.ts +415 -0
- package/src/services/workspace-manager.ts +607 -0
- package/src/syntaxes/domain-lang.monarch.ts +29 -0
- package/src/utils/import-utils.ts +152 -0
- package/src/validation/bounded-context.ts +99 -0
- package/src/validation/classification.ts +5 -0
- package/src/validation/constants.ts +304 -0
- package/src/validation/domain-lang-validator.ts +33 -0
- package/src/validation/domain.ts +77 -0
- package/src/validation/import.ts +295 -0
- package/src/validation/manifest.ts +439 -0
- package/src/validation/maps.ts +76 -0
- package/src/validation/metadata.ts +18 -0
- package/src/validation/model.ts +37 -0
- package/src/validation/relationships.ts +154 -0
- package/src/validation/shared.ts +14 -0
package/out/sdk/index.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model Query SDK - Public API
|
|
3
|
+
*
|
|
4
|
+
* Provides fluent, type-safe query operations on DomainLang models.
|
|
5
|
+
*
|
|
6
|
+
* ## Architecture: SDK vs LSP Responsibilities
|
|
7
|
+
*
|
|
8
|
+
* The SDK is **read-only and query-focused**. It does NOT manage:
|
|
9
|
+
* - Workspace lifecycle (LSP/WorkspaceManager handles this)
|
|
10
|
+
* - File watching or change detection (LSP/TextDocuments handles this)
|
|
11
|
+
* - Cross-file import resolution (LSP/DocumentBuilder handles this)
|
|
12
|
+
* - Document validation scheduling (LSP handles this)
|
|
13
|
+
*
|
|
14
|
+
* **SDK responsibilities:**
|
|
15
|
+
* - Augmented AST properties (transparent property access with precedence rules)
|
|
16
|
+
* - Fluent query chains with lazy iteration
|
|
17
|
+
* - O(1) indexed lookups by FQN/name
|
|
18
|
+
* - Resolution rules (which block wins for 0..1 properties)
|
|
19
|
+
*
|
|
20
|
+
* **Entry points for different deployment targets:**
|
|
21
|
+
*
|
|
22
|
+
* | Target | Entry Point | Browser-Safe | Notes |
|
|
23
|
+
* |--------|-------------|--------------|-------|
|
|
24
|
+
* | VS Code Extension | `fromDocument()` | ✅ | Zero-copy LSP integration |
|
|
25
|
+
* | Web Editor | `fromDocument()`, `loadModelFromText()` | ✅ | Browser-compatible |
|
|
26
|
+
* | CLI (Node.js) | `loadModel()` from `sdk/loader-node` | ❌ | File system access |
|
|
27
|
+
* | Hosted LSP | `fromDocument()`, `fromServices()` | ✅ | Server-side only |
|
|
28
|
+
* | Testing | `loadModelFromText()` | ✅ | In-memory parsing |
|
|
29
|
+
*
|
|
30
|
+
* ## Browser vs Node.js
|
|
31
|
+
*
|
|
32
|
+
* This module (`sdk/index`) is **browser-safe** and exports only:
|
|
33
|
+
* - `loadModelFromText()` - uses EmptyFileSystem
|
|
34
|
+
* - `fromModel()`, `fromDocument()`, `fromServices()` - zero-copy wrappers
|
|
35
|
+
*
|
|
36
|
+
* For file-based loading in Node.js CLI tools:
|
|
37
|
+
* ```typescript
|
|
38
|
+
* import { loadModel } from 'domain-lang-language/sdk/loader-node';
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @packageDocumentation
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* // Node.js CLI: Load from file (requires sdk/loader-node)
|
|
46
|
+
* import { loadModel } from 'domain-lang-language/sdk/loader-node';
|
|
47
|
+
*
|
|
48
|
+
* const { query } = await loadModel('./domains.dlang', {
|
|
49
|
+
* workspaceDir: process.cwd()
|
|
50
|
+
* });
|
|
51
|
+
*
|
|
52
|
+
* const coreContexts = query.boundedContexts()
|
|
53
|
+
* .withClassification('Core')
|
|
54
|
+
* .withTeam('PaymentTeam');
|
|
55
|
+
*
|
|
56
|
+
* for (const bc of coreContexts) {
|
|
57
|
+
* console.log(`${bc.name}: ${bc.description ?? 'n/a'}`);
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* // Browser/Testing: Load from text (browser-safe)
|
|
64
|
+
* import { loadModelFromText } from '@domainlang/language/sdk';
|
|
65
|
+
*
|
|
66
|
+
* const { query } = await loadModelFromText(`
|
|
67
|
+
* Domain Sales { vision: "Handle sales" }
|
|
68
|
+
* bc OrderContext for Sales
|
|
69
|
+
* `);
|
|
70
|
+
*
|
|
71
|
+
* const sales = query.domain('Sales');
|
|
72
|
+
* console.log(sales?.vision);
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* // LSP Integration: Zero-copy access to existing AST (browser-safe)
|
|
78
|
+
* import { fromDocument } from '@domainlang/language/sdk';
|
|
79
|
+
*
|
|
80
|
+
* export class HoverProvider {
|
|
81
|
+
* getHover(document: LangiumDocument<Model>) {
|
|
82
|
+
* // SDK wraps existing AST - no reloading, no file I/O
|
|
83
|
+
* const query = fromDocument(document);
|
|
84
|
+
* const bc = query.boundedContext('OrderContext');
|
|
85
|
+
* return bc?.description;
|
|
86
|
+
* }
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
// Browser-safe entry points
|
|
91
|
+
export { loadModelFromText } from './loader.js';
|
|
92
|
+
export { fromModel, fromDocument, fromServices, augmentModel } from './query.js';
|
|
93
|
+
// Note: loadModel() is NOT exported here - it requires Node.js filesystem
|
|
94
|
+
// For CLI/Node.js usage: import { loadModel } from '@domainlang/language/sdk/loader-node';
|
|
95
|
+
// Integration patterns for type-safe pattern matching (no magic strings)
|
|
96
|
+
export { Pattern, PatternFullName, PatternAliases, matchesPattern, isUpstreamPattern, isDownstreamPattern, isMutualPattern, UpstreamPatterns, DownstreamPatterns, MutualPatterns, } from './patterns.js';
|
|
97
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sdk/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwFG;AAEH,4BAA4B;AAC5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEjF,0EAA0E;AAC1E,2FAA2F;AAE3F,yEAAyE;AACzE,OAAO,EACH,OAAO,EACP,eAAe,EACf,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,GACjB,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Index building for O(1) lookups in the Model Query SDK.
|
|
3
|
+
* Builds maps for FQN, name, team, strategic classification, and metadata lookups.
|
|
4
|
+
*
|
|
5
|
+
* Indexes are built once during model loading and enable fast queries.
|
|
6
|
+
*/
|
|
7
|
+
import type { Model } from '../generated/ast.js';
|
|
8
|
+
import type { ModelIndexes } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Builds all indexes for a model.
|
|
11
|
+
* Called once during model loading.
|
|
12
|
+
*
|
|
13
|
+
* @param model - Root model node
|
|
14
|
+
* @returns ModelIndexes containing all lookup maps
|
|
15
|
+
*/
|
|
16
|
+
export declare function buildIndexes(model: Model): ModelIndexes;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Index building for O(1) lookups in the Model Query SDK.
|
|
3
|
+
* Builds maps for FQN, name, team, strategic classification, and metadata lookups.
|
|
4
|
+
*
|
|
5
|
+
* Indexes are built once during model loading and enable fast queries.
|
|
6
|
+
*/
|
|
7
|
+
import { AstUtils } from 'langium';
|
|
8
|
+
import { isBoundedContext, isClassification, isContextMap, isDomain, isDomainMap, isMetadata, isNamespaceDeclaration, isTeam, } from '../generated/ast.js';
|
|
9
|
+
import { QualifiedNameProvider } from '../lsp/domain-lang-naming.js';
|
|
10
|
+
import { metadataAsMap, effectiveClassification, effectiveTeam, } from './resolution.js';
|
|
11
|
+
/**
|
|
12
|
+
* Builds all indexes for a model.
|
|
13
|
+
* Called once during model loading.
|
|
14
|
+
*
|
|
15
|
+
* @param model - Root model node
|
|
16
|
+
* @returns ModelIndexes containing all lookup maps
|
|
17
|
+
*/
|
|
18
|
+
export function buildIndexes(model) {
|
|
19
|
+
const byFqn = new Map();
|
|
20
|
+
const byName = new Map();
|
|
21
|
+
const byTeam = new Map();
|
|
22
|
+
const byClassification = new Map();
|
|
23
|
+
const byMetadataKey = new Map();
|
|
24
|
+
const fqnProvider = new QualifiedNameProvider();
|
|
25
|
+
// Stream all AST nodes and index them
|
|
26
|
+
for (const node of AstUtils.streamAllContents(model)) {
|
|
27
|
+
// Index named types only
|
|
28
|
+
if (!hasName(node)) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const name = node.name;
|
|
32
|
+
const fqn = fqnProvider.getQualifiedName(node.$container, name);
|
|
33
|
+
// Index by FQN (unique)
|
|
34
|
+
byFqn.set(fqn, node);
|
|
35
|
+
// Index by simple name (may have duplicates)
|
|
36
|
+
const nameList = byName.get(name) ?? [];
|
|
37
|
+
nameList.push(node);
|
|
38
|
+
byName.set(name, nameList);
|
|
39
|
+
// BoundedContext-specific indexes
|
|
40
|
+
if (isBoundedContext(node)) {
|
|
41
|
+
indexBoundedContext(node, byTeam, byClassification, byMetadataKey);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
byFqn,
|
|
46
|
+
byName,
|
|
47
|
+
byTeam,
|
|
48
|
+
byClassification,
|
|
49
|
+
byMetadataKey,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Indexes a BoundedContext by team, strategic classification, and metadata.
|
|
54
|
+
*
|
|
55
|
+
* @param bc - BoundedContext node
|
|
56
|
+
* @param byTeam - Team index map
|
|
57
|
+
* @param byClassification - Strategic classification index map
|
|
58
|
+
* @param byMetadataKey - Metadata key index map
|
|
59
|
+
*/
|
|
60
|
+
function indexBoundedContext(bc, byTeam, byClassification, byMetadataKey) {
|
|
61
|
+
// Index by team
|
|
62
|
+
const team = effectiveTeam(bc);
|
|
63
|
+
if (team?.name) {
|
|
64
|
+
const teamList = byTeam.get(team.name) ?? [];
|
|
65
|
+
teamList.push(bc);
|
|
66
|
+
byTeam.set(team.name, teamList);
|
|
67
|
+
}
|
|
68
|
+
// Index by strategic classification
|
|
69
|
+
const classification = effectiveClassification(bc);
|
|
70
|
+
if (classification?.name) {
|
|
71
|
+
const classificationList = byClassification.get(classification.name) ?? [];
|
|
72
|
+
classificationList.push(bc);
|
|
73
|
+
byClassification.set(classification.name, classificationList);
|
|
74
|
+
}
|
|
75
|
+
// Index by metadata keys
|
|
76
|
+
const metadata = metadataAsMap(bc);
|
|
77
|
+
for (const key of metadata.keys()) {
|
|
78
|
+
const metaList = byMetadataKey.get(key) ?? [];
|
|
79
|
+
metaList.push(bc);
|
|
80
|
+
byMetadataKey.set(key, metaList);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Type guard for named AST nodes.
|
|
85
|
+
* Only these types are indexed by name.
|
|
86
|
+
*/
|
|
87
|
+
function hasName(node) {
|
|
88
|
+
return (isDomain(node) ||
|
|
89
|
+
isBoundedContext(node) ||
|
|
90
|
+
isTeam(node) ||
|
|
91
|
+
isClassification(node) ||
|
|
92
|
+
isContextMap(node) ||
|
|
93
|
+
isDomainMap(node) ||
|
|
94
|
+
isNamespaceDeclaration(node) ||
|
|
95
|
+
isMetadata(node));
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=indexes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexes.js","sourceRoot":"","sources":["../../src/sdk/indexes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAYnC,OAAO,EACH,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,QAAQ,EACR,WAAW,EACX,UAAU,EACV,sBAAsB,EACtB,MAAM,GACT,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,OAAO,EACH,aAAa,EACb,uBAAuB,EACvB,aAAa,GAChB,MAAM,iBAAiB,CAAC;AAEzB;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,KAAY;IACrC,MAAM,KAAK,GAAG,IAAI,GAAG,EAAmB,CAAC;IACzC,MAAM,MAAM,GAAG,IAAI,GAAG,EAAqB,CAAC;IAC5C,MAAM,MAAM,GAAG,IAAI,GAAG,EAA4B,CAAC;IACnD,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAA4B,CAAC;IAC7D,MAAM,aAAa,GAAG,IAAI,GAAG,EAA4B,CAAC;IAE1D,MAAM,WAAW,GAAG,IAAI,qBAAqB,EAAE,CAAC;IAEhD,sCAAsC;IACtC,KAAK,MAAM,IAAI,IAAI,QAAQ,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,CAAC;QACnD,yBAAyB;QACzB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACjB,SAAS;QACb,CAAC;QAED,MAAM,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GAAG,gBAAgB,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QAC3E,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC5B,gBAAgB,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;IAClE,CAAC;IAED,yBAAyB;IACzB,MAAM,QAAQ,GAAG,aAAa,CAAC,EAAE,CAAC,CAAC;IACnC,KAAK,MAAM,GAAG,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QAC9C,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAClB,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IACrC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,SAAS,OAAO,CAAC,IAAa;IAC1B,OAAO,CACH,QAAQ,CAAC,IAAI,CAAC;QACd,gBAAgB,CAAC,IAAI,CAAC;QACtB,MAAM,CAAC,IAAI,CAAC;QACZ,gBAAgB,CAAC,IAAI,CAAC;QACtB,YAAY,CAAC,IAAI,CAAC;QAClB,WAAW,CAAC,IAAI,CAAC;QACjB,sBAAsB,CAAC,IAAI,CAAC;QAC5B,UAAU,CAAC,IAAI,CAAC,CACnB,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js-specific loader for DomainLang models.
|
|
3
|
+
*
|
|
4
|
+
* **WARNING: This module is NOT browser-compatible.**
|
|
5
|
+
*
|
|
6
|
+
* For browser environments, use:
|
|
7
|
+
* - `fromDocument()` with documents from the LSP
|
|
8
|
+
* - `fromModel()` with pre-parsed models
|
|
9
|
+
* - `loadModelFromText()` for in-memory parsing
|
|
10
|
+
*
|
|
11
|
+
* This loader creates **isolated Langium services** for standalone CLI usage.
|
|
12
|
+
* It does NOT integrate with an existing LSP workspace.
|
|
13
|
+
*
|
|
14
|
+
* For full workspace management with cross-file imports:
|
|
15
|
+
* - Use the WorkspaceManager service
|
|
16
|
+
* - Or host the LSP server and use its services
|
|
17
|
+
*
|
|
18
|
+
* @module sdk/loader-node
|
|
19
|
+
*/
|
|
20
|
+
import type { LoadOptions, QueryContext } from './types.js';
|
|
21
|
+
/**
|
|
22
|
+
* Loads a DomainLang model from a file on disk.
|
|
23
|
+
*
|
|
24
|
+
* **Node.js only** - uses file system APIs.
|
|
25
|
+
*
|
|
26
|
+
* Supports multi-file models with imports: all imported files are
|
|
27
|
+
* automatically loaded and linked. Use `documents` in the result
|
|
28
|
+
* to see all loaded files.
|
|
29
|
+
*
|
|
30
|
+
* @param entryFile - Path to the entry .dlang file
|
|
31
|
+
* @param options - Optional load configuration
|
|
32
|
+
* @returns QueryContext with model, documents, and query API
|
|
33
|
+
* @throws Error if file cannot be loaded or parsing fails
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* import { loadModel } from '@domainlang/language/sdk/loader-node';
|
|
38
|
+
*
|
|
39
|
+
* const { query, model, documents } = await loadModel('./domains.dlang', {
|
|
40
|
+
* workspaceDir: process.cwd()
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* // Query spans all imported files
|
|
44
|
+
* for (const bc of query.boundedContexts()) {
|
|
45
|
+
* console.log(bc.name);
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* console.log(`Loaded ${documents.length} files`);
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function loadModel(entryFile: string, options?: LoadOptions): Promise<QueryContext>;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js-specific loader for DomainLang models.
|
|
3
|
+
*
|
|
4
|
+
* **WARNING: This module is NOT browser-compatible.**
|
|
5
|
+
*
|
|
6
|
+
* For browser environments, use:
|
|
7
|
+
* - `fromDocument()` with documents from the LSP
|
|
8
|
+
* - `fromModel()` with pre-parsed models
|
|
9
|
+
* - `loadModelFromText()` for in-memory parsing
|
|
10
|
+
*
|
|
11
|
+
* This loader creates **isolated Langium services** for standalone CLI usage.
|
|
12
|
+
* It does NOT integrate with an existing LSP workspace.
|
|
13
|
+
*
|
|
14
|
+
* For full workspace management with cross-file imports:
|
|
15
|
+
* - Use the WorkspaceManager service
|
|
16
|
+
* - Or host the LSP server and use its services
|
|
17
|
+
*
|
|
18
|
+
* @module sdk/loader-node
|
|
19
|
+
*/
|
|
20
|
+
import { DocumentState, URI } from 'langium';
|
|
21
|
+
import { NodeFileSystem } from 'langium/node';
|
|
22
|
+
import { isModel } from '../generated/ast.js';
|
|
23
|
+
import { createDomainLangServices } from '../domain-lang-module.js';
|
|
24
|
+
import { fromModel, augmentModel } from './query.js';
|
|
25
|
+
import { ensureImportGraphFromDocument } from '../utils/import-utils.js';
|
|
26
|
+
/**
|
|
27
|
+
* Loads a DomainLang model from a file on disk.
|
|
28
|
+
*
|
|
29
|
+
* **Node.js only** - uses file system APIs.
|
|
30
|
+
*
|
|
31
|
+
* Supports multi-file models with imports: all imported files are
|
|
32
|
+
* automatically loaded and linked. Use `documents` in the result
|
|
33
|
+
* to see all loaded files.
|
|
34
|
+
*
|
|
35
|
+
* @param entryFile - Path to the entry .dlang file
|
|
36
|
+
* @param options - Optional load configuration
|
|
37
|
+
* @returns QueryContext with model, documents, and query API
|
|
38
|
+
* @throws Error if file cannot be loaded or parsing fails
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* import { loadModel } from '@domainlang/language/sdk/loader-node';
|
|
43
|
+
*
|
|
44
|
+
* const { query, model, documents } = await loadModel('./domains.dlang', {
|
|
45
|
+
* workspaceDir: process.cwd()
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* // Query spans all imported files
|
|
49
|
+
* for (const bc of query.boundedContexts()) {
|
|
50
|
+
* console.log(bc.name);
|
|
51
|
+
* }
|
|
52
|
+
*
|
|
53
|
+
* console.log(`Loaded ${documents.length} files`);
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export async function loadModel(entryFile, options) {
|
|
57
|
+
// Resolve absolute path
|
|
58
|
+
const path = await import('path');
|
|
59
|
+
const absolutePath = path.isAbsolute(entryFile)
|
|
60
|
+
? entryFile
|
|
61
|
+
: path.resolve(options?.workspaceDir ?? process.cwd(), entryFile);
|
|
62
|
+
// Create or reuse services
|
|
63
|
+
const servicesObj = options?.services
|
|
64
|
+
? { shared: options.services.shared, DomainLang: options.services }
|
|
65
|
+
: createDomainLangServices(NodeFileSystem);
|
|
66
|
+
const services = servicesObj.DomainLang;
|
|
67
|
+
const shared = servicesObj.shared;
|
|
68
|
+
// Initialize workspace if directory provided
|
|
69
|
+
if (options?.workspaceDir) {
|
|
70
|
+
const workspaceManager = services.imports.WorkspaceManager;
|
|
71
|
+
await workspaceManager.initialize(options.workspaceDir);
|
|
72
|
+
}
|
|
73
|
+
// Read file content and create document
|
|
74
|
+
const fs = await import('fs/promises');
|
|
75
|
+
const fileContent = await fs.readFile(absolutePath, 'utf-8');
|
|
76
|
+
const uri = URI.file(absolutePath);
|
|
77
|
+
// Use proper Langium document creation
|
|
78
|
+
const document = shared.workspace.LangiumDocumentFactory.fromString(fileContent, uri);
|
|
79
|
+
// Register document and build it
|
|
80
|
+
shared.workspace.LangiumDocuments.addDocument(document);
|
|
81
|
+
await shared.workspace.DocumentBuilder.build([document], { validation: false });
|
|
82
|
+
// Traverse import graph to load all imported files
|
|
83
|
+
const importedUris = await ensureImportGraphFromDocument(document, shared.workspace.LangiumDocuments);
|
|
84
|
+
// Build all imported documents with validation
|
|
85
|
+
const allDocuments = Array.from(shared.workspace.LangiumDocuments.all);
|
|
86
|
+
await shared.workspace.DocumentBuilder.build(allDocuments, { validation: true });
|
|
87
|
+
// Wait for entry document to be fully processed
|
|
88
|
+
if (document.state < DocumentState.Validated) {
|
|
89
|
+
throw new Error(`Document not fully processed: ${absolutePath}`);
|
|
90
|
+
}
|
|
91
|
+
// Check for parsing errors
|
|
92
|
+
if (document.parseResult.lexerErrors.length > 0) {
|
|
93
|
+
const errors = document.parseResult.lexerErrors.map(e => e.message).join('\n ');
|
|
94
|
+
throw new Error(`Lexer errors in ${entryFile}:\n ${errors}`);
|
|
95
|
+
}
|
|
96
|
+
if (document.parseResult.parserErrors.length > 0) {
|
|
97
|
+
const errors = document.parseResult.parserErrors.map(e => e.message).join('\n ');
|
|
98
|
+
throw new Error(`Parser errors in ${entryFile}:\n ${errors}`);
|
|
99
|
+
}
|
|
100
|
+
const model = document.parseResult.value;
|
|
101
|
+
if (!isModel(model)) {
|
|
102
|
+
throw new Error(`Document root is not a Model: ${entryFile}`);
|
|
103
|
+
}
|
|
104
|
+
// Augment AST nodes with SDK properties for all loaded models
|
|
105
|
+
for (const doc of allDocuments) {
|
|
106
|
+
const docModel = doc.parseResult.value;
|
|
107
|
+
if (isModel(docModel)) {
|
|
108
|
+
augmentModel(docModel);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Collect all document URIs from the import graph
|
|
112
|
+
const documentUris = Array.from(importedUris).map(uriStr => URI.parse(uriStr));
|
|
113
|
+
return {
|
|
114
|
+
model,
|
|
115
|
+
documents: documentUris,
|
|
116
|
+
query: fromModel(model),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=loader-node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader-node.js","sourceRoot":"","sources":["../../src/sdk/loader-node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EA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C;IAClE,CAAC;IAED,IAAI,QAAQ,CAAC,WAAW,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/C,MAAM,MAAM,GAAG,QAAQ,CAAC,WAAW,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClF,MAAM,IAAI,KAAK,CAAC,oBAAoB,SAAS,QAAQ,MAAM,EAAE,CAAC,CAAC;IACnE,CAAC;IAED,MAAM,KAAK,GAAG,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC;IACzC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,iCAAiC,SAAS,EAAE,CAAC,CAAC;IAClE,CAAC;IAED,8DAA8D;IAC9D,KAAK,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;QAC7B,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC;QACvC,IAAI,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YACpB,YAAY,CAAC,QAAQ,CAAC,CAAC;QAC3B,CAAC;IACL,CAAC;IAED,kDAAkD;IAClD,MAAM,YAAY,GAAU,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAEtF,OAAO;QACH,KAAK;QACL,SAAS,EAAE,YAAY;QACvB,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC;KAC1B,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-safe loader for in-memory model parsing.
|
|
3
|
+
*
|
|
4
|
+
* This module provides `loadModelFromText()` which works in both
|
|
5
|
+
* browser and Node.js environments by using Langium's EmptyFileSystem.
|
|
6
|
+
*
|
|
7
|
+
* For file-based loading in Node.js CLI tools, use:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { loadModel } from '@domainlang/language/sdk/loader-node';
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* For LSP/validation code that already has a linked AST, use the sync entry points:
|
|
13
|
+
* - `fromDocument()` - from a LangiumDocument
|
|
14
|
+
* - `fromModel()` - from a Model AST node
|
|
15
|
+
* - `fromServices()` - from DomainLangServices container
|
|
16
|
+
*
|
|
17
|
+
* @module sdk/loader
|
|
18
|
+
*/
|
|
19
|
+
import type { LoadOptions, QueryContext } from './types.js';
|
|
20
|
+
/**
|
|
21
|
+
* Loads a DomainLang model from a text string.
|
|
22
|
+
*
|
|
23
|
+
* **Browser-safe** - uses in-memory file system (EmptyFileSystem).
|
|
24
|
+
*
|
|
25
|
+
* Useful for:
|
|
26
|
+
* - Testing
|
|
27
|
+
* - REPL environments
|
|
28
|
+
* - Web-based editors
|
|
29
|
+
* - Any environment without file system access
|
|
30
|
+
*
|
|
31
|
+
* @param text - DomainLang source code
|
|
32
|
+
* @param options - Optional load configuration
|
|
33
|
+
* @returns QueryContext with model and query API
|
|
34
|
+
* @throws Error if parsing fails
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* import { loadModelFromText } from '@domainlang/language/sdk';
|
|
39
|
+
*
|
|
40
|
+
* const { query } = await loadModelFromText(`
|
|
41
|
+
* Domain Sales { vision: "Handle sales" }
|
|
42
|
+
* bc OrderContext for Sales
|
|
43
|
+
* `);
|
|
44
|
+
*
|
|
45
|
+
* const sales = query.domain('Sales');
|
|
46
|
+
* console.log(sales?.resolvedVision);
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function loadModelFromText(text: string, options?: LoadOptions): Promise<QueryContext>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-safe loader for in-memory model parsing.
|
|
3
|
+
*
|
|
4
|
+
* This module provides `loadModelFromText()` which works in both
|
|
5
|
+
* browser and Node.js environments by using Langium's EmptyFileSystem.
|
|
6
|
+
*
|
|
7
|
+
* For file-based loading in Node.js CLI tools, use:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { loadModel } from '@domainlang/language/sdk/loader-node';
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* For LSP/validation code that already has a linked AST, use the sync entry points:
|
|
13
|
+
* - `fromDocument()` - from a LangiumDocument
|
|
14
|
+
* - `fromModel()` - from a Model AST node
|
|
15
|
+
* - `fromServices()` - from DomainLangServices container
|
|
16
|
+
*
|
|
17
|
+
* @module sdk/loader
|
|
18
|
+
*/
|
|
19
|
+
import { EmptyFileSystem, URI } from 'langium';
|
|
20
|
+
import { isModel } from '../generated/ast.js';
|
|
21
|
+
import { createDomainLangServices } from '../domain-lang-module.js';
|
|
22
|
+
import { augmentModel, fromModel } from './query.js';
|
|
23
|
+
/**
|
|
24
|
+
* Loads a DomainLang model from a text string.
|
|
25
|
+
*
|
|
26
|
+
* **Browser-safe** - uses in-memory file system (EmptyFileSystem).
|
|
27
|
+
*
|
|
28
|
+
* Useful for:
|
|
29
|
+
* - Testing
|
|
30
|
+
* - REPL environments
|
|
31
|
+
* - Web-based editors
|
|
32
|
+
* - Any environment without file system access
|
|
33
|
+
*
|
|
34
|
+
* @param text - DomainLang source code
|
|
35
|
+
* @param options - Optional load configuration
|
|
36
|
+
* @returns QueryContext with model and query API
|
|
37
|
+
* @throws Error if parsing fails
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* import { loadModelFromText } from '@domainlang/language/sdk';
|
|
42
|
+
*
|
|
43
|
+
* const { query } = await loadModelFromText(`
|
|
44
|
+
* Domain Sales { vision: "Handle sales" }
|
|
45
|
+
* bc OrderContext for Sales
|
|
46
|
+
* `);
|
|
47
|
+
*
|
|
48
|
+
* const sales = query.domain('Sales');
|
|
49
|
+
* console.log(sales?.resolvedVision);
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export async function loadModelFromText(text, options) {
|
|
53
|
+
// Create or reuse services (use EmptyFileSystem for in-memory parsing)
|
|
54
|
+
const servicesObj = options?.services
|
|
55
|
+
? { shared: options.services.shared, DomainLang: options.services }
|
|
56
|
+
: createDomainLangServices(EmptyFileSystem);
|
|
57
|
+
const shared = servicesObj.shared;
|
|
58
|
+
// Create document from text with a virtual URI
|
|
59
|
+
const uri = URI.parse('memory:///model.dlang');
|
|
60
|
+
const document = shared.workspace.LangiumDocumentFactory.fromString(text, uri);
|
|
61
|
+
// Register and build document
|
|
62
|
+
shared.workspace.LangiumDocuments.addDocument(document);
|
|
63
|
+
await shared.workspace.DocumentBuilder.build([document], { validation: true });
|
|
64
|
+
// Check for parsing errors
|
|
65
|
+
if (document.parseResult.lexerErrors.length > 0) {
|
|
66
|
+
const errors = document.parseResult.lexerErrors.map(e => e.message).join('\n ');
|
|
67
|
+
throw new Error(`Lexer errors:\n ${errors}`);
|
|
68
|
+
}
|
|
69
|
+
if (document.parseResult.parserErrors.length > 0) {
|
|
70
|
+
const errors = document.parseResult.parserErrors.map(e => e.message).join('\n ');
|
|
71
|
+
throw new Error(`Parser errors:\n ${errors}`);
|
|
72
|
+
}
|
|
73
|
+
const model = document.parseResult.value;
|
|
74
|
+
if (!isModel(model)) {
|
|
75
|
+
throw new Error(`Document root is not a Model`);
|
|
76
|
+
}
|
|
77
|
+
// Augment AST nodes with SDK properties
|
|
78
|
+
augmentModel(model);
|
|
79
|
+
return {
|
|
80
|
+
model,
|
|
81
|
+
documents: [document.uri],
|
|
82
|
+
query: fromModel(model),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/sdk/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO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AAI,CAAC,MAAM,CAAC,CAAC;QACjF,MAAM,IAAI,KAAK,CAAC,oBAAoB,MAAM,EAAE,CAAC,CAAC;IAClD,CAAC;IAED,IAAI,QAAQ,CAAC,WAAW,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/C,MAAM,MAAM,GAAG,QAAQ,CAAC,WAAW,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClF,MAAM,IAAI,KAAK,CAAC,qBAAqB,MAAM,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,MAAM,KAAK,GAAG,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC;IACzC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IACpD,CAAC;IAED,wCAAwC;IACxC,YAAY,CAAC,KAAK,CAAC,CAAC;IAEpB,OAAO;QACH,KAAK;QACL,SAAS,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC;QACzB,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC;KAC1B,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration Patterns - Type-safe constants for DDD integration patterns.
|
|
3
|
+
*
|
|
4
|
+
* Use these constants instead of magic strings when checking relationship patterns.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { Pattern } from '../sdk/patterns.js';
|
|
9
|
+
*
|
|
10
|
+
* // Instead of: hasPattern('SK') or hasPattern('SharedKernel')
|
|
11
|
+
* // Use:
|
|
12
|
+
* if (relationship.hasPattern(Pattern.SharedKernel)) {
|
|
13
|
+
* // ...
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Integration pattern abbreviations as used in the grammar.
|
|
19
|
+
* These are the canonical abbreviations recognized by DomainLang.
|
|
20
|
+
*/
|
|
21
|
+
export declare const Pattern: {
|
|
22
|
+
/** Open Host Service - exposes a clean API for consumers */
|
|
23
|
+
readonly OHS: "OHS";
|
|
24
|
+
/** Published Language - shared data format/protocol */
|
|
25
|
+
readonly PL: "PL";
|
|
26
|
+
/** Conformist - accepts upstream model without translation */
|
|
27
|
+
readonly CF: "CF";
|
|
28
|
+
/** Anti-Corruption Layer - translates upstream model */
|
|
29
|
+
readonly ACL: "ACL";
|
|
30
|
+
/** Shared Kernel - shared code/model ownership */
|
|
31
|
+
readonly SK: "SK";
|
|
32
|
+
/** Partnership - coordinated development */
|
|
33
|
+
readonly P: "P";
|
|
34
|
+
/** Customer/Supplier - negotiated contract */
|
|
35
|
+
readonly CustomerSupplier: "Customer/Supplier";
|
|
36
|
+
/** Separate Ways - no integration */
|
|
37
|
+
readonly SeparateWays: "Separate Ways";
|
|
38
|
+
/** Big Ball of Mud - legacy or unstructured */
|
|
39
|
+
readonly BigBallOfMud: "Big Ball of Mud";
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Full names for integration patterns.
|
|
43
|
+
* Used when patterns are spelled out in documentation blocks.
|
|
44
|
+
*/
|
|
45
|
+
export declare const PatternFullName: {
|
|
46
|
+
readonly OHS: "OpenHostService";
|
|
47
|
+
readonly PL: "PublishedLanguage";
|
|
48
|
+
readonly CF: "Conformist";
|
|
49
|
+
readonly ACL: "AntiCorruptionLayer";
|
|
50
|
+
readonly SK: "SharedKernel";
|
|
51
|
+
readonly P: "Partnership";
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Mapping from abbreviations to full names and vice versa.
|
|
55
|
+
*/
|
|
56
|
+
export declare const PatternAliases: Record<string, readonly string[]>;
|
|
57
|
+
/**
|
|
58
|
+
* Type representing any valid integration pattern (abbreviation or full name).
|
|
59
|
+
*/
|
|
60
|
+
export type IntegrationPattern = typeof Pattern[keyof typeof Pattern] | typeof PatternFullName[keyof typeof PatternFullName];
|
|
61
|
+
/**
|
|
62
|
+
* Checks if a pattern string matches any of the expected aliases.
|
|
63
|
+
* Handles both abbreviations and full names case-insensitively.
|
|
64
|
+
*
|
|
65
|
+
* @param actual - Pattern string from the AST
|
|
66
|
+
* @param expected - Pattern to match (abbreviation or full name)
|
|
67
|
+
* @returns true if patterns match
|
|
68
|
+
*/
|
|
69
|
+
export declare function matchesPattern(actual: string, expected: string): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Patterns that are typically on the upstream (provider) side.
|
|
72
|
+
*/
|
|
73
|
+
export declare const UpstreamPatterns: readonly string[];
|
|
74
|
+
/**
|
|
75
|
+
* Patterns that are typically on the downstream (consumer) side.
|
|
76
|
+
*/
|
|
77
|
+
export declare const DownstreamPatterns: readonly string[];
|
|
78
|
+
/**
|
|
79
|
+
* Patterns that require mutual/bidirectional relationships.
|
|
80
|
+
*/
|
|
81
|
+
export declare const MutualPatterns: readonly string[];
|
|
82
|
+
/**
|
|
83
|
+
* Checks if a pattern is typically an upstream pattern.
|
|
84
|
+
*/
|
|
85
|
+
export declare function isUpstreamPattern(pattern: string): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Checks if a pattern is typically a downstream pattern.
|
|
88
|
+
*/
|
|
89
|
+
export declare function isDownstreamPattern(pattern: string): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Checks if a pattern requires bidirectional relationships.
|
|
92
|
+
*/
|
|
93
|
+
export declare function isMutualPattern(pattern: string): boolean;
|