circle-ir 4.19.0 → 4.21.0

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 (262) hide show
  1. package/dist/analysis/advisories.d.ts +21 -3
  2. package/dist/analysis/advisories.d.ts.map +1 -1
  3. package/dist/analysis/advisories.js +26 -8
  4. package/dist/analysis/advisories.js.map +1 -1
  5. package/dist/analysis/arg-executing-programs.d.ts +16 -0
  6. package/dist/analysis/arg-executing-programs.d.ts.map +1 -0
  7. package/dist/analysis/arg-executing-programs.js +24 -0
  8. package/dist/analysis/arg-executing-programs.js.map +1 -0
  9. package/dist/analysis/config-loader.d.ts.map +1 -1
  10. package/dist/analysis/config-loader.js +27 -3
  11. package/dist/analysis/config-loader.js.map +1 -1
  12. package/dist/analysis/constant-caller-gate.d.ts +3 -1
  13. package/dist/analysis/constant-caller-gate.d.ts.map +1 -1
  14. package/dist/analysis/constant-caller-gate.js +108 -1
  15. package/dist/analysis/constant-caller-gate.js.map +1 -1
  16. package/dist/analysis/constant-propagation/index.d.ts.map +1 -1
  17. package/dist/analysis/constant-propagation/index.js +1 -1
  18. package/dist/analysis/constant-propagation/index.js.map +1 -1
  19. package/dist/analysis/constant-propagation/patterns.d.ts.map +1 -1
  20. package/dist/analysis/constant-propagation/patterns.js +8 -0
  21. package/dist/analysis/constant-propagation/patterns.js.map +1 -1
  22. package/dist/analysis/constant-propagation/propagator.d.ts +47 -2
  23. package/dist/analysis/constant-propagation/propagator.d.ts.map +1 -1
  24. package/dist/analysis/constant-propagation/propagator.js +422 -57
  25. package/dist/analysis/constant-propagation/propagator.js.map +1 -1
  26. package/dist/analysis/constant-propagation/types.d.ts +2 -0
  27. package/dist/analysis/constant-propagation/types.d.ts.map +1 -1
  28. package/dist/analysis/dependency-versions.d.ts +33 -0
  29. package/dist/analysis/dependency-versions.d.ts.map +1 -1
  30. package/dist/analysis/dependency-versions.js +70 -0
  31. package/dist/analysis/dependency-versions.js.map +1 -1
  32. package/dist/analysis/findings.d.ts.map +1 -1
  33. package/dist/analysis/findings.js +7 -5
  34. package/dist/analysis/findings.js.map +1 -1
  35. package/dist/analysis/interprocedural.d.ts +16 -0
  36. package/dist/analysis/interprocedural.d.ts.map +1 -1
  37. package/dist/analysis/interprocedural.js +545 -197
  38. package/dist/analysis/interprocedural.js.map +1 -1
  39. package/dist/analysis/passes/constant-propagation-pass.d.ts.map +1 -1
  40. package/dist/analysis/passes/constant-propagation-pass.js +1 -0
  41. package/dist/analysis/passes/constant-propagation-pass.js.map +1 -1
  42. package/dist/analysis/passes/cross-file-pass.d.ts.map +1 -1
  43. package/dist/analysis/passes/cross-file-pass.js +61 -0
  44. package/dist/analysis/passes/cross-file-pass.js.map +1 -1
  45. package/dist/analysis/passes/csharp-sanitizer-credit.d.ts.map +1 -1
  46. package/dist/analysis/passes/csharp-sanitizer-credit.js +60 -3
  47. package/dist/analysis/passes/csharp-sanitizer-credit.js.map +1 -1
  48. package/dist/analysis/passes/csrf-samesite-none-session-pass.d.ts +58 -0
  49. package/dist/analysis/passes/csrf-samesite-none-session-pass.d.ts.map +1 -0
  50. package/dist/analysis/passes/csrf-samesite-none-session-pass.js +159 -0
  51. package/dist/analysis/passes/csrf-samesite-none-session-pass.js.map +1 -0
  52. package/dist/analysis/passes/deserialization-safety-gate-pass.d.ts +15 -0
  53. package/dist/analysis/passes/deserialization-safety-gate-pass.d.ts.map +1 -1
  54. package/dist/analysis/passes/deserialization-safety-gate-pass.js +60 -1
  55. package/dist/analysis/passes/deserialization-safety-gate-pass.js.map +1 -1
  56. package/dist/analysis/passes/interprocedural-pass.d.ts +23 -1
  57. package/dist/analysis/passes/interprocedural-pass.d.ts.map +1 -1
  58. package/dist/analysis/passes/interprocedural-pass.js +220 -7
  59. package/dist/analysis/passes/interprocedural-pass.js.map +1 -1
  60. package/dist/analysis/passes/language-sources-pass.d.ts +0 -18
  61. package/dist/analysis/passes/language-sources-pass.d.ts.map +1 -1
  62. package/dist/analysis/passes/language-sources-pass.js +549 -22
  63. package/dist/analysis/passes/language-sources-pass.js.map +1 -1
  64. package/dist/analysis/passes/param-source-flow-gate-pass.d.ts.map +1 -1
  65. package/dist/analysis/passes/param-source-flow-gate-pass.js +71 -1
  66. package/dist/analysis/passes/param-source-flow-gate-pass.js.map +1 -1
  67. package/dist/analysis/passes/prompt-injection-safety-gate-pass.js +1 -1
  68. package/dist/analysis/passes/prompt-injection-safety-gate-pass.js.map +1 -1
  69. package/dist/analysis/passes/resource-leak-pass.d.ts.map +1 -1
  70. package/dist/analysis/passes/resource-leak-pass.js +15 -3
  71. package/dist/analysis/passes/resource-leak-pass.js.map +1 -1
  72. package/dist/analysis/passes/scan-secrets-pass.js +2 -2
  73. package/dist/analysis/passes/scan-secrets-pass.js.map +1 -1
  74. package/dist/analysis/passes/sensitive-data-in-log-pass.d.ts +66 -0
  75. package/dist/analysis/passes/sensitive-data-in-log-pass.d.ts.map +1 -0
  76. package/dist/analysis/passes/sensitive-data-in-log-pass.js +462 -0
  77. package/dist/analysis/passes/sensitive-data-in-log-pass.js.map +1 -0
  78. package/dist/analysis/passes/sink-filter-pass.d.ts +7 -1
  79. package/dist/analysis/passes/sink-filter-pass.d.ts.map +1 -1
  80. package/dist/analysis/passes/sink-filter-pass.js +564 -22
  81. package/dist/analysis/passes/sink-filter-pass.js.map +1 -1
  82. package/dist/analysis/passes/taint-propagation-pass.d.ts +7 -3
  83. package/dist/analysis/passes/taint-propagation-pass.d.ts.map +1 -1
  84. package/dist/analysis/passes/taint-propagation-pass.js +464 -27
  85. package/dist/analysis/passes/taint-propagation-pass.js.map +1 -1
  86. package/dist/analysis/passes/xml-entity-expansion-pass.d.ts.map +1 -1
  87. package/dist/analysis/passes/xml-entity-expansion-pass.js +50 -6
  88. package/dist/analysis/passes/xml-entity-expansion-pass.js.map +1 -1
  89. package/dist/analysis/pep440-version.d.ts +40 -0
  90. package/dist/analysis/pep440-version.d.ts.map +1 -0
  91. package/dist/analysis/pep440-version.js +149 -0
  92. package/dist/analysis/pep440-version.js.map +1 -0
  93. package/dist/analysis/project-callee-escape-gate.js +1 -1
  94. package/dist/analysis/project-callee-escape-gate.js.map +1 -1
  95. package/dist/analysis/rules.d.ts.map +1 -1
  96. package/dist/analysis/rules.js +15 -0
  97. package/dist/analysis/rules.js.map +1 -1
  98. package/dist/analysis/sbom.d.ts +92 -4
  99. package/dist/analysis/sbom.d.ts.map +1 -1
  100. package/dist/analysis/sbom.js +390 -33
  101. package/dist/analysis/sbom.js.map +1 -1
  102. package/dist/analysis/taint-matcher.d.ts.map +1 -1
  103. package/dist/analysis/taint-matcher.js +124 -19
  104. package/dist/analysis/taint-matcher.js.map +1 -1
  105. package/dist/analysis/taint-propagation.d.ts +1 -0
  106. package/dist/analysis/taint-propagation.d.ts.map +1 -1
  107. package/dist/analysis/taint-propagation.js +32 -0
  108. package/dist/analysis/taint-propagation.js.map +1 -1
  109. package/dist/analysis/test-to-production-taint-gate.d.ts +13 -0
  110. package/dist/analysis/test-to-production-taint-gate.d.ts.map +1 -0
  111. package/dist/analysis/test-to-production-taint-gate.js +30 -0
  112. package/dist/analysis/test-to-production-taint-gate.js.map +1 -0
  113. package/dist/analyzer.d.ts +21 -3
  114. package/dist/analyzer.d.ts.map +1 -1
  115. package/dist/analyzer.js +83 -3
  116. package/dist/analyzer.js.map +1 -1
  117. package/dist/browser/circle-ir.js +8118 -2526
  118. package/dist/core/circle-ir-core.cjs +3098 -2280
  119. package/dist/core/circle-ir-core.js +3036 -2214
  120. package/dist/core/extractors/calls.d.ts +10 -1
  121. package/dist/core/extractors/calls.d.ts.map +1 -1
  122. package/dist/core/extractors/calls.js +148 -6
  123. package/dist/core/extractors/calls.js.map +1 -1
  124. package/dist/core/extractors/cfg.d.ts.map +1 -1
  125. package/dist/core/extractors/cfg.js +12 -0
  126. package/dist/core/extractors/cfg.js.map +1 -1
  127. package/dist/core/extractors/dfg.d.ts.map +1 -1
  128. package/dist/core/extractors/dfg.js +151 -18
  129. package/dist/core/extractors/dfg.js.map +1 -1
  130. package/dist/core/extractors/ts-declaration-detail.d.ts +8 -0
  131. package/dist/core/extractors/ts-declaration-detail.d.ts.map +1 -1
  132. package/dist/core/extractors/ts-declaration-detail.js +22 -0
  133. package/dist/core/extractors/ts-declaration-detail.js.map +1 -1
  134. package/dist/core/extractors/types.d.ts +5 -0
  135. package/dist/core/extractors/types.d.ts.map +1 -1
  136. package/dist/core/extractors/types.js +149 -4
  137. package/dist/core/extractors/types.js.map +1 -1
  138. package/dist/core/parser.d.ts.map +1 -1
  139. package/dist/core/parser.js +3 -1
  140. package/dist/core/parser.js.map +1 -1
  141. package/dist/core/ts-grammar-workarounds.d.ts +18 -0
  142. package/dist/core/ts-grammar-workarounds.d.ts.map +1 -0
  143. package/dist/core/ts-grammar-workarounds.js +40 -0
  144. package/dist/core/ts-grammar-workarounds.js.map +1 -0
  145. package/dist/facts/arrow.d.ts +106 -0
  146. package/dist/facts/arrow.d.ts.map +1 -0
  147. package/dist/facts/arrow.js +196 -0
  148. package/dist/facts/arrow.js.map +1 -0
  149. package/dist/facts/facts2.d.ts +68 -0
  150. package/dist/facts/facts2.d.ts.map +1 -0
  151. package/dist/facts/facts2.js +379 -0
  152. package/dist/facts/facts2.js.map +1 -0
  153. package/dist/facts/index.d.ts +22 -0
  154. package/dist/facts/index.d.ts.map +1 -0
  155. package/dist/facts/index.js +15 -0
  156. package/dist/facts/index.js.map +1 -0
  157. package/dist/facts/java-facts.d.ts +56 -0
  158. package/dist/facts/java-facts.d.ts.map +1 -0
  159. package/dist/facts/java-facts.js +250 -0
  160. package/dist/facts/java-facts.js.map +1 -0
  161. package/dist/facts/order.d.ts +39 -0
  162. package/dist/facts/order.d.ts.map +1 -0
  163. package/dist/facts/order.js +120 -0
  164. package/dist/facts/order.js.map +1 -0
  165. package/dist/facts/schema.d.ts +60 -0
  166. package/dist/facts/schema.d.ts.map +1 -0
  167. package/dist/facts/schema.js +126 -0
  168. package/dist/facts/schema.js.map +1 -0
  169. package/dist/facts/schema2.d.ts +47 -0
  170. package/dist/facts/schema2.d.ts.map +1 -0
  171. package/dist/facts/schema2.js +194 -0
  172. package/dist/facts/schema2.js.map +1 -0
  173. package/dist/facts/t6.d.ts +84 -0
  174. package/dist/facts/t6.d.ts.map +1 -0
  175. package/dist/facts/t6.js +226 -0
  176. package/dist/facts/t6.js.map +1 -0
  177. package/dist/facts/table.d.ts +80 -0
  178. package/dist/facts/table.d.ts.map +1 -0
  179. package/dist/facts/table.js +548 -0
  180. package/dist/facts/table.js.map +1 -0
  181. package/dist/graph-facts/dead-code.d.ts +2 -0
  182. package/dist/graph-facts/dead-code.d.ts.map +1 -1
  183. package/dist/graph-facts/dead-code.js +4 -3
  184. package/dist/graph-facts/dead-code.js.map +1 -1
  185. package/dist/graph-facts/index.d.ts +1 -1
  186. package/dist/graph-facts/index.d.ts.map +1 -1
  187. package/dist/graph-facts/index.js +1 -1
  188. package/dist/graph-facts/index.js.map +1 -1
  189. package/dist/graph-facts/reach.d.ts +53 -8
  190. package/dist/graph-facts/reach.d.ts.map +1 -1
  191. package/dist/graph-facts/reach.js +172 -16
  192. package/dist/graph-facts/reach.js.map +1 -1
  193. package/dist/graph-facts/removal-reach.d.ts +2 -0
  194. package/dist/graph-facts/removal-reach.d.ts.map +1 -1
  195. package/dist/graph-facts/removal-reach.js +1 -1
  196. package/dist/graph-facts/removal-reach.js.map +1 -1
  197. package/dist/index.d.ts +15 -7
  198. package/dist/index.d.ts.map +1 -1
  199. package/dist/index.js +19 -4
  200. package/dist/index.js.map +1 -1
  201. package/dist/navigation/index.d.ts +1 -0
  202. package/dist/navigation/index.d.ts.map +1 -1
  203. package/dist/navigation/index.js +1 -0
  204. package/dist/navigation/index.js.map +1 -1
  205. package/dist/navigation/java-graph.d.ts +47 -2
  206. package/dist/navigation/java-graph.d.ts.map +1 -1
  207. package/dist/navigation/java-graph.js +395 -18
  208. package/dist/navigation/java-graph.js.map +1 -1
  209. package/dist/navigation/java-registrations.d.ts +93 -0
  210. package/dist/navigation/java-registrations.d.ts.map +1 -0
  211. package/dist/navigation/java-registrations.js +254 -0
  212. package/dist/navigation/java-registrations.js.map +1 -0
  213. package/dist/navigation/navigation-index.d.ts +74 -3
  214. package/dist/navigation/navigation-index.d.ts.map +1 -1
  215. package/dist/navigation/navigation-index.js +206 -11
  216. package/dist/navigation/navigation-index.js.map +1 -1
  217. package/dist/navigation/ts-call-edges.d.ts +15 -0
  218. package/dist/navigation/ts-call-edges.d.ts.map +1 -1
  219. package/dist/navigation/ts-call-edges.js.map +1 -1
  220. package/dist/navigation/ts-entry-tables.d.ts +1 -1
  221. package/dist/navigation/ts-entry-tables.d.ts.map +1 -1
  222. package/dist/navigation/ts-entry-tables.js.map +1 -1
  223. package/dist/navigation/xml-scan.d.ts +40 -0
  224. package/dist/navigation/xml-scan.d.ts.map +1 -0
  225. package/dist/navigation/xml-scan.js +269 -0
  226. package/dist/navigation/xml-scan.js.map +1 -0
  227. package/dist/resolution/cross-file.d.ts +44 -0
  228. package/dist/resolution/cross-file.d.ts.map +1 -1
  229. package/dist/resolution/cross-file.js +259 -13
  230. package/dist/resolution/cross-file.js.map +1 -1
  231. package/dist/stable-ids/files.d.ts +22 -0
  232. package/dist/stable-ids/files.d.ts.map +1 -0
  233. package/dist/stable-ids/files.js +28 -0
  234. package/dist/stable-ids/files.js.map +1 -0
  235. package/dist/stable-ids/hash.d.ts +16 -4
  236. package/dist/stable-ids/hash.d.ts.map +1 -1
  237. package/dist/stable-ids/hash.js +266 -80
  238. package/dist/stable-ids/hash.js.map +1 -1
  239. package/dist/stable-ids/index.d.ts +6 -5
  240. package/dist/stable-ids/index.d.ts.map +1 -1
  241. package/dist/stable-ids/index.js +19 -6
  242. package/dist/stable-ids/index.js.map +1 -1
  243. package/dist/stable-ids/nodes.d.ts +61 -7
  244. package/dist/stable-ids/nodes.d.ts.map +1 -1
  245. package/dist/stable-ids/nodes.js +134 -21
  246. package/dist/stable-ids/nodes.js.map +1 -1
  247. package/dist/stable-ids/ts-parse-errors.d.ts +5 -1
  248. package/dist/stable-ids/ts-parse-errors.d.ts.map +1 -1
  249. package/dist/stable-ids/ts-parse-errors.js +55 -3
  250. package/dist/stable-ids/ts-parse-errors.js.map +1 -1
  251. package/dist/stable-ids/typescript.d.ts +5 -0
  252. package/dist/stable-ids/typescript.d.ts.map +1 -1
  253. package/dist/stable-ids/typescript.js +41 -8
  254. package/dist/stable-ids/typescript.js.map +1 -1
  255. package/dist/types/index.d.ts +21 -3
  256. package/dist/types/index.d.ts.map +1 -1
  257. package/dist/types/index.js +1 -0
  258. package/dist/types/index.js.map +1 -1
  259. package/docs/SPEC.md +9 -0
  260. package/package.json +9 -5
  261. package/schemas/facts@1.json +134 -0
  262. package/schemas/facts@2.json +216 -0
@@ -0,0 +1,250 @@
1
+ /**
2
+ * `facts@1` rows from a `java-graph@0.1` graph: a post-pass over today's
3
+ * structures (graph-store plan T2, first half). The graph is a view of the
4
+ * same facts, so every count here equals one of the graph's *before* the set
5
+ * dedupe: `decl` rows = declarations over `files`, `call` = `edges`,
6
+ * `unresolved` = `unresolved`, `entries` = `entries`, `files` = `files`,
7
+ * `imports` = the files' import declarations, `flow` = the DFG uses with a
8
+ * reaching definition; the manifest's `duplicates_dropped` is the
9
+ * difference. `moved` is empty from one snapshot (see `schemas/facts@1.json`).
10
+ *
11
+ * `flow` rows are keyed by `ids@0.1` node ids in their fixed-width form
12
+ * (`nodeIdBytes`): each DFG def and use is placed in the innermost
13
+ * declaration body enclosing it and numbered there (`locateNodes`), so an
14
+ * edit to one method leaves every other method's flow rows unchanged.
15
+ *
16
+ * Built as columns, never as row objects: each relation's typed arrays are
17
+ * filled straight from the graph, then `canonicalTable` sorts one index
18
+ * permutation, drops duplicates and gathers.
19
+ */
20
+ import { blake3, digest128 } from '../stable-ids/hash.js';
21
+ import { NodeIdWriter, locateNodes } from '../stable-ids/nodes.js';
22
+ import { STABLE_ID_SCHEME } from '../stable-ids/types.js';
23
+ import { compareCodePoints } from './order.js';
24
+ import { FACTS_ID_WIDTH, FACTS_RELATION_NAMES, FACTS_RELATIONS, } from './schema.js';
25
+ import { IdDecoder, allocTable, canonicalTable, dictIndex } from './table.js';
26
+ const encoder = new TextEncoder();
27
+ /** blake3 of the UTF-8 bytes, first 16. */
28
+ export function contentHash(code) {
29
+ return blake3(encoder.encode(code)).subarray(0, FACTS_ID_WIDTH);
30
+ }
31
+ /** The engine's `entry-index@0.1` kind as the `facts@1` vocabulary writes it: `bean` is `di`. */
32
+ export function factsEntryKind(kind) {
33
+ return kind === 'bean' ? 'di' : kind;
34
+ }
35
+ function dict(relation, column) {
36
+ return dictIndex(relation.columns.find(c => c.name === column));
37
+ }
38
+ function code(d, value, column) {
39
+ const k = d.get(value);
40
+ if (k === undefined)
41
+ throw new Error(`facts@1: ${JSON.stringify(value)} is not in the ${column} vocabulary`);
42
+ return k;
43
+ }
44
+ /**
45
+ * The eight relations, each a canonical set, with the dedupe counts
46
+ * (`FactSet`). `inputs` must cover every file of the graph (a file the graph
47
+ * names but the inputs do not is an error, never a silent gap). File ids are
48
+ * the 0-based positions in the code-point-sorted path list.
49
+ */
50
+ export function javaGraphFactSet(graph, inputs) {
51
+ if (graph.ids !== 'ids@0.1')
52
+ throw new Error(`facts@1: graph ids are ${String(graph.ids)}, not ids@0.1`);
53
+ const paths = [...new Set(inputs.map(i => i.path))].sort(compareCodePoints);
54
+ const fileId = new Map(paths.map((p, i) => [p, i]));
55
+ const byPath = new Map(inputs.map(i => [i.path, i]));
56
+ const fid = (path) => {
57
+ const id = fileId.get(path);
58
+ if (id === undefined)
59
+ throw new Error(`facts@1: ${path} is in the graph but not in the inputs`);
60
+ return id;
61
+ };
62
+ const R = FACTS_RELATIONS;
63
+ const ids = new IdDecoder();
64
+ // files
65
+ const files = allocTable(R.files, paths.length);
66
+ {
67
+ const language = code(dict(R.files, 'language'), 'java', 'language');
68
+ for (let i = 0; i < paths.length; i++) {
69
+ files[0][i] = i;
70
+ files[1][i] = paths[i];
71
+ files[2].set(contentHash(byPath.get(paths[i]).code), i * FACTS_ID_WIDTH);
72
+ files[3][i] = language;
73
+ }
74
+ }
75
+ // decl — in file order (code point), the order the duplicate rule counts in.
76
+ const graphFiles = new Map(graph.files.map(f => [f.file, f]));
77
+ const orderedFiles = paths.map(p => graphFiles.get(p)).filter((f) => f !== undefined);
78
+ for (const f of graph.files)
79
+ if (!fileId.has(f.file))
80
+ fid(f.file);
81
+ const declCount = orderedFiles.reduce((n, f) => n + f.decls.length, 0);
82
+ const decl = allocTable(R.decl, declCount);
83
+ const rekey = new Map();
84
+ {
85
+ const kinds = dict(R.decl, 'kind');
86
+ const seen = new Map();
87
+ let i = 0;
88
+ for (const f of orderedFiles) {
89
+ const file = fid(f.file);
90
+ for (const d of f.decls) {
91
+ let id = d.id;
92
+ let qualifiedName = d.qualified_name;
93
+ const n = (seen.get(d.id) ?? 0) + 1;
94
+ seen.set(d.id, n);
95
+ if (n > 1) {
96
+ qualifiedName = `${d.qualified_name}#${n}`;
97
+ id = digest128([STABLE_ID_SCHEME, f.language, d.kind, qualifiedName, d.signature]);
98
+ let m = rekey.get(f.file);
99
+ if (!m)
100
+ rekey.set(f.file, (m = new Map()));
101
+ m.set(d.id, { id, qualifiedName });
102
+ }
103
+ ids.put(id, decl[0], i * FACTS_ID_WIDTH);
104
+ decl[1][i] = code(kinds, d.kind, 'kind');
105
+ decl[2][i] = qualifiedName;
106
+ decl[3][i] = d.signature;
107
+ decl[4][i] = file;
108
+ decl[5][i] = d.start_line;
109
+ // No nulls in facts@1: all-zero bytes when the engine derived no body hash (the array starts zeroed).
110
+ if (d.body_hash)
111
+ ids.put(d.body_hash, decl[6], i * FACTS_ID_WIDTH);
112
+ i++;
113
+ }
114
+ }
115
+ }
116
+ const callerId = (file, id) => (rekey.size > 0 ? rekey.get(file)?.get(id)?.id ?? id : id);
117
+ // flow — def-use edges on fixed-width node ids, one row per DFG use with a
118
+ // reaching definition the same file holds.
119
+ const flowCapacity = orderedFiles.reduce((n, f) => n + (byPath.get(f.file).dfg?.uses.length ?? 0), 0);
120
+ const flow = allocTable(R.flow, flowCapacity);
121
+ let flowCount = 0;
122
+ if (flowCapacity > 0) {
123
+ const defUse = code(dict(R.flow, 'kind'), 'def-use', 'kind');
124
+ const writer = new NodeIdWriter();
125
+ const from = flow[0];
126
+ const to = flow[1];
127
+ const kinds = flow[2];
128
+ for (const f of orderedFiles) {
129
+ const dfg = byPath.get(f.file).dfg;
130
+ if (!dfg || dfg.uses.length === 0)
131
+ continue;
132
+ const rekeyed = rekey.get(f.file);
133
+ const bodyId = (d) => {
134
+ const r = rekeyed?.get(d.id);
135
+ return r ? `${r.id}.${d.body_hash}` : d.body_id;
136
+ };
137
+ // Every def's node id, once; `defAt[def.id]` is its offset in `defIds`, −1 when the def has no body.
138
+ const defs = locateNodes(f, dfg.defs, (d, at) => at(d.line, d.column));
139
+ const defIds = new Uint8Array(defs.length * FACTS_ID_WIDTH);
140
+ const defAt = new Map();
141
+ for (let i = 0; i < defs.length; i++) {
142
+ const n = defs[i];
143
+ if (n === null)
144
+ continue;
145
+ writer.forBody(bodyId(n.decl), 'def');
146
+ writer.write(n.ordinal, defIds, i * FACTS_ID_WIDTH);
147
+ defAt.set(dfg.defs[i].id, i * FACTS_ID_WIDTH);
148
+ }
149
+ const uses = locateNodes(f, dfg.uses, (u, at) => at(u.line, u.column));
150
+ for (let i = 0; i < uses.length; i++) {
151
+ const n = uses[i];
152
+ const u = dfg.uses[i];
153
+ if (n === null || u.def_id === null)
154
+ continue;
155
+ const d = defAt.get(u.def_id);
156
+ if (d === undefined)
157
+ continue;
158
+ const o = flowCount * FACTS_ID_WIDTH;
159
+ for (let k = 0; k < FACTS_ID_WIDTH; k++)
160
+ from[o + k] = defIds[d + k];
161
+ writer.forBody(bodyId(n.decl), 'use');
162
+ writer.write(n.ordinal, to, o);
163
+ kinds[flowCount] = defUse;
164
+ flowCount++;
165
+ }
166
+ }
167
+ }
168
+ // call
169
+ const call = allocTable(R.call, graph.edges.length);
170
+ {
171
+ const tiers = dict(R.call, 'tier');
172
+ for (let i = 0; i < graph.edges.length; i++) {
173
+ const e = graph.edges[i];
174
+ ids.put(callerId(e.site.file, e.from), call[0], i * FACTS_ID_WIDTH);
175
+ ids.put(e.to, call[1], i * FACTS_ID_WIDTH);
176
+ call[2][i] = code(tiers, e.tier, 'tier');
177
+ call[3][i] = e.methodName;
178
+ call[4][i] = fid(e.site.file);
179
+ call[5][i] = e.site.line;
180
+ call[6][i] = e.site.col;
181
+ }
182
+ }
183
+ // unresolved
184
+ const unresolved = allocTable(R.unresolved, graph.unresolved.length);
185
+ {
186
+ const reasons = dict(R.unresolved, 'reason');
187
+ for (let i = 0; i < graph.unresolved.length; i++) {
188
+ const u = graph.unresolved[i];
189
+ ids.put(callerId(u.site.file, u.from), unresolved[0], i * FACTS_ID_WIDTH);
190
+ unresolved[1][i] = code(reasons, u.reason, 'reason');
191
+ // No nulls in facts@1: the empty string when the receiver is unknown.
192
+ unresolved[2][i] = u.receiver ?? '';
193
+ unresolved[3][i] = u.methodName;
194
+ unresolved[4][i] = fid(u.site.file);
195
+ unresolved[5][i] = u.site.line;
196
+ unresolved[6][i] = u.site.col;
197
+ }
198
+ }
199
+ // imports
200
+ const importCount = paths.reduce((n, p) => n + byPath.get(p).imports.length, 0);
201
+ const imports = allocTable(R.imports, importCount);
202
+ {
203
+ let i = 0;
204
+ for (const p of paths) {
205
+ const file = fid(p);
206
+ for (const imp of byPath.get(p).imports) {
207
+ imports[0][i] = file;
208
+ imports[1][i] = imp.target;
209
+ imports[2][i] = imp.wildcard ? 1 : 0;
210
+ i++;
211
+ }
212
+ }
213
+ }
214
+ // entries
215
+ const entries = allocTable(R.entries, graph.entries.length);
216
+ {
217
+ const kinds = dict(R.entries, 'kind');
218
+ const certainties = dict(R.entries, 'certainty');
219
+ for (let i = 0; i < graph.entries.length; i++) {
220
+ const e = graph.entries[i];
221
+ ids.put(e.id, entries[0], i * FACTS_ID_WIDTH);
222
+ entries[1][i] = code(kinds, factsEntryKind(e.kind), 'kind');
223
+ entries[2][i] = e.evidence;
224
+ entries[3][i] = code(certainties, e.certainty, 'certainty');
225
+ }
226
+ }
227
+ const raw = {
228
+ files: { columns: files, length: paths.length },
229
+ decl: { columns: decl, length: declCount },
230
+ call: { columns: call, length: graph.edges.length },
231
+ unresolved: { columns: unresolved, length: graph.unresolved.length },
232
+ flow: { columns: flow, length: flowCount },
233
+ imports: { columns: imports, length: importCount },
234
+ entries: { columns: entries, length: graph.entries.length },
235
+ moved: { columns: allocTable(R.moved, 0), length: 0 },
236
+ };
237
+ const relations = {};
238
+ const duplicatesDropped = {};
239
+ for (const name of FACTS_RELATION_NAMES) {
240
+ const { table, duplicatesDropped: dropped } = canonicalTable(R[name], raw[name].columns, raw[name].length);
241
+ relations[name] = table;
242
+ duplicatesDropped[name] = dropped;
243
+ }
244
+ return { relations, duplicatesDropped };
245
+ }
246
+ /** The eight relations as canonical sets (`javaGraphFactSet` without the dedupe counts). */
247
+ export function javaGraphFacts(graph, inputs) {
248
+ return javaGraphFactSet(graph, inputs).relations;
249
+ }
250
+ //# sourceMappingURL=java-facts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"java-facts.js","sourceRoot":"","sources":["../../src/facts/java-facts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAqB,MAAM,wBAAwB,CAAC;AAE7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,eAAe,GAGhB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,SAAS,EAAuC,MAAM,YAAY,CAAC;AAwBnH,MAAM,OAAO,GAA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AAS,EAAE;QAC1C,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE;QAClD,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE;QAC3D,KAAK,EAAE,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE;KACtD,CAAC;IACF,MAAM,SAAS,GAAG,EAA0C,CAAC;IAC7D,MAAM,iBAAiB,GAAG,EAAuC,CAAC;IAClE,KAAK,MAAM,IAAI,IAAI,oBAAoB,EAAE,CAAC;QACxC,MAAM,EAAE,KAAK,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC;QAC3G,SAAS,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QACxB,iBAAiB,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;IACpC,CAAC;IACD,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,CAAC;AAC1C,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,cAAc,CAAC,KAAgB,EAAE,MAAiC;IAChF,OAAO,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,SAAS,CAAC;AACnD,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * The `facts@1` canonical order: a total order on the rows of one relation,
3
+ * so two runs over the same facts put them in the same sequence and the
4
+ * bytes that follow are identical.
5
+ *
6
+ * Cells compare by type — id bytes unsigned bytewise, integers numerically,
7
+ * strings by Unicode code point (which is UTF-8 byte order, so a Rust reader
8
+ * sorting the raw bytes agrees), booleans false before true, null before any
9
+ * value (a dead branch: `facts@1` has no nullable column) — and rows by the
10
+ * key columns first, then every remaining column in schema order. Two rows
11
+ * compare equal only when every cell is equal; relations are sets, so equal
12
+ * rows collapse to one (`canonicalSet`).
13
+ */
14
+ import { type FactRow, type FactValue, type FactsRelation } from './schema.js';
15
+ /** Unsigned bytewise order; a shorter array that is a prefix sorts first. */
16
+ export declare function compareBytes(a: Uint8Array, b: Uint8Array): number;
17
+ /** Code point order (UTF-8 byte order), not UTF-16 code unit order. */
18
+ export declare function compareCodePoints(a: string, b: string): number;
19
+ /** Order on one cell; the two cells must be of the same column. */
20
+ export declare function compareValues(a: FactValue, b: FactValue): number;
21
+ /** The row comparator of a relation: key columns, then the remaining columns in schema order. */
22
+ export declare function rowComparator(relation: FactsRelation): (a: FactRow, b: FactRow) => number;
23
+ /** `rows` sorted in canonical order (a new array); duplicates kept. */
24
+ export declare function canonicalRows(relation: FactsRelation, rows: readonly FactRow[]): FactRow[];
25
+ /**
26
+ * `rows` as a canonical set: sorted, exact duplicates (equal under the total
27
+ * order) dropped and counted. The row-form reference for what the emitter
28
+ * does on columns (`canonicalTable`).
29
+ */
30
+ export declare function canonicalSet(relation: FactsRelation, rows: readonly FactRow[]): {
31
+ rows: FactRow[];
32
+ duplicatesDropped: number;
33
+ };
34
+ /**
35
+ * The 16 bytes of an `ids@0.1` id (26 lowercase base32 characters, RFC 4648
36
+ * unpadded, the last character carrying 2 zero padding bits).
37
+ */
38
+ export declare function idBytes(id: string): Uint8Array;
39
+ //# sourceMappingURL=order.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order.d.ts","sourceRoot":"","sources":["../../src/facts/order.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAkB,KAAK,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAe,MAAM,aAAa,CAAC;AAE5G,6EAA6E;AAC7E,wBAAgB,YAAY,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,MAAM,CAMjE;AAED,uEAAuE;AACvE,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAa9D;AAED,mEAAmE;AACnE,wBAAgB,aAAa,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,GAAG,MAAM,CAQhE;AAED,iGAAiG;AACjG,wBAAgB,aAAa,CAAC,QAAQ,EAAE,aAAa,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,KAAK,MAAM,CASzF;AAED,uEAAuE;AACvE,wBAAgB,aAAa,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,OAAO,EAAE,GAAG,OAAO,EAAE,CAE1F;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,OAAO,EAAE,GAAG;IAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAA;CAAE,CAS9H;AAKD;;;GAGG;AACH,wBAAgB,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,UAAU,CAoB9C"}
@@ -0,0 +1,120 @@
1
+ /**
2
+ * The `facts@1` canonical order: a total order on the rows of one relation,
3
+ * so two runs over the same facts put them in the same sequence and the
4
+ * bytes that follow are identical.
5
+ *
6
+ * Cells compare by type — id bytes unsigned bytewise, integers numerically,
7
+ * strings by Unicode code point (which is UTF-8 byte order, so a Rust reader
8
+ * sorting the raw bytes agrees), booleans false before true, null before any
9
+ * value (a dead branch: `facts@1` has no nullable column) — and rows by the
10
+ * key columns first, then every remaining column in schema order. Two rows
11
+ * compare equal only when every cell is equal; relations are sets, so equal
12
+ * rows collapse to one (`canonicalSet`).
13
+ */
14
+ import { FACTS_ID_WIDTH, sortColumns } from './schema.js';
15
+ /** Unsigned bytewise order; a shorter array that is a prefix sorts first. */
16
+ export function compareBytes(a, b) {
17
+ const n = Math.min(a.length, b.length);
18
+ for (let i = 0; i < n; i++) {
19
+ if (a[i] !== b[i])
20
+ return a[i] < b[i] ? -1 : 1;
21
+ }
22
+ return a.length - b.length;
23
+ }
24
+ /** Code point order (UTF-8 byte order), not UTF-16 code unit order. */
25
+ export function compareCodePoints(a, b) {
26
+ if (a === b)
27
+ return 0;
28
+ let i = 0;
29
+ let j = 0;
30
+ while (i < a.length && j < b.length) {
31
+ const ca = a.codePointAt(i);
32
+ const cb = b.codePointAt(j);
33
+ if (ca !== cb)
34
+ return ca < cb ? -1 : 1;
35
+ i += ca > 0xffff ? 2 : 1;
36
+ j += cb > 0xffff ? 2 : 1;
37
+ }
38
+ if (i < a.length)
39
+ return 1;
40
+ return j < b.length ? -1 : 0;
41
+ }
42
+ /** Order on one cell; the two cells must be of the same column. */
43
+ export function compareValues(a, b) {
44
+ if (a === null)
45
+ return b === null ? 0 : -1;
46
+ if (b === null)
47
+ return 1;
48
+ if (typeof a === 'number' && typeof b === 'number')
49
+ return a < b ? -1 : a > b ? 1 : 0;
50
+ if (typeof a === 'string' && typeof b === 'string')
51
+ return compareCodePoints(a, b);
52
+ if (typeof a === 'boolean' && typeof b === 'boolean')
53
+ return a === b ? 0 : a ? 1 : -1;
54
+ if (a instanceof Uint8Array && b instanceof Uint8Array)
55
+ return compareBytes(a, b);
56
+ throw new Error(`facts@1: cells of different types in one column (${typeof a} vs ${typeof b})`);
57
+ }
58
+ /** The row comparator of a relation: key columns, then the remaining columns in schema order. */
59
+ export function rowComparator(relation) {
60
+ const order = sortColumns(relation);
61
+ return (a, b) => {
62
+ for (const i of order) {
63
+ const c = compareValues(a[i], b[i]);
64
+ if (c !== 0)
65
+ return c;
66
+ }
67
+ return 0;
68
+ };
69
+ }
70
+ /** `rows` sorted in canonical order (a new array); duplicates kept. */
71
+ export function canonicalRows(relation, rows) {
72
+ return [...rows].sort(rowComparator(relation));
73
+ }
74
+ /**
75
+ * `rows` as a canonical set: sorted, exact duplicates (equal under the total
76
+ * order) dropped and counted. The row-form reference for what the emitter
77
+ * does on columns (`canonicalTable`).
78
+ */
79
+ export function canonicalSet(relation, rows) {
80
+ const cmp = rowComparator(relation);
81
+ const sorted = [...rows].sort(cmp);
82
+ const out = [];
83
+ for (const r of sorted) {
84
+ if (out.length > 0 && cmp(out[out.length - 1], r) === 0)
85
+ continue;
86
+ out.push(r);
87
+ }
88
+ return { rows: out, duplicatesDropped: rows.length - out.length };
89
+ }
90
+ const BASE32 = 'abcdefghijklmnopqrstuvwxyz234567';
91
+ const BASE32_VALUE = new Map([...BASE32].map((c, i) => [c, i]));
92
+ /**
93
+ * The 16 bytes of an `ids@0.1` id (26 lowercase base32 characters, RFC 4648
94
+ * unpadded, the last character carrying 2 zero padding bits).
95
+ */
96
+ export function idBytes(id) {
97
+ if (id.length !== 26)
98
+ throw new Error(`facts@1: not an ids@0.1 id: ${JSON.stringify(id)}`);
99
+ const out = new Uint8Array(FACTS_ID_WIDTH);
100
+ let buffer = 0;
101
+ let bits = 0;
102
+ let n = 0;
103
+ for (const c of id) {
104
+ const v = BASE32_VALUE.get(c);
105
+ if (v === undefined)
106
+ throw new Error(`facts@1: not an ids@0.1 id: ${JSON.stringify(id)}`);
107
+ buffer = (buffer << 5) | v;
108
+ bits += 5;
109
+ if (bits >= 8) {
110
+ out[n++] = (buffer >>> (bits - 8)) & 0xff;
111
+ bits -= 8;
112
+ buffer &= (1 << bits) - 1;
113
+ }
114
+ }
115
+ // 26 × 5 = 130 bits: 128 bits of id and 2 padding bits, which must be zero.
116
+ if (bits !== 2 || buffer !== 0)
117
+ throw new Error(`facts@1: not an ids@0.1 id: ${JSON.stringify(id)}`);
118
+ return out;
119
+ }
120
+ //# sourceMappingURL=order.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order.js","sourceRoot":"","sources":["../../src/facts/order.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,cAAc,EAAoD,WAAW,EAAE,MAAM,aAAa,CAAC;AAE5G,6EAA6E;AAC7E,MAAM,UAAU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C,EAAE,CAAC,CAAC;IACrG,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * `facts@1` — the fact relations circle-ir owes a graph store, as columns in
3
+ * canonical order keyed by `ids@0.1` (graph-store plan 0.1, T1; contract per
4
+ * the 2026-11-01 reconciliation record, decisions 1–11, and the stable-ids
5
+ * decision 1a: `flow` endpoints are node ids in their fixed-width form).
6
+ *
7
+ * Relations are **sets** with **no nulls**: the producer deduplicates after
8
+ * the canonical sort and reports what it dropped; "none" is a sentinel
9
+ * (`unresolved.receiver` empty, `decl.body_hash` all-zero bytes).
10
+ *
11
+ * This module mirrors `schemas/facts@1.json` field for field;
12
+ * `tests/facts/schema.test.ts` fails when the two drift. The JSON file is the
13
+ * document other implementations read; this module is what the emitter and
14
+ * the comparator run on. Nothing in `analyze()` or `buildJavaGraph()` touches
15
+ * it unless a caller asks for facts.
16
+ */
17
+ export declare const FACTS_SCHEME: 'facts@1';
18
+ export type FactsScheme = typeof FACTS_SCHEME;
19
+ /** Width in bytes of an `ids@0.1` id in a column (128 bits). */
20
+ export declare const FACTS_ID_WIDTH = 16;
21
+ /** Rows per record batch after the canonical sort. */
22
+ export declare const FACTS_CHUNK_ROWS = 65536;
23
+ export type FactsColumnType = 'fixed16' | 'u32' | 'utf8' | 'bool' | 'dict';
24
+ export interface FactsColumn {
25
+ readonly name: string;
26
+ readonly type: FactsColumnType;
27
+ /** Always `false` in `facts@1` (no nulls); kept so the schema file and the Arrow fields state it. */
28
+ readonly nullable: boolean;
29
+ /** `dict` columns: the whole vocabulary, in dictionary order. */
30
+ readonly values?: readonly string[];
31
+ }
32
+ export interface FactsRelation {
33
+ /** Sort keys, in order. The remaining columns follow in schema order. */
34
+ readonly key: readonly string[];
35
+ readonly columns: readonly FactsColumn[];
36
+ }
37
+ export declare const FACTS_RELATION_NAMES: readonly ['files', 'decl', 'call', 'unresolved', 'flow', 'imports', 'entries', 'moved'];
38
+ export type FactsRelationName = (typeof FACTS_RELATION_NAMES)[number];
39
+ export declare const FACTS_LANGUAGES: readonly ['java', 'typescript', 'javascript', 'python', 'go'];
40
+ export declare const FACTS_DECL_KINDS: readonly ['module', 'type', 'method', 'field', 'function'];
41
+ export declare const FACTS_TIERS: readonly ['exact', 'polymorphic', 'inferred'];
42
+ export declare const FACTS_UNRESOLVED_REASONS: readonly ['external', 'dynamic', 'generated', 'overload-ambiguous', 'parse-error', 'unsupported-language', 'unknown'];
43
+ export declare const FACTS_FLOW_KINDS: readonly ['def-use', 'taint'];
44
+ /** The engine's `entry-index@0.1` kinds (its `bean` written as `di`) plus the design's data-declared kinds. */
45
+ export declare const FACTS_ENTRY_KINDS: readonly ['main', 'route', 'listener', 'scheduled', 'export', 'di', 'reflection', 'lifecycle', 'test', 'osgi-ds', 'extension-point', 'data-declared', 'script'];
46
+ export declare const FACTS_ENTRY_CERTAINTIES: readonly ['declared', 'conventional', 'inferred'];
47
+ export declare const FACTS_MOVE_KINDS: readonly ['moved', 'renamed'];
48
+ export declare const FACTS_RELATIONS: Readonly<Record<FactsRelationName, FactsRelation>>;
49
+ /** The column indexes a relation sorts by: its key columns, then every other column in schema order. */
50
+ export declare function sortColumns(relation: FactsRelation): number[];
51
+ /**
52
+ * A cell: 16 id bytes, an unsigned 32-bit integer, a string (utf8 and dict
53
+ * columns alike) or a boolean. `null` stays in the type for the comparator's
54
+ * null-first rule (a dead branch: `facts@1` has no nullable column).
55
+ */
56
+ export type FactValue = Uint8Array | number | string | boolean | null;
57
+ /** One row, cells in schema column order. */
58
+ export type FactRow = readonly FactValue[];
59
+ export type FactRows = Readonly<Record<FactsRelationName, FactRow[]>>;
60
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/facts/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,eAAO,MAAM,YAAY,EAAG,SAAkB,CAAC;AAC/C,MAAM,MAAM,WA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B,EAAE,SAAS,CAAU,CAAC;AAC9J,eAAO,MAAM,gBAAgB,YAAI,SAAS,EAAE,OAAO,CAAU,CAAC;AAC9D,+GAA+G;AAC/G,eAAO,MAAM,iBAAiB,YAAI,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,iBAAiB,EAAE,eAAe,EAAE,QAAQ,CAAU,CAAC;AACjM,eAAO,MAAM,uBAAuB,YAAI,UAAU,EAAE,cAAc,EAAE,UAAU,CAAU,CAAC;AACzF,eAAO,MAAM,gBAAgB,YAAI,OAAO,EAAE,SAAS,CAAU,CAAC;AAK9D,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,iBAAiB,EAAE,aAAa,CAAC,CAiF9E,CAAC;AAEF,wGAAwG;AACxG,wBAAgB,WAAW,CAAC,QAAQ,EAAE,aAAa,GAAG,MAAM,EAAE,CAQ7D;AAED;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAEtE,6CAA6C;AAC7C,MAAM,MAAM,OAAO,GAAG,SAAS,SAAS,EAAE,CAAC;AAE3C,MAAM,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,iBAAiB,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC"}
@@ -0,0 +1,126 @@
1
+ /**
2
+ * `facts@1` — the fact relations circle-ir owes a graph store, as columns in
3
+ * canonical order keyed by `ids@0.1` (graph-store plan 0.1, T1; contract per
4
+ * the 2026-11-01 reconciliation record, decisions 1–11, and the stable-ids
5
+ * decision 1a: `flow` endpoints are node ids in their fixed-width form).
6
+ *
7
+ * Relations are **sets** with **no nulls**: the producer deduplicates after
8
+ * the canonical sort and reports what it dropped; "none" is a sentinel
9
+ * (`unresolved.receiver` empty, `decl.body_hash` all-zero bytes).
10
+ *
11
+ * This module mirrors `schemas/facts@1.json` field for field;
12
+ * `tests/facts/schema.test.ts` fails when the two drift. The JSON file is the
13
+ * document other implementations read; this module is what the emitter and
14
+ * the comparator run on. Nothing in `analyze()` or `buildJavaGraph()` touches
15
+ * it unless a caller asks for facts.
16
+ */
17
+ export const FACTS_SCHEME = 'facts@1';
18
+ /** Width in bytes of an `ids@0.1` id in a column (128 bits). */
19
+ export const FACTS_ID_WIDTH = 16;
20
+ /** Rows per record batch after the canonical sort. */
21
+ export const FACTS_CHUNK_ROWS = 65536;
22
+ export const FACTS_RELATION_NAMES = ['files', 'decl', 'call', 'unresolved', 'flow', 'imports', 'entries', 'moved'];
23
+ export const FACTS_LANGUAGES = ['java', 'typescript', 'javascript', 'python', 'go'];
24
+ export const FACTS_DECL_KINDS = ['module', 'type', 'method', 'field', 'function'];
25
+ export const FACTS_TIERS = ['exact', 'polymorphic', 'inferred'];
26
+ export const FACTS_UNRESOLVED_REASONS = ['external', 'dynamic', 'generated', 'overload-ambiguous', 'parse-error', 'unsupported-language', 'unknown'];
27
+ export const FACTS_FLOW_KINDS = ['def-use', 'taint'];
28
+ /** The engine's `entry-index@0.1` kinds (its `bean` written as `di`) plus the design's data-declared kinds. */
29
+ export const FACTS_ENTRY_KINDS = ['main', 'route', 'listener', 'scheduled', 'export', 'di', 'reflection', 'lifecycle', 'test', 'osgi-ds', 'extension-point', 'data-declared', 'script'];
30
+ export const FACTS_ENTRY_CERTAINTIES = ['declared', 'conventional', 'inferred'];
31
+ export const FACTS_MOVE_KINDS = ['moved', 'renamed'];
32
+ const col = (name, type, nullable = false, values) => values ? { name, type, nullable, values } : { name, type, nullable };
33
+ export const FACTS_RELATIONS = {
34
+ files: {
35
+ key: ['file_id'],
36
+ columns: [
37
+ col('file_id', 'u32'),
38
+ col('path', 'utf8'),
39
+ col('content_hash', 'fixed16'),
40
+ col('language', 'dict', false, FACTS_LANGUAGES),
41
+ ],
42
+ },
43
+ decl: {
44
+ key: ['id'],
45
+ columns: [
46
+ col('id', 'fixed16'),
47
+ col('kind', 'dict', false, FACTS_DECL_KINDS),
48
+ col('qualified_name', 'utf8'),
49
+ col('signature', 'utf8'),
50
+ col('file_id', 'u32'),
51
+ col('line', 'u32'),
52
+ col('body_hash', 'fixed16'),
53
+ ],
54
+ },
55
+ call: {
56
+ key: ['caller_id', 'site_file', 'site_line', 'site_col', 'callee_id'],
57
+ columns: [
58
+ col('caller_id', 'fixed16'),
59
+ col('callee_id', 'fixed16'),
60
+ col('tier', 'dict', false, FACTS_TIERS),
61
+ col('method_name', 'utf8'),
62
+ col('site_file', 'u32'),
63
+ col('site_line', 'u32'),
64
+ col('site_col', 'u32'),
65
+ ],
66
+ },
67
+ unresolved: {
68
+ key: ['site_file', 'site_line', 'site_col', 'method_name', 'receiver', 'reason'],
69
+ columns: [
70
+ col('caller_id', 'fixed16'),
71
+ col('reason', 'dict', false, FACTS_UNRESOLVED_REASONS),
72
+ col('receiver', 'utf8'),
73
+ col('method_name', 'utf8'),
74
+ col('site_file', 'u32'),
75
+ col('site_line', 'u32'),
76
+ col('site_col', 'u32'),
77
+ ],
78
+ },
79
+ // Endpoints are ids@0.1 node ids in their fixed-width form (`nodeIdBytes`; the schema file's `node_id`).
80
+ flow: {
81
+ key: ['from_id', 'to_id', 'kind'],
82
+ columns: [
83
+ col('from_id', 'fixed16'),
84
+ col('to_id', 'fixed16'),
85
+ col('kind', 'dict', false, FACTS_FLOW_KINDS),
86
+ ],
87
+ },
88
+ imports: {
89
+ key: ['file_id', 'target', 'wildcard'],
90
+ columns: [
91
+ col('file_id', 'u32'),
92
+ col('target', 'utf8'),
93
+ col('wildcard', 'bool'),
94
+ ],
95
+ },
96
+ entries: {
97
+ key: ['decl_id', 'kind', 'source'],
98
+ columns: [
99
+ col('decl_id', 'fixed16'),
100
+ col('kind', 'dict', false, FACTS_ENTRY_KINDS),
101
+ col('source', 'utf8'),
102
+ col('certainty', 'dict', false, FACTS_ENTRY_CERTAINTIES),
103
+ ],
104
+ },
105
+ moved: {
106
+ key: ['old_id', 'new_id'],
107
+ columns: [
108
+ col('old_id', 'fixed16'),
109
+ col('new_id', 'fixed16'),
110
+ col('kind', 'dict', false, FACTS_MOVE_KINDS),
111
+ col('evidence', 'utf8'),
112
+ ],
113
+ },
114
+ };
115
+ /** The column indexes a relation sorts by: its key columns, then every other column in schema order. */
116
+ export function sortColumns(relation) {
117
+ const names = relation.columns.map(c => c.name);
118
+ const keys = relation.key.map(k => {
119
+ const i = names.indexOf(k);
120
+ if (i < 0)
121
+ throw new Error(`facts@1: key column ${k} is not a column`);
122
+ return i;
123
+ });
124
+ return [...keys, ...names.map((_, i) => i).filter(i => !keys.includes(i))];
125
+ }
126
+ //# sourceMappingURL=schema.js.map