@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
|
@@ -0,0 +1,607 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import YAML from 'yaml';
|
|
4
|
+
import { DependencyResolver } from './dependency-resolver.js';
|
|
5
|
+
import { GitUrlResolver } from './git-url-resolver.js';
|
|
6
|
+
import { getGlobalOptimizer } from './performance-optimizer.js';
|
|
7
|
+
import type {
|
|
8
|
+
LockFile,
|
|
9
|
+
LockedDependency,
|
|
10
|
+
ModelManifest,
|
|
11
|
+
DependencySpec,
|
|
12
|
+
ExtendedDependencySpec,
|
|
13
|
+
PathAliases,
|
|
14
|
+
WorkspaceManagerOptions
|
|
15
|
+
} from './types.js';
|
|
16
|
+
|
|
17
|
+
const DEFAULT_MANIFEST_FILES = [
|
|
18
|
+
'model.yaml'
|
|
19
|
+
] as const;
|
|
20
|
+
|
|
21
|
+
const DEFAULT_LOCK_FILES = [
|
|
22
|
+
'model.lock'
|
|
23
|
+
] as const;
|
|
24
|
+
|
|
25
|
+
const JSON_SPACE = 2;
|
|
26
|
+
|
|
27
|
+
interface ManifestCache {
|
|
28
|
+
readonly manifest: ModelManifest;
|
|
29
|
+
readonly path: string;
|
|
30
|
+
readonly mtimeMs: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface LoadedLockFile {
|
|
34
|
+
readonly lockFile: LockFile;
|
|
35
|
+
readonly filePath: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Coordinates workspace discovery, lock file lifecycle management, and git resolver configuration.
|
|
40
|
+
*/
|
|
41
|
+
export class WorkspaceManager {
|
|
42
|
+
private readonly manifestFiles: readonly string[];
|
|
43
|
+
private readonly lockFiles: readonly string[];
|
|
44
|
+
private workspaceRoot: string | undefined;
|
|
45
|
+
private lockFile: LockFile | undefined;
|
|
46
|
+
private gitResolver: GitUrlResolver | undefined;
|
|
47
|
+
private dependencyResolver: DependencyResolver | undefined;
|
|
48
|
+
private initializePromise: Promise<void> | undefined;
|
|
49
|
+
private manifestCache: ManifestCache | undefined;
|
|
50
|
+
|
|
51
|
+
constructor(private readonly options: WorkspaceManagerOptions = {}) {
|
|
52
|
+
this.manifestFiles = options.manifestFiles ?? [...DEFAULT_MANIFEST_FILES];
|
|
53
|
+
this.lockFiles = options.lockFiles ?? [...DEFAULT_LOCK_FILES];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Finds the workspace root, loads any existing lock file, and prepares the git resolver.
|
|
58
|
+
* Repeated calls await the same initialization work.
|
|
59
|
+
*/
|
|
60
|
+
async initialize(startPath: string): Promise<void> {
|
|
61
|
+
if (!this.initializePromise) {
|
|
62
|
+
this.initializePromise = this.performInitialization(startPath);
|
|
63
|
+
}
|
|
64
|
+
await this.initializePromise;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Returns the absolute path of the workspace root.
|
|
69
|
+
* @throws Error if {@link initialize} has not completed successfully.
|
|
70
|
+
*/
|
|
71
|
+
getWorkspaceRoot(): string {
|
|
72
|
+
if (!this.workspaceRoot) {
|
|
73
|
+
throw new Error('WorkspaceManager not initialized. Call initialize() first.');
|
|
74
|
+
}
|
|
75
|
+
return this.workspaceRoot;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Resolves the manifest file path within the workspace, if present.
|
|
80
|
+
*/
|
|
81
|
+
async getManifestPath(): Promise<string | undefined> {
|
|
82
|
+
await this.ensureInitialized();
|
|
83
|
+
const root = this.workspaceRoot;
|
|
84
|
+
if (!root) {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
for (const manifest of this.manifestFiles) {
|
|
89
|
+
const candidate = path.join(root, manifest);
|
|
90
|
+
if (await this.fileExists(candidate)) {
|
|
91
|
+
return candidate;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Returns the parsed manifest when present, otherwise undefined.
|
|
100
|
+
* Uses cached contents when unchanged on disk.
|
|
101
|
+
*/
|
|
102
|
+
async getManifest(): Promise<ModelManifest | undefined> {
|
|
103
|
+
await this.ensureInitialized();
|
|
104
|
+
return this.loadManifest();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Returns the cached lock file or triggers resolution when missing.
|
|
109
|
+
*/
|
|
110
|
+
async ensureLockFile(): Promise<LockFile> {
|
|
111
|
+
await this.ensureInitialized();
|
|
112
|
+
|
|
113
|
+
if (!this.lockFile) {
|
|
114
|
+
// Try loading from cache first
|
|
115
|
+
const optimizer = getGlobalOptimizer();
|
|
116
|
+
const cached = await optimizer.getCachedLockFile(this.workspaceRoot || '');
|
|
117
|
+
|
|
118
|
+
if (cached) {
|
|
119
|
+
this.lockFile = cached;
|
|
120
|
+
} else {
|
|
121
|
+
if (this.options.allowNetwork === false) {
|
|
122
|
+
throw new Error(
|
|
123
|
+
'Lock file (model.lock) not found and network access is disabled.\n' +
|
|
124
|
+
'Hint: Run \'dlang install\' to generate the lock file.'
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
await this.generateLockFile();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (!this.lockFile) {
|
|
132
|
+
throw new Error(
|
|
133
|
+
'Unable to resolve workspace lock file.\n' +
|
|
134
|
+
'Hint: Ensure model.yaml exists and run \'dlang install\' to generate model.lock.'
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return this.lockFile;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Gets the currently cached lock file without refreshing from disk.
|
|
143
|
+
*/
|
|
144
|
+
async getLockFile(): Promise<LockFile | undefined> {
|
|
145
|
+
await this.ensureInitialized();
|
|
146
|
+
return this.lockFile;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Reloads the lock file from disk, updating the git resolver.
|
|
151
|
+
*/
|
|
152
|
+
async refreshLockFile(): Promise<LockFile | undefined> {
|
|
153
|
+
await this.ensureInitialized();
|
|
154
|
+
const loaded = await this.loadLockFileFromDisk();
|
|
155
|
+
this.applyLockFile(loaded);
|
|
156
|
+
return this.lockFile;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Invalidates all cached data (manifest and lock file).
|
|
161
|
+
* Call this when config files change externally (e.g., from CLI commands).
|
|
162
|
+
*
|
|
163
|
+
* After invalidation, the next call to getManifest() or getLockFile()
|
|
164
|
+
* will re-read from disk.
|
|
165
|
+
*/
|
|
166
|
+
invalidateCache(): void {
|
|
167
|
+
this.manifestCache = undefined;
|
|
168
|
+
this.lockFile = undefined;
|
|
169
|
+
// Re-apply undefined to git resolver to clear its lock file
|
|
170
|
+
if (this.gitResolver) {
|
|
171
|
+
this.gitResolver.setLockFile(undefined);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Invalidates only the manifest cache.
|
|
177
|
+
* Call this when model.yaml changes.
|
|
178
|
+
*/
|
|
179
|
+
invalidateManifestCache(): void {
|
|
180
|
+
this.manifestCache = undefined;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Invalidates only the lock file cache.
|
|
185
|
+
* Call this when model.lock changes.
|
|
186
|
+
*/
|
|
187
|
+
invalidateLockCache(): void {
|
|
188
|
+
this.lockFile = undefined;
|
|
189
|
+
if (this.gitResolver) {
|
|
190
|
+
this.gitResolver.setLockFile(undefined);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Provides the shared git URL resolver configured with the current lock file.
|
|
196
|
+
*/
|
|
197
|
+
async getGitResolver(): Promise<GitUrlResolver> {
|
|
198
|
+
await this.ensureInitialized();
|
|
199
|
+
if (!this.gitResolver) {
|
|
200
|
+
throw new Error('GitUrlResolver not available. Workspace initialization failed.');
|
|
201
|
+
}
|
|
202
|
+
return this.gitResolver;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Forces dependency resolution and regenerates lock files on disk.
|
|
207
|
+
*/
|
|
208
|
+
async regenerateLockFile(): Promise<LockFile> {
|
|
209
|
+
await this.ensureInitialized();
|
|
210
|
+
await this.generateLockFile(true);
|
|
211
|
+
if (!this.lockFile) {
|
|
212
|
+
throw new Error('Failed to regenerate workspace lock file.');
|
|
213
|
+
}
|
|
214
|
+
return this.lockFile;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Returns the path aliases from the manifest, if present.
|
|
219
|
+
*/
|
|
220
|
+
async getPathAliases(): Promise<PathAliases | undefined> {
|
|
221
|
+
const manifest = await this.getManifest();
|
|
222
|
+
return manifest?.paths;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Normalizes a dependency entry to its extended form.
|
|
227
|
+
* Handles both short form (string version) and extended form (object).
|
|
228
|
+
*
|
|
229
|
+
* In the new format, the key IS the owner/package, so source is derived from key
|
|
230
|
+
* ONLY for git dependencies (not for path-based local dependencies).
|
|
231
|
+
*/
|
|
232
|
+
private normalizeDependency(key: string, dep: DependencySpec): ExtendedDependencySpec {
|
|
233
|
+
if (typeof dep === 'string') {
|
|
234
|
+
// Short form: "owner/package": "v1.0.0" or "main"
|
|
235
|
+
// Key is the source (owner/package format)
|
|
236
|
+
return { source: key, ref: dep };
|
|
237
|
+
}
|
|
238
|
+
// Extended form:
|
|
239
|
+
// - If has source: use as-is
|
|
240
|
+
// - If has path: it's a local dep, don't set source
|
|
241
|
+
// - If neither: derive source from key (owner/package becomes source)
|
|
242
|
+
if (dep.source || dep.path) {
|
|
243
|
+
return dep;
|
|
244
|
+
}
|
|
245
|
+
return { ...dep, source: key };
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Resolves a manifest dependency to its git import string.
|
|
250
|
+
*
|
|
251
|
+
* NEW FORMAT (PRS-010): Dependencies are keyed by owner/package directly
|
|
252
|
+
* @param specifier - Import specifier (owner/package format, may include subpaths)
|
|
253
|
+
* @returns Resolved git import string or undefined when not found
|
|
254
|
+
*/
|
|
255
|
+
async resolveDependencyImport(specifier: string): Promise<string | undefined> {
|
|
256
|
+
await this.ensureInitialized();
|
|
257
|
+
const manifest = await this.loadManifest();
|
|
258
|
+
const dependencies = manifest?.dependencies;
|
|
259
|
+
|
|
260
|
+
if (!dependencies) {
|
|
261
|
+
return undefined;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// NEW: Dependencies are keyed by owner/package (e.g., "domainlang/core")
|
|
265
|
+
// Import specifier is also owner/package, potentially with subpath
|
|
266
|
+
for (const [key, dep] of Object.entries(dependencies)) {
|
|
267
|
+
const normalized = this.normalizeDependency(key, dep);
|
|
268
|
+
|
|
269
|
+
// Skip path-based dependencies (handled by path aliases)
|
|
270
|
+
if (normalized.path) {
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (!normalized.source) {
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Match if specifier equals key or starts with key/
|
|
279
|
+
if (specifier === key || specifier.startsWith(`${key}/`)) {
|
|
280
|
+
const suffix = specifier.slice(key.length);
|
|
281
|
+
const ref = normalized.ref ?? '';
|
|
282
|
+
const refSegment = ref
|
|
283
|
+
? (ref.startsWith('@') ? ref : `@${ref}`)
|
|
284
|
+
: '';
|
|
285
|
+
return `${normalized.source}${refSegment}${suffix}`;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return undefined;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
private async performInitialization(startPath: string): Promise<void> {
|
|
293
|
+
this.workspaceRoot = await this.findWorkspaceRoot(startPath) ?? path.resolve(startPath);
|
|
294
|
+
|
|
295
|
+
// Per PRS-010: Project-local cache at .dlang/packages/ (like node_modules)
|
|
296
|
+
const cacheDir = path.join(this.workspaceRoot, '.dlang', 'packages');
|
|
297
|
+
this.gitResolver = new GitUrlResolver(cacheDir);
|
|
298
|
+
const loaded = await this.loadLockFileFromDisk();
|
|
299
|
+
this.applyLockFile(loaded);
|
|
300
|
+
|
|
301
|
+
if (!this.lockFile && this.options.autoResolve !== false && this.options.allowNetwork !== false) {
|
|
302
|
+
await this.generateLockFile();
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
private async ensureInitialized(): Promise<void> {
|
|
307
|
+
if (this.initializePromise) {
|
|
308
|
+
await this.initializePromise;
|
|
309
|
+
} else if (!this.workspaceRoot) {
|
|
310
|
+
throw new Error('WorkspaceManager not initialized. Call initialize() first.');
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
private applyLockFile(loaded: LoadedLockFile | undefined): void {
|
|
315
|
+
if (!this.gitResolver) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (loaded) {
|
|
320
|
+
this.lockFile = loaded.lockFile;
|
|
321
|
+
this.gitResolver.setLockFile(this.lockFile);
|
|
322
|
+
} else {
|
|
323
|
+
this.lockFile = undefined;
|
|
324
|
+
this.gitResolver.setLockFile(undefined);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
private async generateLockFile(force = false): Promise<void> {
|
|
329
|
+
if (!this.workspaceRoot || !this.gitResolver) {
|
|
330
|
+
throw new Error('WorkspaceManager not initialized.');
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const resolver = this.ensureDependencyResolver();
|
|
334
|
+
if (!force && this.lockFile) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const lockFile = await resolver.resolveDependencies();
|
|
339
|
+
this.lockFile = lockFile;
|
|
340
|
+
this.gitResolver.setLockFile(lockFile);
|
|
341
|
+
|
|
342
|
+
// Write JSON lock file
|
|
343
|
+
await this.writeJsonLockFile(lockFile);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
private ensureDependencyResolver(): DependencyResolver {
|
|
347
|
+
if (!this.workspaceRoot || !this.gitResolver) {
|
|
348
|
+
throw new Error('WorkspaceManager not initialized.');
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (!this.dependencyResolver) {
|
|
352
|
+
this.dependencyResolver = new DependencyResolver(this.workspaceRoot, this.gitResolver);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return this.dependencyResolver;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
private async writeJsonLockFile(lockFile: LockFile): Promise<void> {
|
|
359
|
+
if (!this.workspaceRoot) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
const jsonPath = path.join(this.workspaceRoot, 'model.lock');
|
|
364
|
+
const payload = {
|
|
365
|
+
version: lockFile.version,
|
|
366
|
+
dependencies: lockFile.dependencies,
|
|
367
|
+
} satisfies LockFile;
|
|
368
|
+
|
|
369
|
+
await fs.writeFile(jsonPath, JSON.stringify(payload, undefined, JSON_SPACE), 'utf-8');
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
private async loadLockFileFromDisk(): Promise<LoadedLockFile | undefined> {
|
|
373
|
+
if (!this.workspaceRoot) {
|
|
374
|
+
return undefined;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
for (const filename of this.lockFiles) {
|
|
378
|
+
const filePath = path.join(this.workspaceRoot, filename);
|
|
379
|
+
const lockFile = await this.tryReadLockFile(filePath, filename);
|
|
380
|
+
if (lockFile) {
|
|
381
|
+
return { lockFile, filePath };
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
return undefined;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
private async tryReadLockFile(filePath: string, _filename: string): Promise<LockFile | undefined> {
|
|
389
|
+
try {
|
|
390
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
391
|
+
return this.parseJsonLockFile(content);
|
|
392
|
+
} catch (error) {
|
|
393
|
+
if ((error as NodeJS.ErrnoException)?.code === 'ENOENT') {
|
|
394
|
+
return undefined;
|
|
395
|
+
}
|
|
396
|
+
throw error;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
private async loadManifest(): Promise<ModelManifest | undefined> {
|
|
401
|
+
const manifestPath = await this.getManifestPath();
|
|
402
|
+
if (!manifestPath) {
|
|
403
|
+
this.manifestCache = undefined;
|
|
404
|
+
return undefined;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
try {
|
|
408
|
+
const stat = await fs.stat(manifestPath);
|
|
409
|
+
if (this.manifestCache &&
|
|
410
|
+
this.manifestCache.path === manifestPath &&
|
|
411
|
+
this.manifestCache.mtimeMs === stat.mtimeMs) {
|
|
412
|
+
return this.manifestCache.manifest;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
const content = await fs.readFile(manifestPath, 'utf-8');
|
|
416
|
+
const manifest = (YAML.parse(content) ?? {}) as ModelManifest;
|
|
417
|
+
|
|
418
|
+
// Validate manifest structure
|
|
419
|
+
this.validateManifest(manifest, manifestPath);
|
|
420
|
+
|
|
421
|
+
this.manifestCache = {
|
|
422
|
+
manifest,
|
|
423
|
+
path: manifestPath,
|
|
424
|
+
mtimeMs: stat.mtimeMs,
|
|
425
|
+
};
|
|
426
|
+
return manifest;
|
|
427
|
+
} catch (error) {
|
|
428
|
+
if ((error as NodeJS.ErrnoException)?.code === 'ENOENT') {
|
|
429
|
+
this.manifestCache = undefined;
|
|
430
|
+
return undefined;
|
|
431
|
+
}
|
|
432
|
+
throw error;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Validates manifest structure and dependency configurations.
|
|
438
|
+
* Throws detailed errors for invalid manifests.
|
|
439
|
+
*
|
|
440
|
+
* Supports both new format (owner/package: version) and extended format.
|
|
441
|
+
*/
|
|
442
|
+
private validateManifest(manifest: ModelManifest, manifestPath: string): void {
|
|
443
|
+
// Validate path aliases
|
|
444
|
+
if (manifest.paths) {
|
|
445
|
+
this.validatePathAliases(manifest.paths, manifestPath);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
if (!manifest.dependencies) {
|
|
449
|
+
return; // No dependencies to validate
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
for (const [key, dep] of Object.entries(manifest.dependencies)) {
|
|
453
|
+
const normalized = this.normalizeDependency(key, dep);
|
|
454
|
+
|
|
455
|
+
// Validate mutually exclusive source and path
|
|
456
|
+
if (normalized.source && normalized.path) {
|
|
457
|
+
throw new Error(
|
|
458
|
+
`Invalid dependency '${key}' in ${manifestPath}:\n` +
|
|
459
|
+
`Cannot specify both 'source' and 'path'.\n` +
|
|
460
|
+
`Hint: Use 'source' for git dependencies or 'path' for local workspace dependencies.`
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// For string format, source is always derived from key (valid)
|
|
465
|
+
// For extended format without source or path, error
|
|
466
|
+
if (typeof dep !== 'string' && !normalized.source && !normalized.path) {
|
|
467
|
+
throw new Error(
|
|
468
|
+
`Invalid dependency '${key}' in ${manifestPath}:\n` +
|
|
469
|
+
`Must specify either 'source' or 'path'.\n` +
|
|
470
|
+
`Hint: Add 'source: owner/repo' for git dependencies, or 'path: ./local/path' for local packages.`
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// Validate path is relative and within workspace
|
|
475
|
+
if (normalized.path) {
|
|
476
|
+
this.validateLocalPath(normalized.path, key, manifestPath);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// Validate source has ref when specified
|
|
480
|
+
if (normalized.source && !normalized.ref) {
|
|
481
|
+
throw new Error(
|
|
482
|
+
`Invalid dependency '${key}' in ${manifestPath}:\n` +
|
|
483
|
+
`Git dependencies must specify a 'ref' (git reference).\n` +
|
|
484
|
+
`Hint: Add 'ref: v1.0.0' (tag), 'ref: main' (branch), or a commit SHA.`
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Validates path aliases for security and correctness.
|
|
492
|
+
*/
|
|
493
|
+
private validatePathAliases(paths: PathAliases, manifestPath: string): void {
|
|
494
|
+
for (const [alias, targetPath] of Object.entries(paths)) {
|
|
495
|
+
// Validate alias starts with @
|
|
496
|
+
if (!alias.startsWith('@')) {
|
|
497
|
+
throw new Error(
|
|
498
|
+
`Invalid path alias '${alias}' in ${manifestPath}:\n` +
|
|
499
|
+
`Path aliases must start with '@'.\n` +
|
|
500
|
+
`Hint: Rename to '@${alias}' in your model.yaml paths section.`
|
|
501
|
+
);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// Validate target path doesn't escape workspace
|
|
505
|
+
this.validateLocalPath(targetPath, alias, manifestPath);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Validates local path dependencies for security.
|
|
511
|
+
* Ensures paths don't escape workspace boundary.
|
|
512
|
+
*/
|
|
513
|
+
private validateLocalPath(localPath: string, alias: string, manifestPath: string): void {
|
|
514
|
+
// Reject absolute paths
|
|
515
|
+
if (path.isAbsolute(localPath)) {
|
|
516
|
+
throw new Error(
|
|
517
|
+
`Invalid local path '${alias}' in ${manifestPath}:\n` +
|
|
518
|
+
`Cannot use absolute path '${localPath}'.\n` +
|
|
519
|
+
`Hint: Use relative paths (e.g., './lib', '../shared') for local dependencies.`
|
|
520
|
+
);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// Resolve path relative to manifest directory
|
|
524
|
+
const manifestDir = path.dirname(manifestPath);
|
|
525
|
+
const resolvedPath = path.resolve(manifestDir, localPath);
|
|
526
|
+
const workspaceRoot = this.workspaceRoot || manifestDir;
|
|
527
|
+
|
|
528
|
+
// Check if resolved path is within workspace
|
|
529
|
+
const relativePath = path.relative(workspaceRoot, resolvedPath);
|
|
530
|
+
if (relativePath.startsWith('..') || path.isAbsolute(relativePath)) {
|
|
531
|
+
throw new Error(
|
|
532
|
+
`Invalid local path '${alias}' in ${manifestPath}:\n` +
|
|
533
|
+
`Path '${localPath}' resolves outside workspace boundary.\n` +
|
|
534
|
+
`Resolved: ${resolvedPath}\n` +
|
|
535
|
+
`Workspace: ${workspaceRoot}\n` +
|
|
536
|
+
`Hint: Local dependencies must be within the workspace. Consider moving the dependency or using a git-based source.`
|
|
537
|
+
);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
private parseJsonLockFile(content: string): LockFile {
|
|
542
|
+
const parsed = JSON.parse(content) as Partial<LockFile> & {
|
|
543
|
+
dependencies?: Record<string, Partial<LockedDependency>>;
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
const version = typeof parsed.version === 'string' ? parsed.version : '1';
|
|
547
|
+
const dependencies: Record<string, LockedDependency> = {};
|
|
548
|
+
|
|
549
|
+
for (const [key, value] of Object.entries(parsed.dependencies ?? {})) {
|
|
550
|
+
if (!value || typeof value.ref !== 'string' || typeof value.resolved !== 'string' || typeof value.commit !== 'string') {
|
|
551
|
+
continue;
|
|
552
|
+
}
|
|
553
|
+
dependencies[key] = {
|
|
554
|
+
ref: value.ref,
|
|
555
|
+
refType: value.refType ?? 'commit', // Default to commit for backwards compatibility
|
|
556
|
+
resolved: value.resolved,
|
|
557
|
+
commit: value.commit,
|
|
558
|
+
integrity: value.integrity,
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
return { version, dependencies };
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
private async findWorkspaceRoot(startPath: string): Promise<string | undefined> {
|
|
566
|
+
let current = path.resolve(startPath);
|
|
567
|
+
const { root } = path.parse(current);
|
|
568
|
+
|
|
569
|
+
while (true) {
|
|
570
|
+
if (await this.containsManifest(current)) {
|
|
571
|
+
return current;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
if (current === root) {
|
|
575
|
+
return undefined;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
const parent = path.dirname(current);
|
|
579
|
+
if (parent === current) {
|
|
580
|
+
return undefined;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
current = parent;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
private async containsManifest(dir: string): Promise<boolean> {
|
|
588
|
+
for (const manifest of this.manifestFiles) {
|
|
589
|
+
if (await this.fileExists(path.join(dir, manifest))) {
|
|
590
|
+
return true;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
return false;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
private async fileExists(targetPath: string): Promise<boolean> {
|
|
597
|
+
try {
|
|
598
|
+
await fs.access(targetPath);
|
|
599
|
+
return true;
|
|
600
|
+
} catch (error) {
|
|
601
|
+
if ((error as NodeJS.ErrnoException)?.code === 'ENOENT') {
|
|
602
|
+
return false;
|
|
603
|
+
}
|
|
604
|
+
throw error;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Monarch syntax highlighting for the domain-lang language.
|
|
2
|
+
export default {
|
|
3
|
+
keywords: [
|
|
4
|
+
'ACL','AntiCorruptionLayer','BBoM','BigBallOfMud','BoundedContext','CF','Classification','Conformist','ContextMap','CustomerSupplier','Decision','Domain','DomainMap','Import','Metadata','Namespace','OHS','OpenHostService','P','PL','Partnership','Policy','PublishedLanguage','Rule','SK','SeparateWays','SharedKernel','Team','Term','UpstreamDownstream','aka','archetype','as','bc','businessModel','by','classification','cmap','contains','decision','decisions','description','dmap','dom','evolution','examples','for','glossary','import','in','integrations','is','meta','metadata','ns','policy','relationships','rule','rules','synonyms','team','term','terminology','this','type','vision'
|
|
5
|
+
],
|
|
6
|
+
operators: [
|
|
7
|
+
',','->','.',':','<-','<->','=','><'
|
|
8
|
+
],
|
|
9
|
+
symbols: /,|->|\.|:|<-|<->|=|><|\[|\]|\{|\}/,
|
|
10
|
+
|
|
11
|
+
tokenizer: {
|
|
12
|
+
initial: [
|
|
13
|
+
{ regex: /[_a-zA-Z][\w_-]*/, action: { cases: { '@keywords': {"token":"keyword"}, '@default': {"token":"ID"} }} },
|
|
14
|
+
{ regex: /"(\\.|[^"\\])*"|'(\\.|[^'\\])*'/, action: {"token":"string"} },
|
|
15
|
+
{ include: '@whitespace' },
|
|
16
|
+
{ regex: /@symbols/, action: { cases: { '@operators': {"token":"operator"}, '@default': {"token":""} }} },
|
|
17
|
+
],
|
|
18
|
+
whitespace: [
|
|
19
|
+
{ regex: /\s+/, action: {"token":"white"} },
|
|
20
|
+
{ regex: /\/\*/, action: {"token":"comment","next":"@comment"} },
|
|
21
|
+
{ regex: /\/\/[^\n\r]*/, action: {"token":"comment"} },
|
|
22
|
+
],
|
|
23
|
+
comment: [
|
|
24
|
+
{ regex: /[^/\*]+/, action: {"token":"comment"} },
|
|
25
|
+
{ regex: /\*\//, action: {"token":"comment","next":"@pop"} },
|
|
26
|
+
{ regex: /[/\*]/, action: {"token":"comment"} },
|
|
27
|
+
],
|
|
28
|
+
}
|
|
29
|
+
};
|