@grafema/util 0.3.0-beta

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 (324) hide show
  1. package/LICENSE +190 -0
  2. package/dist/api/GraphAPI.d.ts +87 -0
  3. package/dist/api/GraphAPI.d.ts.map +1 -0
  4. package/dist/api/GraphAPI.js +212 -0
  5. package/dist/api/GraphAPI.js.map +1 -0
  6. package/dist/api/GuaranteeAPI.d.ts +147 -0
  7. package/dist/api/GuaranteeAPI.d.ts.map +1 -0
  8. package/dist/api/GuaranteeAPI.js +290 -0
  9. package/dist/api/GuaranteeAPI.js.map +1 -0
  10. package/dist/config/ConfigLoader.d.ts +214 -0
  11. package/dist/config/ConfigLoader.d.ts.map +1 -0
  12. package/dist/config/ConfigLoader.js +441 -0
  13. package/dist/config/ConfigLoader.js.map +1 -0
  14. package/dist/config/index.d.ts +6 -0
  15. package/dist/config/index.d.ts.map +1 -0
  16. package/dist/config/index.js +5 -0
  17. package/dist/config/index.js.map +1 -0
  18. package/dist/core/CoverageAnalyzer.d.ts +65 -0
  19. package/dist/core/CoverageAnalyzer.d.ts.map +1 -0
  20. package/dist/core/CoverageAnalyzer.js +199 -0
  21. package/dist/core/CoverageAnalyzer.js.map +1 -0
  22. package/dist/core/FileExplainer.d.ts +101 -0
  23. package/dist/core/FileExplainer.d.ts.map +1 -0
  24. package/dist/core/FileExplainer.js +140 -0
  25. package/dist/core/FileExplainer.js.map +1 -0
  26. package/dist/core/FileOverview.d.ts +124 -0
  27. package/dist/core/FileOverview.d.ts.map +1 -0
  28. package/dist/core/FileOverview.js +279 -0
  29. package/dist/core/FileOverview.js.map +1 -0
  30. package/dist/core/GrafemaUri.d.ts +66 -0
  31. package/dist/core/GrafemaUri.d.ts.map +1 -0
  32. package/dist/core/GrafemaUri.js +191 -0
  33. package/dist/core/GrafemaUri.js.map +1 -0
  34. package/dist/core/GraphBackend.d.ts +158 -0
  35. package/dist/core/GraphBackend.d.ts.map +1 -0
  36. package/dist/core/GraphBackend.js +85 -0
  37. package/dist/core/GraphBackend.js.map +1 -0
  38. package/dist/core/GraphFreshnessChecker.d.ts +33 -0
  39. package/dist/core/GraphFreshnessChecker.d.ts.map +1 -0
  40. package/dist/core/GraphFreshnessChecker.js +104 -0
  41. package/dist/core/GraphFreshnessChecker.js.map +1 -0
  42. package/dist/core/GuaranteeManager.d.ts +254 -0
  43. package/dist/core/GuaranteeManager.d.ts.map +1 -0
  44. package/dist/core/GuaranteeManager.js +447 -0
  45. package/dist/core/GuaranteeManager.js.map +1 -0
  46. package/dist/core/HashUtils.d.ts +24 -0
  47. package/dist/core/HashUtils.d.ts.map +1 -0
  48. package/dist/core/HashUtils.js +46 -0
  49. package/dist/core/HashUtils.js.map +1 -0
  50. package/dist/core/IncrementalReanalyzer.d.ts +33 -0
  51. package/dist/core/IncrementalReanalyzer.d.ts.map +1 -0
  52. package/dist/core/IncrementalReanalyzer.js +67 -0
  53. package/dist/core/IncrementalReanalyzer.js.map +1 -0
  54. package/dist/core/ResourceRegistry.d.ts +17 -0
  55. package/dist/core/ResourceRegistry.d.ts.map +1 -0
  56. package/dist/core/ResourceRegistry.js +32 -0
  57. package/dist/core/ResourceRegistry.js.map +1 -0
  58. package/dist/core/SemanticId.d.ts +159 -0
  59. package/dist/core/SemanticId.d.ts.map +1 -0
  60. package/dist/core/SemanticId.js +291 -0
  61. package/dist/core/SemanticId.js.map +1 -0
  62. package/dist/core/VersionManager.d.ts +166 -0
  63. package/dist/core/VersionManager.d.ts.map +1 -0
  64. package/dist/core/VersionManager.js +239 -0
  65. package/dist/core/VersionManager.js.map +1 -0
  66. package/dist/core/brandNodeInternal.d.ts +14 -0
  67. package/dist/core/brandNodeInternal.d.ts.map +1 -0
  68. package/dist/core/brandNodeInternal.js +4 -0
  69. package/dist/core/brandNodeInternal.js.map +1 -0
  70. package/dist/core/nodes/GuaranteeNode.d.ts +76 -0
  71. package/dist/core/nodes/GuaranteeNode.d.ts.map +1 -0
  72. package/dist/core/nodes/GuaranteeNode.js +118 -0
  73. package/dist/core/nodes/GuaranteeNode.js.map +1 -0
  74. package/dist/core/nodes/IssueNode.d.ts +73 -0
  75. package/dist/core/nodes/IssueNode.d.ts.map +1 -0
  76. package/dist/core/nodes/IssueNode.js +130 -0
  77. package/dist/core/nodes/IssueNode.js.map +1 -0
  78. package/dist/core/nodes/NodeKind.d.ts +104 -0
  79. package/dist/core/nodes/NodeKind.d.ts.map +1 -0
  80. package/dist/core/nodes/NodeKind.js +166 -0
  81. package/dist/core/nodes/NodeKind.js.map +1 -0
  82. package/dist/diagnostics/DiagnosticCollector.d.ts +103 -0
  83. package/dist/diagnostics/DiagnosticCollector.d.ts.map +1 -0
  84. package/dist/diagnostics/DiagnosticCollector.js +133 -0
  85. package/dist/diagnostics/DiagnosticCollector.js.map +1 -0
  86. package/dist/diagnostics/DiagnosticReporter.d.ts +122 -0
  87. package/dist/diagnostics/DiagnosticReporter.d.ts.map +1 -0
  88. package/dist/diagnostics/DiagnosticReporter.js +300 -0
  89. package/dist/diagnostics/DiagnosticReporter.js.map +1 -0
  90. package/dist/diagnostics/DiagnosticWriter.d.ts +31 -0
  91. package/dist/diagnostics/DiagnosticWriter.d.ts.map +1 -0
  92. package/dist/diagnostics/DiagnosticWriter.js +44 -0
  93. package/dist/diagnostics/DiagnosticWriter.js.map +1 -0
  94. package/dist/diagnostics/categories.d.ts +57 -0
  95. package/dist/diagnostics/categories.d.ts.map +1 -0
  96. package/dist/diagnostics/categories.js +71 -0
  97. package/dist/diagnostics/categories.js.map +1 -0
  98. package/dist/diagnostics/index.d.ts +17 -0
  99. package/dist/diagnostics/index.d.ts.map +1 -0
  100. package/dist/diagnostics/index.js +15 -0
  101. package/dist/diagnostics/index.js.map +1 -0
  102. package/dist/errors/GrafemaError.d.ts +200 -0
  103. package/dist/errors/GrafemaError.d.ts.map +1 -0
  104. package/dist/errors/GrafemaError.js +209 -0
  105. package/dist/errors/GrafemaError.js.map +1 -0
  106. package/dist/index.d.ts +75 -0
  107. package/dist/index.d.ts.map +1 -0
  108. package/dist/index.js +76 -0
  109. package/dist/index.js.map +1 -0
  110. package/dist/instructions/index.d.ts +8 -0
  111. package/dist/instructions/index.d.ts.map +1 -0
  112. package/dist/instructions/index.js +20 -0
  113. package/dist/instructions/index.js.map +1 -0
  114. package/dist/instructions/onboarding.md +133 -0
  115. package/dist/knowledge/KnowledgeBase.d.ts +113 -0
  116. package/dist/knowledge/KnowledgeBase.d.ts.map +1 -0
  117. package/dist/knowledge/KnowledgeBase.js +420 -0
  118. package/dist/knowledge/KnowledgeBase.js.map +1 -0
  119. package/dist/knowledge/SemanticAddressResolver.d.ts +59 -0
  120. package/dist/knowledge/SemanticAddressResolver.d.ts.map +1 -0
  121. package/dist/knowledge/SemanticAddressResolver.js +160 -0
  122. package/dist/knowledge/SemanticAddressResolver.js.map +1 -0
  123. package/dist/knowledge/git-ingest.d.ts +58 -0
  124. package/dist/knowledge/git-ingest.d.ts.map +1 -0
  125. package/dist/knowledge/git-ingest.js +301 -0
  126. package/dist/knowledge/git-ingest.js.map +1 -0
  127. package/dist/knowledge/git-queries.d.ts +86 -0
  128. package/dist/knowledge/git-queries.d.ts.map +1 -0
  129. package/dist/knowledge/git-queries.js +177 -0
  130. package/dist/knowledge/git-queries.js.map +1 -0
  131. package/dist/knowledge/index.d.ts +14 -0
  132. package/dist/knowledge/index.d.ts.map +1 -0
  133. package/dist/knowledge/index.js +10 -0
  134. package/dist/knowledge/index.js.map +1 -0
  135. package/dist/knowledge/parser.d.ts +39 -0
  136. package/dist/knowledge/parser.d.ts.map +1 -0
  137. package/dist/knowledge/parser.js +292 -0
  138. package/dist/knowledge/parser.js.map +1 -0
  139. package/dist/knowledge/types.d.ts +133 -0
  140. package/dist/knowledge/types.d.ts.map +1 -0
  141. package/dist/knowledge/types.js +8 -0
  142. package/dist/knowledge/types.js.map +1 -0
  143. package/dist/logging/Logger.d.ts +98 -0
  144. package/dist/logging/Logger.d.ts.map +1 -0
  145. package/dist/logging/Logger.js +274 -0
  146. package/dist/logging/Logger.js.map +1 -0
  147. package/dist/notation/archetypes.d.ts +36 -0
  148. package/dist/notation/archetypes.d.ts.map +1 -0
  149. package/dist/notation/archetypes.js +173 -0
  150. package/dist/notation/archetypes.js.map +1 -0
  151. package/dist/notation/fold.d.ts +25 -0
  152. package/dist/notation/fold.d.ts.map +1 -0
  153. package/dist/notation/fold.js +598 -0
  154. package/dist/notation/fold.js.map +1 -0
  155. package/dist/notation/index.d.ts +18 -0
  156. package/dist/notation/index.d.ts.map +1 -0
  157. package/dist/notation/index.js +16 -0
  158. package/dist/notation/index.js.map +1 -0
  159. package/dist/notation/lodExtractor.d.ts +32 -0
  160. package/dist/notation/lodExtractor.d.ts.map +1 -0
  161. package/dist/notation/lodExtractor.js +149 -0
  162. package/dist/notation/lodExtractor.js.map +1 -0
  163. package/dist/notation/nameShortener.d.ts +22 -0
  164. package/dist/notation/nameShortener.d.ts.map +1 -0
  165. package/dist/notation/nameShortener.js +24 -0
  166. package/dist/notation/nameShortener.js.map +1 -0
  167. package/dist/notation/perspectives.d.ts +11 -0
  168. package/dist/notation/perspectives.d.ts.map +1 -0
  169. package/dist/notation/perspectives.js +16 -0
  170. package/dist/notation/perspectives.js.map +1 -0
  171. package/dist/notation/renderer.d.ts +31 -0
  172. package/dist/notation/renderer.d.ts.map +1 -0
  173. package/dist/notation/renderer.js +315 -0
  174. package/dist/notation/renderer.js.map +1 -0
  175. package/dist/notation/traceRenderer.d.ts +39 -0
  176. package/dist/notation/traceRenderer.d.ts.map +1 -0
  177. package/dist/notation/traceRenderer.js +358 -0
  178. package/dist/notation/traceRenderer.js.map +1 -0
  179. package/dist/notation/types.d.ts +66 -0
  180. package/dist/notation/types.d.ts.map +1 -0
  181. package/dist/notation/types.js +10 -0
  182. package/dist/notation/types.js.map +1 -0
  183. package/dist/queries/NodeContext.d.ts +81 -0
  184. package/dist/queries/NodeContext.d.ts.map +1 -0
  185. package/dist/queries/NodeContext.js +196 -0
  186. package/dist/queries/NodeContext.js.map +1 -0
  187. package/dist/queries/findCallsInFunction.d.ts +62 -0
  188. package/dist/queries/findCallsInFunction.d.ts.map +1 -0
  189. package/dist/queries/findCallsInFunction.js +169 -0
  190. package/dist/queries/findCallsInFunction.js.map +1 -0
  191. package/dist/queries/findContainingFunction.d.ts +57 -0
  192. package/dist/queries/findContainingFunction.d.ts.map +1 -0
  193. package/dist/queries/findContainingFunction.js +91 -0
  194. package/dist/queries/findContainingFunction.js.map +1 -0
  195. package/dist/queries/index.d.ts +18 -0
  196. package/dist/queries/index.d.ts.map +1 -0
  197. package/dist/queries/index.js +14 -0
  198. package/dist/queries/index.js.map +1 -0
  199. package/dist/queries/traceDataflow.d.ts +65 -0
  200. package/dist/queries/traceDataflow.d.ts.map +1 -0
  201. package/dist/queries/traceDataflow.js +754 -0
  202. package/dist/queries/traceDataflow.js.map +1 -0
  203. package/dist/queries/traceValues.d.ts +70 -0
  204. package/dist/queries/traceValues.d.ts.map +1 -0
  205. package/dist/queries/traceValues.js +373 -0
  206. package/dist/queries/traceValues.js.map +1 -0
  207. package/dist/queries/types.d.ts +166 -0
  208. package/dist/queries/types.d.ts.map +1 -0
  209. package/dist/queries/types.js +10 -0
  210. package/dist/queries/types.js.map +1 -0
  211. package/dist/schema/GraphSchemaExtractor.d.ts +53 -0
  212. package/dist/schema/GraphSchemaExtractor.d.ts.map +1 -0
  213. package/dist/schema/GraphSchemaExtractor.js +125 -0
  214. package/dist/schema/GraphSchemaExtractor.js.map +1 -0
  215. package/dist/schema/InterfaceSchemaExtractor.d.ts +73 -0
  216. package/dist/schema/InterfaceSchemaExtractor.d.ts.map +1 -0
  217. package/dist/schema/InterfaceSchemaExtractor.js +113 -0
  218. package/dist/schema/InterfaceSchemaExtractor.js.map +1 -0
  219. package/dist/schema/index.d.ts +5 -0
  220. package/dist/schema/index.d.ts.map +1 -0
  221. package/dist/schema/index.js +3 -0
  222. package/dist/schema/index.js.map +1 -0
  223. package/dist/storage/backends/RFDBServerBackend.d.ts +356 -0
  224. package/dist/storage/backends/RFDBServerBackend.d.ts.map +1 -0
  225. package/dist/storage/backends/RFDBServerBackend.js +748 -0
  226. package/dist/storage/backends/RFDBServerBackend.js.map +1 -0
  227. package/dist/storage/backends/typeValidation.d.ts +47 -0
  228. package/dist/storage/backends/typeValidation.d.ts.map +1 -0
  229. package/dist/storage/backends/typeValidation.js +141 -0
  230. package/dist/storage/backends/typeValidation.js.map +1 -0
  231. package/dist/utils/findRfdbBinary.d.ts +67 -0
  232. package/dist/utils/findRfdbBinary.d.ts.map +1 -0
  233. package/dist/utils/findRfdbBinary.js +261 -0
  234. package/dist/utils/findRfdbBinary.js.map +1 -0
  235. package/dist/utils/lazyDownload.d.ts +43 -0
  236. package/dist/utils/lazyDownload.d.ts.map +1 -0
  237. package/dist/utils/lazyDownload.js +175 -0
  238. package/dist/utils/lazyDownload.js.map +1 -0
  239. package/dist/utils/moduleResolution.d.ts +134 -0
  240. package/dist/utils/moduleResolution.d.ts.map +1 -0
  241. package/dist/utils/moduleResolution.js +189 -0
  242. package/dist/utils/moduleResolution.js.map +1 -0
  243. package/dist/utils/resolveNodeFile.d.ts +13 -0
  244. package/dist/utils/resolveNodeFile.d.ts.map +1 -0
  245. package/dist/utils/resolveNodeFile.js +18 -0
  246. package/dist/utils/resolveNodeFile.js.map +1 -0
  247. package/dist/utils/startRfdbServer.d.ts +63 -0
  248. package/dist/utils/startRfdbServer.d.ts.map +1 -0
  249. package/dist/utils/startRfdbServer.js +142 -0
  250. package/dist/utils/startRfdbServer.js.map +1 -0
  251. package/dist/validation/PathValidator.d.ts +80 -0
  252. package/dist/validation/PathValidator.d.ts.map +1 -0
  253. package/dist/validation/PathValidator.js +252 -0
  254. package/dist/validation/PathValidator.js.map +1 -0
  255. package/dist/version.d.ts +11 -0
  256. package/dist/version.d.ts.map +1 -0
  257. package/dist/version.js +26 -0
  258. package/dist/version.js.map +1 -0
  259. package/package.json +50 -0
  260. package/src/api/GraphAPI.ts +307 -0
  261. package/src/api/GuaranteeAPI.ts +402 -0
  262. package/src/config/ConfigLoader.ts +653 -0
  263. package/src/config/index.ts +13 -0
  264. package/src/core/CoverageAnalyzer.ts +243 -0
  265. package/src/core/FileExplainer.ts +179 -0
  266. package/src/core/FileOverview.ts +397 -0
  267. package/src/core/GrafemaUri.ts +216 -0
  268. package/src/core/GraphBackend.ts +266 -0
  269. package/src/core/GraphFreshnessChecker.ts +145 -0
  270. package/src/core/GuaranteeManager.ts +684 -0
  271. package/src/core/HashUtils.ts +48 -0
  272. package/src/core/IncrementalReanalyzer.ts +106 -0
  273. package/src/core/ResourceRegistry.ts +39 -0
  274. package/src/core/SemanticId.ts +423 -0
  275. package/src/core/VersionManager.ts +405 -0
  276. package/src/core/brandNodeInternal.ts +16 -0
  277. package/src/core/nodes/GuaranteeNode.ts +162 -0
  278. package/src/core/nodes/IssueNode.ts +177 -0
  279. package/src/core/nodes/NodeKind.ts +192 -0
  280. package/src/diagnostics/DiagnosticCollector.ts +170 -0
  281. package/src/diagnostics/DiagnosticReporter.ts +395 -0
  282. package/src/diagnostics/DiagnosticWriter.ts +50 -0
  283. package/src/diagnostics/categories.ts +104 -0
  284. package/src/diagnostics/index.ts +30 -0
  285. package/src/errors/GrafemaError.ts +297 -0
  286. package/src/index.ts +261 -0
  287. package/src/instructions/index.ts +21 -0
  288. package/src/instructions/onboarding.md +133 -0
  289. package/src/knowledge/KnowledgeBase.ts +486 -0
  290. package/src/knowledge/SemanticAddressResolver.ts +191 -0
  291. package/src/knowledge/git-ingest.ts +402 -0
  292. package/src/knowledge/git-queries.ts +269 -0
  293. package/src/knowledge/index.ts +29 -0
  294. package/src/knowledge/parser.ts +294 -0
  295. package/src/knowledge/types.ts +146 -0
  296. package/src/logging/Logger.ts +303 -0
  297. package/src/notation/archetypes.ts +189 -0
  298. package/src/notation/fold.ts +696 -0
  299. package/src/notation/index.ts +27 -0
  300. package/src/notation/lodExtractor.ts +177 -0
  301. package/src/notation/nameShortener.ts +24 -0
  302. package/src/notation/perspectives.ts +18 -0
  303. package/src/notation/renderer.ts +394 -0
  304. package/src/notation/traceRenderer.ts +458 -0
  305. package/src/notation/types.ts +79 -0
  306. package/src/queries/NodeContext.ts +280 -0
  307. package/src/queries/findCallsInFunction.ts +249 -0
  308. package/src/queries/findContainingFunction.ts +124 -0
  309. package/src/queries/index.ts +44 -0
  310. package/src/queries/traceDataflow.ts +838 -0
  311. package/src/queries/traceValues.ts +531 -0
  312. package/src/queries/types.ts +191 -0
  313. package/src/schema/GraphSchemaExtractor.ts +177 -0
  314. package/src/schema/InterfaceSchemaExtractor.ts +173 -0
  315. package/src/schema/index.ts +5 -0
  316. package/src/storage/backends/RFDBServerBackend.ts +895 -0
  317. package/src/storage/backends/typeValidation.ts +154 -0
  318. package/src/utils/findRfdbBinary.ts +288 -0
  319. package/src/utils/lazyDownload.ts +206 -0
  320. package/src/utils/moduleResolution.ts +271 -0
  321. package/src/utils/resolveNodeFile.ts +18 -0
  322. package/src/utils/startRfdbServer.ts +197 -0
  323. package/src/validation/PathValidator.ts +334 -0
  324. package/src/version.ts +28 -0
@@ -0,0 +1,158 @@
1
+ /**
2
+ * GraphBackend - abstract base class for graph storage implementations
3
+ *
4
+ * This defines the full contract for graph storage backends.
5
+ * All operations are async for compatibility with disk-based storage.
6
+ *
7
+ * Implementations:
8
+ * - RFDBServerBackend (Rust-based, production)
9
+ * - TestBackend (wrapper over RFDBServerBackend for tests)
10
+ */
11
+ import type { NodeRecord } from '@grafema/types';
12
+ import type { EdgeRecord, EdgeType } from '@grafema/types';
13
+ export type { NodeRecord as Node } from '@grafema/types';
14
+ export type { EdgeRecord as Edge, EdgeType } from '@grafema/types';
15
+ /**
16
+ * Query filter for finding nodes by attributes
17
+ */
18
+ export interface AttrQuery {
19
+ kind?: number;
20
+ version?: string;
21
+ file_id?: string;
22
+ file?: string;
23
+ exported?: boolean;
24
+ type?: string;
25
+ name?: string;
26
+ /** When true, name and file filters use substring (contains) matching instead of exact match */
27
+ substringMatch?: boolean;
28
+ [key: string]: unknown;
29
+ }
30
+ /**
31
+ * Graph statistics
32
+ */
33
+ export interface GraphStats {
34
+ nodeCount: number;
35
+ edgeCount: number;
36
+ }
37
+ /**
38
+ * Exported graph data
39
+ */
40
+ export interface GraphExport {
41
+ nodes: NodeRecord[];
42
+ edges: EdgeRecord[];
43
+ }
44
+ /**
45
+ * Abstract GraphBackend class - base for all graph storage implementations
46
+ */
47
+ export declare abstract class GraphBackend {
48
+ /**
49
+ * Initialize backend
50
+ */
51
+ abstract initialize(): Promise<void>;
52
+ /**
53
+ * Connect to storage (alias for initialize)
54
+ */
55
+ connect(): Promise<void>;
56
+ /**
57
+ * Close connection and flush data to disk
58
+ */
59
+ abstract close(): Promise<void>;
60
+ /**
61
+ * Clear all data
62
+ */
63
+ abstract clear(): Promise<void>;
64
+ /**
65
+ * Add a single node
66
+ */
67
+ abstract addNode(node: NodeRecord): Promise<void>;
68
+ /**
69
+ * Add multiple nodes (batch operation)
70
+ */
71
+ abstract addNodes(nodes: NodeRecord[]): Promise<void>;
72
+ /**
73
+ * Get node by ID
74
+ */
75
+ abstract getNode(id: string): Promise<NodeRecord | null>;
76
+ /**
77
+ * Check if node exists
78
+ */
79
+ abstract nodeExists(id: string): Promise<boolean>;
80
+ /**
81
+ * Delete a node
82
+ */
83
+ abstract deleteNode(id: string): Promise<void>;
84
+ /**
85
+ * Find nodes by attributes
86
+ * @returns Array of node IDs
87
+ */
88
+ abstract findByAttr(query: AttrQuery): Promise<string[]>;
89
+ /**
90
+ * Add a single edge
91
+ */
92
+ abstract addEdge(edge: EdgeRecord): Promise<void>;
93
+ /**
94
+ * Add multiple edges (batch operation)
95
+ */
96
+ abstract addEdges(edges: EdgeRecord[]): Promise<void>;
97
+ /**
98
+ * Delete an edge
99
+ */
100
+ abstract deleteEdge(src: string, dst: string, type: string): Promise<void>;
101
+ /**
102
+ * Get outgoing edges from a node
103
+ * @param nodeId - Node ID
104
+ * @param edgeTypes - Filter by edge types (optional)
105
+ */
106
+ abstract getOutgoingEdges(nodeId: string, edgeTypes?: EdgeType[] | null): Promise<EdgeRecord[]>;
107
+ /**
108
+ * Get incoming edges to a node
109
+ * @param nodeId - Node ID
110
+ * @param edgeTypes - Filter by edge types (optional)
111
+ */
112
+ abstract getIncomingEdges(nodeId: string, edgeTypes?: EdgeType[] | null): Promise<EdgeRecord[]>;
113
+ /**
114
+ * BFS traversal from start nodes
115
+ * @param startIds - Starting nodes
116
+ * @param maxDepth - Maximum depth
117
+ * @param edgeTypes - Edge types to traverse (as numbers)
118
+ * @returns Array of reachable node IDs
119
+ */
120
+ abstract bfs(startIds: string[], maxDepth: number, edgeTypes: number[]): Promise<string[]>;
121
+ /**
122
+ * Flush data to disk
123
+ */
124
+ abstract flush(): Promise<void>;
125
+ /**
126
+ * Get graph statistics
127
+ */
128
+ abstract getStats(): Promise<GraphStats>;
129
+ /**
130
+ * Export entire graph to memory (only for tests!)
131
+ * WARNING: Do not use on large graphs
132
+ */
133
+ abstract export(): Promise<GraphExport>;
134
+ /**
135
+ * Find nodes by predicate (for demo-gui compatibility)
136
+ * WARNING: May be slow on large graphs
137
+ */
138
+ abstract findNodes(predicate: (node: NodeRecord) => boolean): Promise<NodeRecord[]>;
139
+ /**
140
+ * Get all nodes (for GUI - only for first level visualization)
141
+ * WARNING: Do not use on large graphs
142
+ */
143
+ abstract getAllNodes(): Promise<NodeRecord[]>;
144
+ /**
145
+ * Get all edges (for GUI)
146
+ * WARNING: Do not use on large graphs
147
+ */
148
+ abstract getAllEdges(): Promise<EdgeRecord[]>;
149
+ }
150
+ /**
151
+ * Convert node type to numeric kind
152
+ */
153
+ export declare function typeToKind(type: string): number;
154
+ /**
155
+ * Convert edge type to number
156
+ */
157
+ export declare function edgeTypeToNumber(type: string): number;
158
+ //# sourceMappingURL=GraphBackend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GraphBackend.d.ts","sourceRoot":"","sources":["../../src/core/GraphBackend.ts"],"names":[],"m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AAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAM1F;;OAEG;IACH,QAAQ,CAAC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAE/B;;OAEG;IACH,QAAQ,CAAC,QAAQ,IAAI,OAAO,CAAC,UAAU,CAAC;IAMxC;;;OAGG;IACH,QAAQ,CAAC,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC;IAEvC;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,OAAO,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAEnF;;;OAGG;IACH,QAAQ,CAAC,WAAW,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IAE7C;;;OAGG;IACH,QAAQ,CAAC,WAAW,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;CAC9C;AA6BD;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/C;AA4BD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAErD"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * GraphBackend - abstract base class for graph storage implementations
3
+ *
4
+ * This defines the full contract for graph storage backends.
5
+ * All operations are async for compatibility with disk-based storage.
6
+ *
7
+ * Implementations:
8
+ * - RFDBServerBackend (Rust-based, production)
9
+ * - TestBackend (wrapper over RFDBServerBackend for tests)
10
+ */
11
+ /**
12
+ * Abstract GraphBackend class - base for all graph storage implementations
13
+ */
14
+ export class GraphBackend {
15
+ /**
16
+ * Connect to storage (alias for initialize)
17
+ */
18
+ async connect() {
19
+ return this.initialize();
20
+ }
21
+ }
22
+ /**
23
+ * Node type to numeric kind mapping
24
+ */
25
+ const NODE_TYPE_TO_KIND = {
26
+ 'PROJECT': 1,
27
+ 'SERVICE': 2,
28
+ 'FUNCTION': 3,
29
+ 'CLASS': 4,
30
+ 'METHOD': 5,
31
+ 'VARIABLE': 6,
32
+ 'PARAMETER': 7,
33
+ 'MODULE': 8,
34
+ 'ROUTE': 9,
35
+ 'ENDPOINT': 10,
36
+ 'FILE': 11,
37
+ 'EXTERNAL_MODULE': 12,
38
+ 'IMPORT': 13,
39
+ 'EXPORT': 14,
40
+ 'CALL_SITE': 15,
41
+ 'METHOD_CALL': 16,
42
+ 'SCOPE': 17,
43
+ 'VARIABLE_DECLARATION': 18,
44
+ 'CONSTANT': 19,
45
+ 'EVENT_LISTENER': 20,
46
+ 'HTTP_REQUEST': 21,
47
+ };
48
+ /**
49
+ * Convert node type to numeric kind
50
+ */
51
+ export function typeToKind(type) {
52
+ return NODE_TYPE_TO_KIND[type] || 0;
53
+ }
54
+ /**
55
+ * Edge type to numeric mapping
56
+ */
57
+ const EDGE_TYPE_TO_NUMBER = {
58
+ 'CONTAINS': 1,
59
+ 'DEPENDS_ON': 2,
60
+ 'CALLS': 3,
61
+ 'EXTENDS': 4,
62
+ 'IMPLEMENTS': 5,
63
+ 'USES': 6,
64
+ 'DEFINES': 7,
65
+ 'IMPORTS': 8,
66
+ 'EXPORTS': 9,
67
+ 'ROUTES_TO': 10,
68
+ 'DECLARES': 11,
69
+ 'HAS_SCOPE': 12,
70
+ 'CAPTURES': 13,
71
+ 'MODIFIES': 14,
72
+ 'WRITES_TO': 15,
73
+ 'INSTANCE_OF': 16,
74
+ 'HANDLED_BY': 17,
75
+ 'HAS_CALLBACK': 18,
76
+ 'MAKES_REQUEST': 19,
77
+ 'IMPORTS_FROM': 20,
78
+ };
79
+ /**
80
+ * Convert edge type to number
81
+ */
82
+ export function edgeTypeToNumber(type) {
83
+ return EDGE_TYPE_TO_NUMBER[type] || 0;
84
+ }
85
+ //# sourceMappingURL=GraphBackend.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GraphBackend.js","sourceRoot":"","sources":["../../src/core/GraphBackend.ts"],"names":[],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a,EAAE,EAAE;IACjB,YAAY,EAAE,EAAE;IAChB,cAAc,EAAE,EAAE;IAClB,eAAe,EAAE,EAAE;IACnB,cAAc,EAAE,EAAE;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,OAAO,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * GraphFreshnessChecker - checks if graph data matches current files
3
+ *
4
+ * Compares contentHash stored in MODULE nodes against current file hashes.
5
+ * Used by `grafema check` to detect when files have changed since analysis.
6
+ */
7
+ import type { NodeRecord } from '@grafema/types';
8
+ export interface StaleModule {
9
+ id: string;
10
+ file: string;
11
+ storedHash: string;
12
+ currentHash: string | null;
13
+ reason: 'changed' | 'deleted' | 'unreadable';
14
+ }
15
+ export interface FreshnessResult {
16
+ isFresh: boolean;
17
+ staleModules: StaleModule[];
18
+ freshCount: number;
19
+ staleCount: number;
20
+ deletedCount: number;
21
+ checkDurationMs: number;
22
+ }
23
+ export interface FreshnessGraph {
24
+ queryNodes(query: {
25
+ type: string;
26
+ }): AsyncGenerator<NodeRecord, void, unknown>;
27
+ }
28
+ export declare class GraphFreshnessChecker {
29
+ checkFreshness(graph: FreshnessGraph, projectPath?: string): Promise<FreshnessResult>;
30
+ private _checkModuleFreshness;
31
+ private _fileExists;
32
+ }
33
+ //# sourceMappingURL=GraphFreshnessChecker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GraphFreshnessChecker.d.ts","sourceRoot":"","sources":["../../src/core/GraphFreshnessChecker.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,YAAY,CAAC;CAC9C;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,WAAW,EAAE,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,cAAc;IAC7B,UAAU,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;CAChF;AAUD,qBAAa,qBAAqB;IAC1B,cAAc,CAAC,KAAK,EAAE,cAAc,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;YAyD7E,qBAAqB;YAqCrB,WAAW;CAQ1B"}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * GraphFreshnessChecker - checks if graph data matches current files
3
+ *
4
+ * Compares contentHash stored in MODULE nodes against current file hashes.
5
+ * Used by `grafema check` to detect when files have changed since analysis.
6
+ */
7
+ import { access, constants } from 'fs/promises';
8
+ import { calculateFileHashAsync } from './HashUtils.js';
9
+ import { resolveNodeFile } from '../utils/resolveNodeFile.js';
10
+ const BATCH_SIZE = 50;
11
+ export class GraphFreshnessChecker {
12
+ async checkFreshness(graph, projectPath) {
13
+ const startTime = Date.now();
14
+ const modules = [];
15
+ for await (const node of graph.queryNodes({ type: 'MODULE' })) {
16
+ if (node.file && typeof node.contentHash === 'string') {
17
+ modules.push({
18
+ id: node.id,
19
+ file: node.file,
20
+ contentHash: node.contentHash
21
+ });
22
+ }
23
+ }
24
+ if (modules.length === 0) {
25
+ return {
26
+ isFresh: true,
27
+ staleModules: [],
28
+ freshCount: 0,
29
+ staleCount: 0,
30
+ deletedCount: 0,
31
+ checkDurationMs: Date.now() - startTime
32
+ };
33
+ }
34
+ const staleModules = [];
35
+ let freshCount = 0;
36
+ let deletedCount = 0;
37
+ for (let i = 0; i < modules.length; i += BATCH_SIZE) {
38
+ const batch = modules.slice(i, i + BATCH_SIZE);
39
+ const results = await Promise.all(batch.map(module => this._checkModuleFreshness(module, projectPath)));
40
+ for (const result of results) {
41
+ if (result === null) {
42
+ freshCount++;
43
+ }
44
+ else {
45
+ staleModules.push(result);
46
+ if (result.reason === 'deleted') {
47
+ deletedCount++;
48
+ }
49
+ }
50
+ }
51
+ }
52
+ return {
53
+ isFresh: staleModules.length === 0,
54
+ staleModules,
55
+ freshCount,
56
+ staleCount: staleModules.length,
57
+ deletedCount,
58
+ checkDurationMs: Date.now() - startTime
59
+ };
60
+ }
61
+ async _checkModuleFreshness(module, projectPath) {
62
+ const absoluteFile = projectPath ? resolveNodeFile(module.file, projectPath) : module.file;
63
+ const exists = await this._fileExists(absoluteFile);
64
+ if (!exists) {
65
+ return {
66
+ id: module.id,
67
+ file: module.file,
68
+ storedHash: module.contentHash,
69
+ currentHash: null,
70
+ reason: 'deleted'
71
+ };
72
+ }
73
+ const currentHash = await calculateFileHashAsync(absoluteFile);
74
+ if (currentHash === null) {
75
+ return {
76
+ id: module.id,
77
+ file: module.file,
78
+ storedHash: module.contentHash,
79
+ currentHash: null,
80
+ reason: 'unreadable'
81
+ };
82
+ }
83
+ if (currentHash !== module.contentHash) {
84
+ return {
85
+ id: module.id,
86
+ file: module.file,
87
+ storedHash: module.contentHash,
88
+ currentHash,
89
+ reason: 'changed'
90
+ };
91
+ }
92
+ return null;
93
+ }
94
+ async _fileExists(filePath) {
95
+ try {
96
+ await access(filePath, constants.R_OK);
97
+ return true;
98
+ }
99
+ catch {
100
+ return false;
101
+ }
102
+ }
103
+ }
104
+ //# sourceMappingURL=GraphFreshnessChecker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GraphFreshnessChecker.js","sourceRoot":"","sources":["../../src/core/GraphFreshnessChecker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U,EAAE,MAAM,CAAC,WAAW;gBAC9B,WAAW,EAAE,IAAI;gBACjB,MAAM,EAAE,SAAS;aAClB,CAAC;QACJ,CAAC;QAED,MAAM,WAAW,GAAG,MAAM,sBAAsB,CAAC,YAAY,CAAC,CAAC;QAC/D,IAAI,WAAW,KAAK,IAAI,EAAE,CAAC;YACzB,OAAO;gBACL,EAAE,EAAE,MAAM,CAAC,EAAE;gBACb,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,UAAU,EAAE,MAAM,CAAC,WAAW;gBAC9B,WAAW,EAAE,IAAI;gBACjB,MAAM,EAAE,YAAY;aACrB,CAAC;QACJ,CAAC;QAED,IAAI,WAAW,KAAK,MAAM,CAAC,WAAW,EAAE,CAAC;YACvC,OAAO;gBACL,EAAE,EAAE,MAAM,CAAC,EAAE;gBACb,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,UAAU,EAAE,MAAM,CAAC,WAAW;gBAC9B,WAAW;gBACX,MAAM,EAAE,SAAS;aAClB,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,KAAK,CAAC,WAAW,CAAC,QAAgB;QACxC,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;YACvC,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,254 @@
1
+ /**
2
+ * GuaranteeManager - управление гарантиями/инвариантами кода
3
+ *
4
+ * GUARANTEE ноды хранят Datalog правила, которые код должен соблюдать.
5
+ * GOVERNS edges связывают гарантии с модулями, к которым они применяются.
6
+ *
7
+ * Workflow:
8
+ * 1. Создать гарантию (create) → GUARANTEE нода + GOVERNS edges
9
+ * 2. Проверить (check) → выполнить Datalog rule, найти нарушения
10
+ * 3. Экспортировать (export) → сохранить в YAML для version control
11
+ * 4. Импортировать (import) → загрузить из YAML в граф
12
+ * 5. Drift detection → сравнить граф с файлом
13
+ */
14
+ /**
15
+ * Severity level for guarantees
16
+ */
17
+ export type GuaranteeSeverity = 'error' | 'warning' | 'info';
18
+ /**
19
+ * Guarantee definition
20
+ */
21
+ export interface GuaranteeDefinition {
22
+ id: string;
23
+ name?: string;
24
+ rule: string;
25
+ severity?: GuaranteeSeverity;
26
+ governs?: string[];
27
+ }
28
+ /**
29
+ * Guarantee node structure
30
+ */
31
+ export interface GuaranteeNode {
32
+ id: string;
33
+ type: 'GUARANTEE';
34
+ name: string;
35
+ rule: string;
36
+ severity: GuaranteeSeverity;
37
+ governs: string[];
38
+ version: 'meta';
39
+ createdAt: number;
40
+ governedModules?: string[];
41
+ }
42
+ /**
43
+ * Edge structure
44
+ */
45
+ export interface GraphEdge {
46
+ type: string;
47
+ src: string;
48
+ dst: string;
49
+ }
50
+ /**
51
+ * Module node
52
+ */
53
+ export interface ModuleNode {
54
+ id: string;
55
+ type: string;
56
+ file?: string;
57
+ }
58
+ /**
59
+ * Violation binding
60
+ */
61
+ export interface ViolationBinding {
62
+ name: string;
63
+ value: string;
64
+ }
65
+ /**
66
+ * Violation result from Datalog
67
+ */
68
+ export interface ViolationResult {
69
+ bindings?: ViolationBinding[];
70
+ }
71
+ /**
72
+ * Enriched violation info
73
+ */
74
+ export interface EnrichedViolation {
75
+ nodeId: string;
76
+ type: string;
77
+ name?: string;
78
+ file?: string;
79
+ line?: number;
80
+ }
81
+ /**
82
+ * Check result for a single guarantee
83
+ */
84
+ export interface GuaranteeCheckResult {
85
+ guaranteeId: string;
86
+ name: string;
87
+ severity: GuaranteeSeverity;
88
+ passed: boolean;
89
+ violationCount: number;
90
+ violations: EnrichedViolation[];
91
+ error: string | null;
92
+ checkDurationMs: number;
93
+ }
94
+ /**
95
+ * Check all result
96
+ */
97
+ export interface CheckAllResult {
98
+ total: number;
99
+ passed: number;
100
+ failed: number;
101
+ errors: number;
102
+ results: GuaranteeCheckResult[];
103
+ }
104
+ /**
105
+ * Import options
106
+ */
107
+ export interface ImportOptions {
108
+ clearExisting?: boolean;
109
+ }
110
+ /**
111
+ * Import result
112
+ */
113
+ export interface ImportResult {
114
+ imported: number;
115
+ skipped: number;
116
+ importedIds: string[];
117
+ skippedIds: string[];
118
+ }
119
+ /**
120
+ * Modified guarantee in drift
121
+ */
122
+ export interface ModifiedGuarantee {
123
+ id: string;
124
+ changes: string[];
125
+ }
126
+ /**
127
+ * Drift summary
128
+ */
129
+ export interface DriftSummary {
130
+ onlyInGraph: number;
131
+ onlyInFile: number;
132
+ modified: number;
133
+ unchanged: number;
134
+ }
135
+ /**
136
+ * Drift result
137
+ */
138
+ export interface DriftResult {
139
+ hasDrift: boolean;
140
+ summary: DriftSummary;
141
+ onlyInGraph: string[];
142
+ onlyInFile: string[];
143
+ modified: ModifiedGuarantee[];
144
+ unchanged: string[];
145
+ }
146
+ /**
147
+ * Export data format
148
+ */
149
+ export interface ExportData {
150
+ version: number;
151
+ exportedAt: string;
152
+ guarantees: Array<{
153
+ id: string;
154
+ name: string;
155
+ rule: string;
156
+ severity: GuaranteeSeverity;
157
+ governs: string[];
158
+ }>;
159
+ }
160
+ /**
161
+ * Graph interface for GuaranteeManager
162
+ */
163
+ export interface GuaranteeGraph {
164
+ addNode(node: GuaranteeNode): Promise<void>;
165
+ getNode(id: string): Promise<GuaranteeNode | ModuleNode | null>;
166
+ deleteNode(id: string): Promise<void>;
167
+ queryNodes(filter: {
168
+ type: string;
169
+ }): AsyncIterable<GuaranteeNode | ModuleNode>;
170
+ addEdge(edge: GraphEdge): Promise<void>;
171
+ deleteEdge(src: string, dst: string, type: string): Promise<void>;
172
+ getOutgoingEdges(nodeId: string, types: string[]): Promise<GraphEdge[]>;
173
+ getIncomingEdges(nodeId: string, types: string[]): Promise<GraphEdge[]>;
174
+ checkGuarantee(rule: string): Promise<ViolationResult[]>;
175
+ }
176
+ export declare class GuaranteeManager {
177
+ private graph;
178
+ private projectPath;
179
+ private guaranteesFile;
180
+ constructor(graph: GuaranteeGraph, projectPath: string);
181
+ /**
182
+ * Создать новую гарантию
183
+ */
184
+ create(guarantee: GuaranteeDefinition): Promise<GuaranteeNode>;
185
+ /**
186
+ * Получить все гарантии из графа
187
+ */
188
+ list(): Promise<GuaranteeNode[]>;
189
+ /**
190
+ * Проверить гарантию
191
+ */
192
+ check(guaranteeId: string): Promise<GuaranteeCheckResult>;
193
+ /**
194
+ * Проверить все гарантии
195
+ */
196
+ checkAll(): Promise<CheckAllResult>;
197
+ /**
198
+ * Extract type references from a Datalog rule.
199
+ * Matches node(X, "TYPE") and edge(X, Y, "TYPE") patterns.
200
+ * Returns unique types array. If nothing parseable, returns empty array.
201
+ */
202
+ extractRelevantTypes(rule: string): string[];
203
+ /**
204
+ * Selectively check guarantees whose relevant types overlap with changedTypes.
205
+ * Guarantees with no parseable types are always checked (conservative).
206
+ * Returns CheckAllResult with total = all guarantees count,
207
+ * but results only for the checked subset.
208
+ */
209
+ checkSelective(changedTypes: Set<string>): Promise<CheckAllResult>;
210
+ /**
211
+ * Load guarantees from the project's YAML file (.grafema/guarantees.yaml).
212
+ *
213
+ * Reads the YAML file, skips non-datalog guarantees (e.g., integration-test),
214
+ * and creates GUARANTEE nodes in the graph for each datalog guarantee.
215
+ * Idempotent: skips guarantees that already exist in the graph.
216
+ * Gracefully handles missing file (no error, just returns).
217
+ *
218
+ * @returns ImportResult with counts of imported and skipped guarantees
219
+ */
220
+ loadFromYaml(): Promise<ImportResult>;
221
+ /**
222
+ * Удалить гарантию
223
+ */
224
+ delete(guaranteeId: string): Promise<void>;
225
+ /**
226
+ * Экспортировать гарантии в YAML файл
227
+ */
228
+ export(filePath?: string): Promise<string>;
229
+ /**
230
+ * Импортировать гарантии из YAML файла
231
+ */
232
+ import(filePath?: string, options?: ImportOptions): Promise<ImportResult>;
233
+ /**
234
+ * Показать drift между графом и файлом
235
+ */
236
+ drift(filePath?: string): Promise<DriftResult>;
237
+ /**
238
+ * Найти гарантии затронутые изменением ноды
239
+ */
240
+ findAffectedGuarantees(nodeId: string): Promise<string[]>;
241
+ /**
242
+ * Создать GOVERNS edges к модулям по glob patterns
243
+ */
244
+ private _createGovernsEdges;
245
+ /**
246
+ * Проверить есть ли изменения между версиями гарантии
247
+ */
248
+ private _hasChanges;
249
+ /**
250
+ * Описать изменения между версиями
251
+ */
252
+ private _describeChanges;
253
+ }
254
+ //# sourceMappingURL=GuaranteeManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GuaranteeManager.d.ts","sourceRoot":"","sources":["../../src/core/GuaranteeManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AASH;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE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