@principal-ai/principal-view-core 0.5.6
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 +126 -0
- package/dist/ConfigurationLoader.d.ts +76 -0
- package/dist/ConfigurationLoader.d.ts.map +1 -0
- package/dist/ConfigurationLoader.js +144 -0
- package/dist/ConfigurationLoader.js.map +1 -0
- package/dist/ConfigurationValidator.d.ts +31 -0
- package/dist/ConfigurationValidator.d.ts.map +1 -0
- package/dist/ConfigurationValidator.js +242 -0
- package/dist/ConfigurationValidator.js.map +1 -0
- package/dist/EventProcessor.d.ts +49 -0
- package/dist/EventProcessor.d.ts.map +1 -0
- package/dist/EventProcessor.js +215 -0
- package/dist/EventProcessor.js.map +1 -0
- package/dist/EventRecorderService.d.ts +305 -0
- package/dist/EventRecorderService.d.ts.map +1 -0
- package/dist/EventRecorderService.js +463 -0
- package/dist/EventRecorderService.js.map +1 -0
- package/dist/LibraryLoader.d.ts +63 -0
- package/dist/LibraryLoader.d.ts.map +1 -0
- package/dist/LibraryLoader.js +188 -0
- package/dist/LibraryLoader.js.map +1 -0
- package/dist/PathBasedEventProcessor.d.ts +90 -0
- package/dist/PathBasedEventProcessor.d.ts.map +1 -0
- package/dist/PathBasedEventProcessor.js +239 -0
- package/dist/PathBasedEventProcessor.js.map +1 -0
- package/dist/SessionManager.d.ts +194 -0
- package/dist/SessionManager.d.ts.map +1 -0
- package/dist/SessionManager.js +299 -0
- package/dist/SessionManager.js.map +1 -0
- package/dist/ValidationEngine.d.ts +31 -0
- package/dist/ValidationEngine.d.ts.map +1 -0
- package/dist/ValidationEngine.js +158 -0
- package/dist/ValidationEngine.js.map +1 -0
- package/dist/helpers/GraphInstrumentationHelper.d.ts +93 -0
- package/dist/helpers/GraphInstrumentationHelper.d.ts.map +1 -0
- package/dist/helpers/GraphInstrumentationHelper.js +248 -0
- package/dist/helpers/GraphInstrumentationHelper.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/rules/config.d.ts +57 -0
- package/dist/rules/config.d.ts.map +1 -0
- package/dist/rules/config.js +382 -0
- package/dist/rules/config.js.map +1 -0
- package/dist/rules/engine.d.ts +70 -0
- package/dist/rules/engine.d.ts.map +1 -0
- package/dist/rules/engine.js +252 -0
- package/dist/rules/engine.js.map +1 -0
- package/dist/rules/implementations/connection-type-references.d.ts +7 -0
- package/dist/rules/implementations/connection-type-references.d.ts.map +1 -0
- package/dist/rules/implementations/connection-type-references.js +104 -0
- package/dist/rules/implementations/connection-type-references.js.map +1 -0
- package/dist/rules/implementations/dead-end-states.d.ts +17 -0
- package/dist/rules/implementations/dead-end-states.d.ts.map +1 -0
- package/dist/rules/implementations/dead-end-states.js +72 -0
- package/dist/rules/implementations/dead-end-states.js.map +1 -0
- package/dist/rules/implementations/index.d.ts +24 -0
- package/dist/rules/implementations/index.d.ts.map +1 -0
- package/dist/rules/implementations/index.js +62 -0
- package/dist/rules/implementations/index.js.map +1 -0
- package/dist/rules/implementations/library-node-type-match.d.ts +17 -0
- package/dist/rules/implementations/library-node-type-match.d.ts.map +1 -0
- package/dist/rules/implementations/library-node-type-match.js +123 -0
- package/dist/rules/implementations/library-node-type-match.js.map +1 -0
- package/dist/rules/implementations/minimum-node-sources.d.ts +22 -0
- package/dist/rules/implementations/minimum-node-sources.d.ts.map +1 -0
- package/dist/rules/implementations/minimum-node-sources.js +54 -0
- package/dist/rules/implementations/minimum-node-sources.js.map +1 -0
- package/dist/rules/implementations/no-unknown-fields.d.ts +7 -0
- package/dist/rules/implementations/no-unknown-fields.d.ts.map +1 -0
- package/dist/rules/implementations/no-unknown-fields.js +211 -0
- package/dist/rules/implementations/no-unknown-fields.js.map +1 -0
- package/dist/rules/implementations/orphaned-edge-types.d.ts +7 -0
- package/dist/rules/implementations/orphaned-edge-types.d.ts.map +1 -0
- package/dist/rules/implementations/orphaned-edge-types.js +47 -0
- package/dist/rules/implementations/orphaned-edge-types.js.map +1 -0
- package/dist/rules/implementations/orphaned-node-types.d.ts +7 -0
- package/dist/rules/implementations/orphaned-node-types.d.ts.map +1 -0
- package/dist/rules/implementations/orphaned-node-types.js +50 -0
- package/dist/rules/implementations/orphaned-node-types.js.map +1 -0
- package/dist/rules/implementations/required-metadata.d.ts +7 -0
- package/dist/rules/implementations/required-metadata.d.ts.map +1 -0
- package/dist/rules/implementations/required-metadata.js +57 -0
- package/dist/rules/implementations/required-metadata.js.map +1 -0
- package/dist/rules/implementations/state-transition-references.d.ts +7 -0
- package/dist/rules/implementations/state-transition-references.d.ts.map +1 -0
- package/dist/rules/implementations/state-transition-references.js +135 -0
- package/dist/rules/implementations/state-transition-references.js.map +1 -0
- package/dist/rules/implementations/unreachable-states.d.ts +7 -0
- package/dist/rules/implementations/unreachable-states.d.ts.map +1 -0
- package/dist/rules/implementations/unreachable-states.js +80 -0
- package/dist/rules/implementations/unreachable-states.js.map +1 -0
- package/dist/rules/implementations/valid-action-patterns.d.ts +17 -0
- package/dist/rules/implementations/valid-action-patterns.d.ts.map +1 -0
- package/dist/rules/implementations/valid-action-patterns.js +109 -0
- package/dist/rules/implementations/valid-action-patterns.js.map +1 -0
- package/dist/rules/implementations/valid-color-format.d.ts +7 -0
- package/dist/rules/implementations/valid-color-format.d.ts.map +1 -0
- package/dist/rules/implementations/valid-color-format.js +91 -0
- package/dist/rules/implementations/valid-color-format.js.map +1 -0
- package/dist/rules/implementations/valid-edge-types.d.ts +7 -0
- package/dist/rules/implementations/valid-edge-types.d.ts.map +1 -0
- package/dist/rules/implementations/valid-edge-types.js +244 -0
- package/dist/rules/implementations/valid-edge-types.js.map +1 -0
- package/dist/rules/implementations/valid-node-types.d.ts +7 -0
- package/dist/rules/implementations/valid-node-types.d.ts.map +1 -0
- package/dist/rules/implementations/valid-node-types.js +175 -0
- package/dist/rules/implementations/valid-node-types.js.map +1 -0
- package/dist/rules/index.d.ts +28 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +45 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/types.d.ts +309 -0
- package/dist/rules/types.d.ts.map +1 -0
- package/dist/rules/types.js +35 -0
- package/dist/rules/types.js.map +1 -0
- package/dist/types/canvas.d.ts +409 -0
- package/dist/types/canvas.d.ts.map +1 -0
- package/dist/types/canvas.js +70 -0
- package/dist/types/canvas.js.map +1 -0
- package/dist/types/index.d.ts +311 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +13 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/library.d.ts +185 -0
- package/dist/types/library.d.ts.map +1 -0
- package/dist/types/library.js +15 -0
- package/dist/types/library.js.map +1 -0
- package/dist/types/path-based-config.d.ts +230 -0
- package/dist/types/path-based-config.d.ts.map +1 -0
- package/dist/types/path-based-config.js +9 -0
- package/dist/types/path-based-config.js.map +1 -0
- package/dist/utils/CanvasConverter.d.ts +118 -0
- package/dist/utils/CanvasConverter.d.ts.map +1 -0
- package/dist/utils/CanvasConverter.js +315 -0
- package/dist/utils/CanvasConverter.js.map +1 -0
- package/dist/utils/GraphConverter.d.ts +18 -0
- package/dist/utils/GraphConverter.d.ts.map +1 -0
- package/dist/utils/GraphConverter.js +61 -0
- package/dist/utils/GraphConverter.js.map +1 -0
- package/dist/utils/LibraryConverter.d.ts +113 -0
- package/dist/utils/LibraryConverter.d.ts.map +1 -0
- package/dist/utils/LibraryConverter.js +166 -0
- package/dist/utils/LibraryConverter.js.map +1 -0
- package/dist/utils/PathMatcher.d.ts +55 -0
- package/dist/utils/PathMatcher.d.ts.map +1 -0
- package/dist/utils/PathMatcher.js +172 -0
- package/dist/utils/PathMatcher.js.map +1 -0
- package/dist/utils/YamlParser.d.ts +36 -0
- package/dist/utils/YamlParser.d.ts.map +1 -0
- package/dist/utils/YamlParser.js +63 -0
- package/dist/utils/YamlParser.js.map +1 -0
- package/package.json +47 -0
- package/src/ConfigurationLoader.test.ts +490 -0
- package/src/ConfigurationLoader.ts +185 -0
- package/src/ConfigurationValidator.test.ts +200 -0
- package/src/ConfigurationValidator.ts +283 -0
- package/src/EventProcessor.test.ts +405 -0
- package/src/EventProcessor.ts +250 -0
- package/src/EventRecorderService.test.ts +541 -0
- package/src/EventRecorderService.ts +744 -0
- package/src/LibraryLoader.ts +215 -0
- package/src/PathBasedEventProcessor.test.ts +567 -0
- package/src/PathBasedEventProcessor.ts +332 -0
- package/src/SessionManager.test.ts +424 -0
- package/src/SessionManager.ts +470 -0
- package/src/ValidationEngine.test.ts +371 -0
- package/src/ValidationEngine.ts +196 -0
- package/src/helpers/GraphInstrumentationHelper.test.ts +340 -0
- package/src/helpers/GraphInstrumentationHelper.ts +326 -0
- package/src/index.ts +85 -0
- package/src/rules/config.test.ts +278 -0
- package/src/rules/config.ts +459 -0
- package/src/rules/engine.test.ts +332 -0
- package/src/rules/engine.ts +318 -0
- package/src/rules/implementations/connection-type-references.ts +117 -0
- package/src/rules/implementations/dead-end-states.ts +101 -0
- package/src/rules/implementations/index.ts +73 -0
- package/src/rules/implementations/library-node-type-match.ts +148 -0
- package/src/rules/implementations/minimum-node-sources.ts +82 -0
- package/src/rules/implementations/no-unknown-fields.ts +342 -0
- package/src/rules/implementations/orphaned-edge-types.ts +55 -0
- package/src/rules/implementations/orphaned-node-types.ts +58 -0
- package/src/rules/implementations/required-metadata.ts +64 -0
- package/src/rules/implementations/state-transition-references.ts +151 -0
- package/src/rules/implementations/unreachable-states.ts +94 -0
- package/src/rules/implementations/valid-action-patterns.ts +136 -0
- package/src/rules/implementations/valid-color-format.ts +140 -0
- package/src/rules/implementations/valid-edge-types.ts +258 -0
- package/src/rules/implementations/valid-node-types.ts +189 -0
- package/src/rules/index.ts +95 -0
- package/src/rules/types.ts +426 -0
- package/src/types/canvas.ts +496 -0
- package/src/types/index.ts +382 -0
- package/src/types/library.ts +233 -0
- package/src/types/path-based-config.ts +281 -0
- package/src/utils/CanvasConverter.ts +431 -0
- package/src/utils/GraphConverter.test.ts +195 -0
- package/src/utils/GraphConverter.ts +71 -0
- package/src/utils/LibraryConverter.ts +245 -0
- package/src/utils/PathMatcher.test.ts +148 -0
- package/src/utils/PathMatcher.ts +183 -0
- package/src/utils/YamlParser.ts +75 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Library Loader
|
|
3
|
+
*
|
|
4
|
+
* Loads component library files (.yaml, .yml, or .json) from the .vgc/ folder.
|
|
5
|
+
* Component libraries contain reusable node and edge type definitions.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { FileSystemAdapter } from '@principal-ai/repository-abstraction';
|
|
9
|
+
import type { ComponentLibrary, LibraryLoadResult } from './types/library';
|
|
10
|
+
import * as yaml from 'js-yaml';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Default library file names to search for (in order of preference)
|
|
14
|
+
*/
|
|
15
|
+
const DEFAULT_LIBRARY_FILES = ['library.yaml', 'library.yml', 'library.json'];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Configuration directory name
|
|
19
|
+
*/
|
|
20
|
+
const CONFIG_DIR = '.vgc';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Loader for component library files
|
|
24
|
+
*/
|
|
25
|
+
export class LibraryLoader {
|
|
26
|
+
constructor(private fsAdapter: FileSystemAdapter) {}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Load the component library from the .vgc/ folder
|
|
30
|
+
*
|
|
31
|
+
* Searches for library.yaml, library.yml, or library.json (in that order).
|
|
32
|
+
*
|
|
33
|
+
* @param baseDir - Base directory containing .vgc/ folder
|
|
34
|
+
* @returns Library load result
|
|
35
|
+
*/
|
|
36
|
+
load(baseDir: string): LibraryLoadResult {
|
|
37
|
+
const configPath = this.fsAdapter.join(baseDir, CONFIG_DIR);
|
|
38
|
+
|
|
39
|
+
// Check if .vgc directory exists
|
|
40
|
+
if (!this.fsAdapter.exists(configPath) || !this.fsAdapter.isDirectory(configPath)) {
|
|
41
|
+
return {
|
|
42
|
+
success: false,
|
|
43
|
+
error: 'Configuration directory .vgc/ not found',
|
|
44
|
+
path: configPath,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Try each default library file name
|
|
49
|
+
for (const fileName of DEFAULT_LIBRARY_FILES) {
|
|
50
|
+
const fullPath = this.fsAdapter.join(configPath, fileName);
|
|
51
|
+
|
|
52
|
+
if (this.fsAdapter.exists(fullPath)) {
|
|
53
|
+
return this.loadFromPath(fullPath);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
success: false,
|
|
59
|
+
error: `No library file found. Expected one of: ${DEFAULT_LIBRARY_FILES.join(', ')}`,
|
|
60
|
+
path: configPath,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Load a library from a specific file path
|
|
66
|
+
*
|
|
67
|
+
* @param filePath - Full path to the library file
|
|
68
|
+
* @returns Library load result
|
|
69
|
+
*/
|
|
70
|
+
loadFromPath(filePath: string): LibraryLoadResult {
|
|
71
|
+
try {
|
|
72
|
+
const content = this.fsAdapter.readFile(filePath);
|
|
73
|
+
const isJson = filePath.endsWith('.json');
|
|
74
|
+
|
|
75
|
+
const library = isJson ? this.parseJson(content, filePath) : this.parseYaml(content, filePath);
|
|
76
|
+
|
|
77
|
+
const validationError = this.validate(library, filePath);
|
|
78
|
+
if (validationError) {
|
|
79
|
+
return {
|
|
80
|
+
success: false,
|
|
81
|
+
error: validationError,
|
|
82
|
+
path: filePath,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
success: true,
|
|
88
|
+
library,
|
|
89
|
+
path: filePath,
|
|
90
|
+
};
|
|
91
|
+
} catch (error) {
|
|
92
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
93
|
+
return {
|
|
94
|
+
success: false,
|
|
95
|
+
error: `Failed to load library: ${errorMessage}`,
|
|
96
|
+
path: filePath,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Check if a library file exists in the .vgc/ folder
|
|
103
|
+
*
|
|
104
|
+
* @param baseDir - Base directory containing .vgc/ folder
|
|
105
|
+
* @returns True if a library file exists
|
|
106
|
+
*/
|
|
107
|
+
hasLibrary(baseDir: string): boolean {
|
|
108
|
+
const configPath = this.fsAdapter.join(baseDir, CONFIG_DIR);
|
|
109
|
+
|
|
110
|
+
if (!this.fsAdapter.exists(configPath) || !this.fsAdapter.isDirectory(configPath)) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return DEFAULT_LIBRARY_FILES.some((fileName) => this.fsAdapter.exists(this.fsAdapter.join(configPath, fileName)));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Get the path where the library file would be located
|
|
119
|
+
*
|
|
120
|
+
* @param baseDir - Base directory
|
|
121
|
+
* @param format - Preferred format ('yaml' or 'json')
|
|
122
|
+
* @returns Full path to the library file
|
|
123
|
+
*/
|
|
124
|
+
getLibraryPath(baseDir: string, format: 'yaml' | 'json' = 'yaml'): string {
|
|
125
|
+
const fileName = format === 'json' ? 'library.json' : 'library.yaml';
|
|
126
|
+
return this.fsAdapter.join(baseDir, CONFIG_DIR, fileName);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Parse YAML content into a library object
|
|
131
|
+
*/
|
|
132
|
+
private parseYaml(content: string, filePath: string): ComponentLibrary {
|
|
133
|
+
const data = yaml.load(content);
|
|
134
|
+
|
|
135
|
+
if (!data || typeof data !== 'object') {
|
|
136
|
+
throw new Error(`Empty or invalid YAML in ${filePath}`);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return data as ComponentLibrary;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Parse JSON content into a library object
|
|
144
|
+
*/
|
|
145
|
+
private parseJson(content: string, filePath: string): ComponentLibrary {
|
|
146
|
+
try {
|
|
147
|
+
const data = JSON.parse(content);
|
|
148
|
+
return data as ComponentLibrary;
|
|
149
|
+
} catch (error) {
|
|
150
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
151
|
+
throw new Error(`Invalid JSON in ${filePath}: ${errorMessage}`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Validate the library structure
|
|
157
|
+
*
|
|
158
|
+
* @param library - Parsed library object
|
|
159
|
+
* @param filePath - File path for error messages
|
|
160
|
+
* @returns Error message if invalid, undefined if valid
|
|
161
|
+
*/
|
|
162
|
+
private validate(library: ComponentLibrary, filePath: string): string | undefined {
|
|
163
|
+
if (!library.version) {
|
|
164
|
+
return `Missing required field 'version' in ${filePath}`;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (!library.name) {
|
|
168
|
+
return `Missing required field 'name' in ${filePath}`;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (!library.nodeComponents || typeof library.nodeComponents !== 'object') {
|
|
172
|
+
return `Missing or invalid 'nodeComponents' in ${filePath}`;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (!library.edgeComponents || typeof library.edgeComponents !== 'object') {
|
|
176
|
+
return `Missing or invalid 'edgeComponents' in ${filePath}`;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Validate node components
|
|
180
|
+
for (const [key, node] of Object.entries(library.nodeComponents)) {
|
|
181
|
+
if (!node.shape) {
|
|
182
|
+
return `Node component '${key}' is missing required field 'shape' in ${filePath}`;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Validate edge components
|
|
187
|
+
for (const [key, edge] of Object.entries(library.edgeComponents)) {
|
|
188
|
+
if (!edge.style) {
|
|
189
|
+
return `Edge component '${key}' is missing required field 'style' in ${filePath}`;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Validate connection rules if present
|
|
194
|
+
if (library.connectionRules) {
|
|
195
|
+
for (const [index, rule] of library.connectionRules.entries()) {
|
|
196
|
+
if (!rule.from || !rule.to || !rule.via) {
|
|
197
|
+
return `Connection rule at index ${index} is missing required fields (from, to, via) in ${filePath}`;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Check that referenced types exist
|
|
201
|
+
if (!library.nodeComponents[rule.from]) {
|
|
202
|
+
return `Connection rule references unknown node type '${rule.from}' in ${filePath}`;
|
|
203
|
+
}
|
|
204
|
+
if (!library.nodeComponents[rule.to]) {
|
|
205
|
+
return `Connection rule references unknown node type '${rule.to}' in ${filePath}`;
|
|
206
|
+
}
|
|
207
|
+
if (!library.edgeComponents[rule.via]) {
|
|
208
|
+
return `Connection rule references unknown edge type '${rule.via}' in ${filePath}`;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return undefined;
|
|
214
|
+
}
|
|
215
|
+
}
|