@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.
Files changed (204) hide show
  1. package/README.md +126 -0
  2. package/dist/ConfigurationLoader.d.ts +76 -0
  3. package/dist/ConfigurationLoader.d.ts.map +1 -0
  4. package/dist/ConfigurationLoader.js +144 -0
  5. package/dist/ConfigurationLoader.js.map +1 -0
  6. package/dist/ConfigurationValidator.d.ts +31 -0
  7. package/dist/ConfigurationValidator.d.ts.map +1 -0
  8. package/dist/ConfigurationValidator.js +242 -0
  9. package/dist/ConfigurationValidator.js.map +1 -0
  10. package/dist/EventProcessor.d.ts +49 -0
  11. package/dist/EventProcessor.d.ts.map +1 -0
  12. package/dist/EventProcessor.js +215 -0
  13. package/dist/EventProcessor.js.map +1 -0
  14. package/dist/EventRecorderService.d.ts +305 -0
  15. package/dist/EventRecorderService.d.ts.map +1 -0
  16. package/dist/EventRecorderService.js +463 -0
  17. package/dist/EventRecorderService.js.map +1 -0
  18. package/dist/LibraryLoader.d.ts +63 -0
  19. package/dist/LibraryLoader.d.ts.map +1 -0
  20. package/dist/LibraryLoader.js +188 -0
  21. package/dist/LibraryLoader.js.map +1 -0
  22. package/dist/PathBasedEventProcessor.d.ts +90 -0
  23. package/dist/PathBasedEventProcessor.d.ts.map +1 -0
  24. package/dist/PathBasedEventProcessor.js +239 -0
  25. package/dist/PathBasedEventProcessor.js.map +1 -0
  26. package/dist/SessionManager.d.ts +194 -0
  27. package/dist/SessionManager.d.ts.map +1 -0
  28. package/dist/SessionManager.js +299 -0
  29. package/dist/SessionManager.js.map +1 -0
  30. package/dist/ValidationEngine.d.ts +31 -0
  31. package/dist/ValidationEngine.d.ts.map +1 -0
  32. package/dist/ValidationEngine.js +158 -0
  33. package/dist/ValidationEngine.js.map +1 -0
  34. package/dist/helpers/GraphInstrumentationHelper.d.ts +93 -0
  35. package/dist/helpers/GraphInstrumentationHelper.d.ts.map +1 -0
  36. package/dist/helpers/GraphInstrumentationHelper.js +248 -0
  37. package/dist/helpers/GraphInstrumentationHelper.js.map +1 -0
  38. package/dist/index.d.ts +33 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +34 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/rules/config.d.ts +57 -0
  43. package/dist/rules/config.d.ts.map +1 -0
  44. package/dist/rules/config.js +382 -0
  45. package/dist/rules/config.js.map +1 -0
  46. package/dist/rules/engine.d.ts +70 -0
  47. package/dist/rules/engine.d.ts.map +1 -0
  48. package/dist/rules/engine.js +252 -0
  49. package/dist/rules/engine.js.map +1 -0
  50. package/dist/rules/implementations/connection-type-references.d.ts +7 -0
  51. package/dist/rules/implementations/connection-type-references.d.ts.map +1 -0
  52. package/dist/rules/implementations/connection-type-references.js +104 -0
  53. package/dist/rules/implementations/connection-type-references.js.map +1 -0
  54. package/dist/rules/implementations/dead-end-states.d.ts +17 -0
  55. package/dist/rules/implementations/dead-end-states.d.ts.map +1 -0
  56. package/dist/rules/implementations/dead-end-states.js +72 -0
  57. package/dist/rules/implementations/dead-end-states.js.map +1 -0
  58. package/dist/rules/implementations/index.d.ts +24 -0
  59. package/dist/rules/implementations/index.d.ts.map +1 -0
  60. package/dist/rules/implementations/index.js +62 -0
  61. package/dist/rules/implementations/index.js.map +1 -0
  62. package/dist/rules/implementations/library-node-type-match.d.ts +17 -0
  63. package/dist/rules/implementations/library-node-type-match.d.ts.map +1 -0
  64. package/dist/rules/implementations/library-node-type-match.js +123 -0
  65. package/dist/rules/implementations/library-node-type-match.js.map +1 -0
  66. package/dist/rules/implementations/minimum-node-sources.d.ts +22 -0
  67. package/dist/rules/implementations/minimum-node-sources.d.ts.map +1 -0
  68. package/dist/rules/implementations/minimum-node-sources.js +54 -0
  69. package/dist/rules/implementations/minimum-node-sources.js.map +1 -0
  70. package/dist/rules/implementations/no-unknown-fields.d.ts +7 -0
  71. package/dist/rules/implementations/no-unknown-fields.d.ts.map +1 -0
  72. package/dist/rules/implementations/no-unknown-fields.js +211 -0
  73. package/dist/rules/implementations/no-unknown-fields.js.map +1 -0
  74. package/dist/rules/implementations/orphaned-edge-types.d.ts +7 -0
  75. package/dist/rules/implementations/orphaned-edge-types.d.ts.map +1 -0
  76. package/dist/rules/implementations/orphaned-edge-types.js +47 -0
  77. package/dist/rules/implementations/orphaned-edge-types.js.map +1 -0
  78. package/dist/rules/implementations/orphaned-node-types.d.ts +7 -0
  79. package/dist/rules/implementations/orphaned-node-types.d.ts.map +1 -0
  80. package/dist/rules/implementations/orphaned-node-types.js +50 -0
  81. package/dist/rules/implementations/orphaned-node-types.js.map +1 -0
  82. package/dist/rules/implementations/required-metadata.d.ts +7 -0
  83. package/dist/rules/implementations/required-metadata.d.ts.map +1 -0
  84. package/dist/rules/implementations/required-metadata.js +57 -0
  85. package/dist/rules/implementations/required-metadata.js.map +1 -0
  86. package/dist/rules/implementations/state-transition-references.d.ts +7 -0
  87. package/dist/rules/implementations/state-transition-references.d.ts.map +1 -0
  88. package/dist/rules/implementations/state-transition-references.js +135 -0
  89. package/dist/rules/implementations/state-transition-references.js.map +1 -0
  90. package/dist/rules/implementations/unreachable-states.d.ts +7 -0
  91. package/dist/rules/implementations/unreachable-states.d.ts.map +1 -0
  92. package/dist/rules/implementations/unreachable-states.js +80 -0
  93. package/dist/rules/implementations/unreachable-states.js.map +1 -0
  94. package/dist/rules/implementations/valid-action-patterns.d.ts +17 -0
  95. package/dist/rules/implementations/valid-action-patterns.d.ts.map +1 -0
  96. package/dist/rules/implementations/valid-action-patterns.js +109 -0
  97. package/dist/rules/implementations/valid-action-patterns.js.map +1 -0
  98. package/dist/rules/implementations/valid-color-format.d.ts +7 -0
  99. package/dist/rules/implementations/valid-color-format.d.ts.map +1 -0
  100. package/dist/rules/implementations/valid-color-format.js +91 -0
  101. package/dist/rules/implementations/valid-color-format.js.map +1 -0
  102. package/dist/rules/implementations/valid-edge-types.d.ts +7 -0
  103. package/dist/rules/implementations/valid-edge-types.d.ts.map +1 -0
  104. package/dist/rules/implementations/valid-edge-types.js +244 -0
  105. package/dist/rules/implementations/valid-edge-types.js.map +1 -0
  106. package/dist/rules/implementations/valid-node-types.d.ts +7 -0
  107. package/dist/rules/implementations/valid-node-types.d.ts.map +1 -0
  108. package/dist/rules/implementations/valid-node-types.js +175 -0
  109. package/dist/rules/implementations/valid-node-types.js.map +1 -0
  110. package/dist/rules/index.d.ts +28 -0
  111. package/dist/rules/index.d.ts.map +1 -0
  112. package/dist/rules/index.js +45 -0
  113. package/dist/rules/index.js.map +1 -0
  114. package/dist/rules/types.d.ts +309 -0
  115. package/dist/rules/types.d.ts.map +1 -0
  116. package/dist/rules/types.js +35 -0
  117. package/dist/rules/types.js.map +1 -0
  118. package/dist/types/canvas.d.ts +409 -0
  119. package/dist/types/canvas.d.ts.map +1 -0
  120. package/dist/types/canvas.js +70 -0
  121. package/dist/types/canvas.js.map +1 -0
  122. package/dist/types/index.d.ts +311 -0
  123. package/dist/types/index.d.ts.map +1 -0
  124. package/dist/types/index.js +13 -0
  125. package/dist/types/index.js.map +1 -0
  126. package/dist/types/library.d.ts +185 -0
  127. package/dist/types/library.d.ts.map +1 -0
  128. package/dist/types/library.js +15 -0
  129. package/dist/types/library.js.map +1 -0
  130. package/dist/types/path-based-config.d.ts +230 -0
  131. package/dist/types/path-based-config.d.ts.map +1 -0
  132. package/dist/types/path-based-config.js +9 -0
  133. package/dist/types/path-based-config.js.map +1 -0
  134. package/dist/utils/CanvasConverter.d.ts +118 -0
  135. package/dist/utils/CanvasConverter.d.ts.map +1 -0
  136. package/dist/utils/CanvasConverter.js +315 -0
  137. package/dist/utils/CanvasConverter.js.map +1 -0
  138. package/dist/utils/GraphConverter.d.ts +18 -0
  139. package/dist/utils/GraphConverter.d.ts.map +1 -0
  140. package/dist/utils/GraphConverter.js +61 -0
  141. package/dist/utils/GraphConverter.js.map +1 -0
  142. package/dist/utils/LibraryConverter.d.ts +113 -0
  143. package/dist/utils/LibraryConverter.d.ts.map +1 -0
  144. package/dist/utils/LibraryConverter.js +166 -0
  145. package/dist/utils/LibraryConverter.js.map +1 -0
  146. package/dist/utils/PathMatcher.d.ts +55 -0
  147. package/dist/utils/PathMatcher.d.ts.map +1 -0
  148. package/dist/utils/PathMatcher.js +172 -0
  149. package/dist/utils/PathMatcher.js.map +1 -0
  150. package/dist/utils/YamlParser.d.ts +36 -0
  151. package/dist/utils/YamlParser.d.ts.map +1 -0
  152. package/dist/utils/YamlParser.js +63 -0
  153. package/dist/utils/YamlParser.js.map +1 -0
  154. package/package.json +47 -0
  155. package/src/ConfigurationLoader.test.ts +490 -0
  156. package/src/ConfigurationLoader.ts +185 -0
  157. package/src/ConfigurationValidator.test.ts +200 -0
  158. package/src/ConfigurationValidator.ts +283 -0
  159. package/src/EventProcessor.test.ts +405 -0
  160. package/src/EventProcessor.ts +250 -0
  161. package/src/EventRecorderService.test.ts +541 -0
  162. package/src/EventRecorderService.ts +744 -0
  163. package/src/LibraryLoader.ts +215 -0
  164. package/src/PathBasedEventProcessor.test.ts +567 -0
  165. package/src/PathBasedEventProcessor.ts +332 -0
  166. package/src/SessionManager.test.ts +424 -0
  167. package/src/SessionManager.ts +470 -0
  168. package/src/ValidationEngine.test.ts +371 -0
  169. package/src/ValidationEngine.ts +196 -0
  170. package/src/helpers/GraphInstrumentationHelper.test.ts +340 -0
  171. package/src/helpers/GraphInstrumentationHelper.ts +326 -0
  172. package/src/index.ts +85 -0
  173. package/src/rules/config.test.ts +278 -0
  174. package/src/rules/config.ts +459 -0
  175. package/src/rules/engine.test.ts +332 -0
  176. package/src/rules/engine.ts +318 -0
  177. package/src/rules/implementations/connection-type-references.ts +117 -0
  178. package/src/rules/implementations/dead-end-states.ts +101 -0
  179. package/src/rules/implementations/index.ts +73 -0
  180. package/src/rules/implementations/library-node-type-match.ts +148 -0
  181. package/src/rules/implementations/minimum-node-sources.ts +82 -0
  182. package/src/rules/implementations/no-unknown-fields.ts +342 -0
  183. package/src/rules/implementations/orphaned-edge-types.ts +55 -0
  184. package/src/rules/implementations/orphaned-node-types.ts +58 -0
  185. package/src/rules/implementations/required-metadata.ts +64 -0
  186. package/src/rules/implementations/state-transition-references.ts +151 -0
  187. package/src/rules/implementations/unreachable-states.ts +94 -0
  188. package/src/rules/implementations/valid-action-patterns.ts +136 -0
  189. package/src/rules/implementations/valid-color-format.ts +140 -0
  190. package/src/rules/implementations/valid-edge-types.ts +258 -0
  191. package/src/rules/implementations/valid-node-types.ts +189 -0
  192. package/src/rules/index.ts +95 -0
  193. package/src/rules/types.ts +426 -0
  194. package/src/types/canvas.ts +496 -0
  195. package/src/types/index.ts +382 -0
  196. package/src/types/library.ts +233 -0
  197. package/src/types/path-based-config.ts +281 -0
  198. package/src/utils/CanvasConverter.ts +431 -0
  199. package/src/utils/GraphConverter.test.ts +195 -0
  200. package/src/utils/GraphConverter.ts +71 -0
  201. package/src/utils/LibraryConverter.ts +245 -0
  202. package/src/utils/PathMatcher.test.ts +148 -0
  203. package/src/utils/PathMatcher.ts +183 -0
  204. package/src/utils/YamlParser.ts +75 -0
@@ -0,0 +1,183 @@
1
+ /**
2
+ * Utility for matching file paths against glob patterns
3
+ * Used for associating logs with components based on source paths
4
+ */
5
+
6
+ export class PathMatcher {
7
+ /**
8
+ * Check if a file path matches a glob pattern
9
+ *
10
+ * Supports:
11
+ * - Exact matches: "lib/lock-manager.ts"
12
+ * - Wildcards: "lib/*.ts"
13
+ * - Double wildcards: "lib/**​/*.ts"
14
+ * - Character sets: "lib/[abc].ts"
15
+ *
16
+ * @param path File path to test
17
+ * @param pattern Glob pattern
18
+ * @returns True if path matches pattern
19
+ */
20
+ public static matches(path: string, pattern: string): boolean {
21
+ // Normalize paths (convert backslashes to forward slashes)
22
+ path = path.replace(/\\/g, '/');
23
+ pattern = pattern.replace(/\\/g, '/');
24
+
25
+ // Exact match
26
+ if (path === pattern) {
27
+ return true;
28
+ }
29
+
30
+ // Convert glob pattern to regex
31
+ const regex = this.globToRegex(pattern);
32
+ return regex.test(path);
33
+ }
34
+
35
+ /**
36
+ * Find all patterns that match a given path
37
+ *
38
+ * @param path File path to test
39
+ * @param patterns Array of glob patterns
40
+ * @returns Array of matching patterns
41
+ */
42
+ public static findMatches(path: string, patterns: string[]): string[] {
43
+ return patterns.filter(pattern => this.matches(path, pattern));
44
+ }
45
+
46
+ /**
47
+ * Convert a glob pattern to a regular expression
48
+ *
49
+ * @param pattern Glob pattern
50
+ * @returns Regular expression
51
+ */
52
+ private static globToRegex(pattern: string): RegExp {
53
+ const regex = this.globToRegexString(pattern);
54
+ // Match entire string
55
+ return new RegExp('^' + regex + '$');
56
+ }
57
+
58
+ /**
59
+ * Convert a glob pattern to a regex string (without anchors)
60
+ * This allows for proper composition when handling alternatives
61
+ */
62
+ private static globToRegexString(pattern: string): string {
63
+ let regex = '';
64
+ let i = 0;
65
+
66
+ while (i < pattern.length) {
67
+ const char = pattern[i];
68
+
69
+ switch (char) {
70
+ case '*':
71
+ // Check for **
72
+ if (pattern[i + 1] === '*') {
73
+ // ** matches any number of directories
74
+ if (pattern[i + 2] === '/') {
75
+ regex += '(?:.*/)?'; // Match zero or more path segments
76
+ i += 3;
77
+ } else {
78
+ // ** at end of pattern
79
+ regex += '.*';
80
+ i += 2;
81
+ }
82
+ } else {
83
+ // * matches anything except /
84
+ regex += '[^/]*';
85
+ i++;
86
+ }
87
+ break;
88
+
89
+ case '?':
90
+ // ? matches any single character except /
91
+ regex += '[^/]';
92
+ i++;
93
+ break;
94
+
95
+ case '[':
96
+ // [...] matches character set
97
+ let j = i + 1;
98
+ while (j < pattern.length && pattern[j] !== ']') {
99
+ j++;
100
+ }
101
+ if (j < pattern.length) {
102
+ const set = pattern.substring(i + 1, j);
103
+ regex += '[' + set.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + ']';
104
+ i = j + 1;
105
+ } else {
106
+ regex += '\\[';
107
+ i++;
108
+ }
109
+ break;
110
+
111
+ case '{':
112
+ // {a,b,c} matches alternatives
113
+ let k = i + 1;
114
+ let depth = 1;
115
+ while (k < pattern.length && depth > 0) {
116
+ if (pattern[k] === '{') depth++;
117
+ if (pattern[k] === '}') depth--;
118
+ k++;
119
+ }
120
+ if (depth === 0) {
121
+ const alternatives = pattern.substring(i + 1, k - 1).split(',');
122
+ regex += '(?:' + alternatives.map(alt => this.globToRegexString(alt)).join('|') + ')';
123
+ i = k;
124
+ } else {
125
+ regex += '\\{';
126
+ i++;
127
+ }
128
+ break;
129
+
130
+ // Escape special regex characters
131
+ case '.':
132
+ case '+':
133
+ case '^':
134
+ case '$':
135
+ case '(':
136
+ case ')':
137
+ case '|':
138
+ case '\\':
139
+ regex += '\\' + char;
140
+ i++;
141
+ break;
142
+
143
+ default:
144
+ regex += char;
145
+ i++;
146
+ }
147
+ }
148
+
149
+ return regex;
150
+ }
151
+
152
+ /**
153
+ * Escape special regex characters in a string
154
+ */
155
+ private static escapeRegex(str: string): string {
156
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
157
+ }
158
+
159
+ /**
160
+ * Check if a pattern might match multiple paths (contains wildcards)
161
+ */
162
+ public static isGlob(pattern: string): boolean {
163
+ return /[*?[\]{]/.test(pattern);
164
+ }
165
+
166
+ /**
167
+ * Get the base directory from a glob pattern (part before first wildcard)
168
+ *
169
+ * Example: "lib/services/**​/*.ts" → "lib/services"
170
+ */
171
+ public static getBaseDir(pattern: string): string {
172
+ const firstWildcard = pattern.search(/[*?[\]{]/);
173
+ if (firstWildcard === -1) {
174
+ // No wildcards, return the directory part
175
+ return pattern.substring(0, pattern.lastIndexOf('/'));
176
+ }
177
+
178
+ // Return part before first wildcard
179
+ const beforeWildcard = pattern.substring(0, firstWildcard);
180
+ const lastSlash = beforeWildcard.lastIndexOf('/');
181
+ return lastSlash === -1 ? '' : beforeWildcard.substring(0, lastSlash);
182
+ }
183
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * YAML parsing utility for loading configuration files
3
+ *
4
+ * Provides error handling and validation for YAML configuration files.
5
+ * Supports both .yaml and .yml file extensions.
6
+ */
7
+
8
+ import * as yaml from 'js-yaml';
9
+ import { PathBasedGraphConfiguration } from '../types/path-based-config';
10
+
11
+ export interface YamlParseResult {
12
+ success: boolean;
13
+ data?: PathBasedGraphConfiguration;
14
+ error?: string;
15
+ }
16
+
17
+ /**
18
+ * Parse YAML content into a configuration object
19
+ *
20
+ * @param content - Raw YAML string content
21
+ * @param filename - Optional filename for error messages
22
+ * @returns Parse result with configuration or error
23
+ */
24
+ export function parseYaml(content: string, filename?: string): YamlParseResult {
25
+ try {
26
+ const data = yaml.load(content) as PathBasedGraphConfiguration;
27
+
28
+ if (!data) {
29
+ return {
30
+ success: false,
31
+ error: `Empty YAML file${filename ? `: ${filename}` : ''}`,
32
+ };
33
+ }
34
+
35
+ // Basic validation - ensure it has the required structure
36
+ if (!data.metadata || !data.nodeTypes || !data.edgeTypes) {
37
+ return {
38
+ success: false,
39
+ error: `Invalid configuration structure${filename ? ` in ${filename}` : ''}: missing required fields (metadata, nodeTypes, or edgeTypes)`,
40
+ };
41
+ }
42
+
43
+ return {
44
+ success: true,
45
+ data,
46
+ };
47
+ } catch (error) {
48
+ const errorMessage = error instanceof Error ? error.message : String(error);
49
+ return {
50
+ success: false,
51
+ error: `YAML parse error${filename ? ` in ${filename}` : ''}: ${errorMessage}`,
52
+ };
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Check if a filename has a valid YAML extension
58
+ *
59
+ * @param filename - Filename to check
60
+ * @returns True if filename ends with .yaml or .yml
61
+ */
62
+ export function isYamlFile(filename: string): boolean {
63
+ return filename.endsWith('.yaml') || filename.endsWith('.yml');
64
+ }
65
+
66
+ /**
67
+ * Extract configuration name from filename
68
+ * Removes the .yaml or .yml extension
69
+ *
70
+ * @param filename - Filename to process
71
+ * @returns Configuration name without extension
72
+ */
73
+ export function getConfigNameFromFilename(filename: string): string {
74
+ return filename.replace(/\.(yaml|yml)$/, '');
75
+ }