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.
- package/dist/analysis/advisories.d.ts +21 -3
- package/dist/analysis/advisories.d.ts.map +1 -1
- package/dist/analysis/advisories.js +26 -8
- package/dist/analysis/advisories.js.map +1 -1
- package/dist/analysis/arg-executing-programs.d.ts +16 -0
- package/dist/analysis/arg-executing-programs.d.ts.map +1 -0
- package/dist/analysis/arg-executing-programs.js +24 -0
- package/dist/analysis/arg-executing-programs.js.map +1 -0
- package/dist/analysis/config-loader.d.ts.map +1 -1
- package/dist/analysis/config-loader.js +27 -3
- package/dist/analysis/config-loader.js.map +1 -1
- package/dist/analysis/constant-caller-gate.d.ts +3 -1
- package/dist/analysis/constant-caller-gate.d.ts.map +1 -1
- package/dist/analysis/constant-caller-gate.js +108 -1
- package/dist/analysis/constant-caller-gate.js.map +1 -1
- package/dist/analysis/constant-propagation/index.d.ts.map +1 -1
- package/dist/analysis/constant-propagation/index.js +1 -1
- package/dist/analysis/constant-propagation/index.js.map +1 -1
- package/dist/analysis/constant-propagation/patterns.d.ts.map +1 -1
- package/dist/analysis/constant-propagation/patterns.js +8 -0
- package/dist/analysis/constant-propagation/patterns.js.map +1 -1
- package/dist/analysis/constant-propagation/propagator.d.ts +47 -2
- package/dist/analysis/constant-propagation/propagator.d.ts.map +1 -1
- package/dist/analysis/constant-propagation/propagator.js +422 -57
- package/dist/analysis/constant-propagation/propagator.js.map +1 -1
- package/dist/analysis/constant-propagation/types.d.ts +2 -0
- package/dist/analysis/constant-propagation/types.d.ts.map +1 -1
- package/dist/analysis/dependency-versions.d.ts +33 -0
- package/dist/analysis/dependency-versions.d.ts.map +1 -1
- package/dist/analysis/dependency-versions.js +70 -0
- package/dist/analysis/dependency-versions.js.map +1 -1
- package/dist/analysis/findings.d.ts.map +1 -1
- package/dist/analysis/findings.js +7 -5
- package/dist/analysis/findings.js.map +1 -1
- package/dist/analysis/interprocedural.d.ts +16 -0
- package/dist/analysis/interprocedural.d.ts.map +1 -1
- package/dist/analysis/interprocedural.js +545 -197
- package/dist/analysis/interprocedural.js.map +1 -1
- package/dist/analysis/passes/constant-propagation-pass.d.ts.map +1 -1
- package/dist/analysis/passes/constant-propagation-pass.js +1 -0
- package/dist/analysis/passes/constant-propagation-pass.js.map +1 -1
- package/dist/analysis/passes/cross-file-pass.d.ts.map +1 -1
- package/dist/analysis/passes/cross-file-pass.js +61 -0
- package/dist/analysis/passes/cross-file-pass.js.map +1 -1
- package/dist/analysis/passes/csharp-sanitizer-credit.d.ts.map +1 -1
- package/dist/analysis/passes/csharp-sanitizer-credit.js +60 -3
- package/dist/analysis/passes/csharp-sanitizer-credit.js.map +1 -1
- package/dist/analysis/passes/csrf-samesite-none-session-pass.d.ts +58 -0
- package/dist/analysis/passes/csrf-samesite-none-session-pass.d.ts.map +1 -0
- package/dist/analysis/passes/csrf-samesite-none-session-pass.js +159 -0
- package/dist/analysis/passes/csrf-samesite-none-session-pass.js.map +1 -0
- package/dist/analysis/passes/deserialization-safety-gate-pass.d.ts +15 -0
- package/dist/analysis/passes/deserialization-safety-gate-pass.d.ts.map +1 -1
- package/dist/analysis/passes/deserialization-safety-gate-pass.js +60 -1
- package/dist/analysis/passes/deserialization-safety-gate-pass.js.map +1 -1
- package/dist/analysis/passes/interprocedural-pass.d.ts +23 -1
- package/dist/analysis/passes/interprocedural-pass.d.ts.map +1 -1
- package/dist/analysis/passes/interprocedural-pass.js +220 -7
- package/dist/analysis/passes/interprocedural-pass.js.map +1 -1
- package/dist/analysis/passes/language-sources-pass.d.ts +0 -18
- package/dist/analysis/passes/language-sources-pass.d.ts.map +1 -1
- package/dist/analysis/passes/language-sources-pass.js +549 -22
- package/dist/analysis/passes/language-sources-pass.js.map +1 -1
- package/dist/analysis/passes/param-source-flow-gate-pass.d.ts.map +1 -1
- package/dist/analysis/passes/param-source-flow-gate-pass.js +71 -1
- package/dist/analysis/passes/param-source-flow-gate-pass.js.map +1 -1
- package/dist/analysis/passes/prompt-injection-safety-gate-pass.js +1 -1
- package/dist/analysis/passes/prompt-injection-safety-gate-pass.js.map +1 -1
- package/dist/analysis/passes/resource-leak-pass.d.ts.map +1 -1
- package/dist/analysis/passes/resource-leak-pass.js +15 -3
- package/dist/analysis/passes/resource-leak-pass.js.map +1 -1
- package/dist/analysis/passes/scan-secrets-pass.js +2 -2
- package/dist/analysis/passes/scan-secrets-pass.js.map +1 -1
- package/dist/analysis/passes/sensitive-data-in-log-pass.d.ts +66 -0
- package/dist/analysis/passes/sensitive-data-in-log-pass.d.ts.map +1 -0
- package/dist/analysis/passes/sensitive-data-in-log-pass.js +462 -0
- package/dist/analysis/passes/sensitive-data-in-log-pass.js.map +1 -0
- package/dist/analysis/passes/sink-filter-pass.d.ts +7 -1
- package/dist/analysis/passes/sink-filter-pass.d.ts.map +1 -1
- package/dist/analysis/passes/sink-filter-pass.js +564 -22
- package/dist/analysis/passes/sink-filter-pass.js.map +1 -1
- package/dist/analysis/passes/taint-propagation-pass.d.ts +7 -3
- package/dist/analysis/passes/taint-propagation-pass.d.ts.map +1 -1
- package/dist/analysis/passes/taint-propagation-pass.js +464 -27
- package/dist/analysis/passes/taint-propagation-pass.js.map +1 -1
- package/dist/analysis/passes/xml-entity-expansion-pass.d.ts.map +1 -1
- package/dist/analysis/passes/xml-entity-expansion-pass.js +50 -6
- package/dist/analysis/passes/xml-entity-expansion-pass.js.map +1 -1
- package/dist/analysis/pep440-version.d.ts +40 -0
- package/dist/analysis/pep440-version.d.ts.map +1 -0
- package/dist/analysis/pep440-version.js +149 -0
- package/dist/analysis/pep440-version.js.map +1 -0
- package/dist/analysis/project-callee-escape-gate.js +1 -1
- package/dist/analysis/project-callee-escape-gate.js.map +1 -1
- package/dist/analysis/rules.d.ts.map +1 -1
- package/dist/analysis/rules.js +15 -0
- package/dist/analysis/rules.js.map +1 -1
- package/dist/analysis/sbom.d.ts +92 -4
- package/dist/analysis/sbom.d.ts.map +1 -1
- package/dist/analysis/sbom.js +390 -33
- package/dist/analysis/sbom.js.map +1 -1
- package/dist/analysis/taint-matcher.d.ts.map +1 -1
- package/dist/analysis/taint-matcher.js +124 -19
- package/dist/analysis/taint-matcher.js.map +1 -1
- package/dist/analysis/taint-propagation.d.ts +1 -0
- package/dist/analysis/taint-propagation.d.ts.map +1 -1
- package/dist/analysis/taint-propagation.js +32 -0
- package/dist/analysis/taint-propagation.js.map +1 -1
- package/dist/analysis/test-to-production-taint-gate.d.ts +13 -0
- package/dist/analysis/test-to-production-taint-gate.d.ts.map +1 -0
- package/dist/analysis/test-to-production-taint-gate.js +30 -0
- package/dist/analysis/test-to-production-taint-gate.js.map +1 -0
- package/dist/analyzer.d.ts +21 -3
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/analyzer.js +83 -3
- package/dist/analyzer.js.map +1 -1
- package/dist/browser/circle-ir.js +8118 -2526
- package/dist/core/circle-ir-core.cjs +3098 -2280
- package/dist/core/circle-ir-core.js +3036 -2214
- package/dist/core/extractors/calls.d.ts +10 -1
- package/dist/core/extractors/calls.d.ts.map +1 -1
- package/dist/core/extractors/calls.js +148 -6
- package/dist/core/extractors/calls.js.map +1 -1
- package/dist/core/extractors/cfg.d.ts.map +1 -1
- package/dist/core/extractors/cfg.js +12 -0
- package/dist/core/extractors/cfg.js.map +1 -1
- package/dist/core/extractors/dfg.d.ts.map +1 -1
- package/dist/core/extractors/dfg.js +151 -18
- package/dist/core/extractors/dfg.js.map +1 -1
- package/dist/core/extractors/ts-declaration-detail.d.ts +8 -0
- package/dist/core/extractors/ts-declaration-detail.d.ts.map +1 -1
- package/dist/core/extractors/ts-declaration-detail.js +22 -0
- package/dist/core/extractors/ts-declaration-detail.js.map +1 -1
- package/dist/core/extractors/types.d.ts +5 -0
- package/dist/core/extractors/types.d.ts.map +1 -1
- package/dist/core/extractors/types.js +149 -4
- package/dist/core/extractors/types.js.map +1 -1
- package/dist/core/parser.d.ts.map +1 -1
- package/dist/core/parser.js +3 -1
- package/dist/core/parser.js.map +1 -1
- package/dist/core/ts-grammar-workarounds.d.ts +18 -0
- package/dist/core/ts-grammar-workarounds.d.ts.map +1 -0
- package/dist/core/ts-grammar-workarounds.js +40 -0
- package/dist/core/ts-grammar-workarounds.js.map +1 -0
- package/dist/facts/arrow.d.ts +106 -0
- package/dist/facts/arrow.d.ts.map +1 -0
- package/dist/facts/arrow.js +196 -0
- package/dist/facts/arrow.js.map +1 -0
- package/dist/facts/facts2.d.ts +68 -0
- package/dist/facts/facts2.d.ts.map +1 -0
- package/dist/facts/facts2.js +379 -0
- package/dist/facts/facts2.js.map +1 -0
- package/dist/facts/index.d.ts +22 -0
- package/dist/facts/index.d.ts.map +1 -0
- package/dist/facts/index.js +15 -0
- package/dist/facts/index.js.map +1 -0
- package/dist/facts/java-facts.d.ts +56 -0
- package/dist/facts/java-facts.d.ts.map +1 -0
- package/dist/facts/java-facts.js +250 -0
- package/dist/facts/java-facts.js.map +1 -0
- package/dist/facts/order.d.ts +39 -0
- package/dist/facts/order.d.ts.map +1 -0
- package/dist/facts/order.js +120 -0
- package/dist/facts/order.js.map +1 -0
- package/dist/facts/schema.d.ts +60 -0
- package/dist/facts/schema.d.ts.map +1 -0
- package/dist/facts/schema.js +126 -0
- package/dist/facts/schema.js.map +1 -0
- package/dist/facts/schema2.d.ts +47 -0
- package/dist/facts/schema2.d.ts.map +1 -0
- package/dist/facts/schema2.js +194 -0
- package/dist/facts/schema2.js.map +1 -0
- package/dist/facts/t6.d.ts +84 -0
- package/dist/facts/t6.d.ts.map +1 -0
- package/dist/facts/t6.js +226 -0
- package/dist/facts/t6.js.map +1 -0
- package/dist/facts/table.d.ts +80 -0
- package/dist/facts/table.d.ts.map +1 -0
- package/dist/facts/table.js +548 -0
- package/dist/facts/table.js.map +1 -0
- package/dist/graph-facts/dead-code.d.ts +2 -0
- package/dist/graph-facts/dead-code.d.ts.map +1 -1
- package/dist/graph-facts/dead-code.js +4 -3
- package/dist/graph-facts/dead-code.js.map +1 -1
- package/dist/graph-facts/index.d.ts +1 -1
- package/dist/graph-facts/index.d.ts.map +1 -1
- package/dist/graph-facts/index.js +1 -1
- package/dist/graph-facts/index.js.map +1 -1
- package/dist/graph-facts/reach.d.ts +53 -8
- package/dist/graph-facts/reach.d.ts.map +1 -1
- package/dist/graph-facts/reach.js +172 -16
- package/dist/graph-facts/reach.js.map +1 -1
- package/dist/graph-facts/removal-reach.d.ts +2 -0
- package/dist/graph-facts/removal-reach.d.ts.map +1 -1
- package/dist/graph-facts/removal-reach.js +1 -1
- package/dist/graph-facts/removal-reach.js.map +1 -1
- package/dist/index.d.ts +15 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -4
- package/dist/index.js.map +1 -1
- package/dist/navigation/index.d.ts +1 -0
- package/dist/navigation/index.d.ts.map +1 -1
- package/dist/navigation/index.js +1 -0
- package/dist/navigation/index.js.map +1 -1
- package/dist/navigation/java-graph.d.ts +47 -2
- package/dist/navigation/java-graph.d.ts.map +1 -1
- package/dist/navigation/java-graph.js +395 -18
- package/dist/navigation/java-graph.js.map +1 -1
- package/dist/navigation/java-registrations.d.ts +93 -0
- package/dist/navigation/java-registrations.d.ts.map +1 -0
- package/dist/navigation/java-registrations.js +254 -0
- package/dist/navigation/java-registrations.js.map +1 -0
- package/dist/navigation/navigation-index.d.ts +74 -3
- package/dist/navigation/navigation-index.d.ts.map +1 -1
- package/dist/navigation/navigation-index.js +206 -11
- package/dist/navigation/navigation-index.js.map +1 -1
- package/dist/navigation/ts-call-edges.d.ts +15 -0
- package/dist/navigation/ts-call-edges.d.ts.map +1 -1
- package/dist/navigation/ts-call-edges.js.map +1 -1
- package/dist/navigation/ts-entry-tables.d.ts +1 -1
- package/dist/navigation/ts-entry-tables.d.ts.map +1 -1
- package/dist/navigation/ts-entry-tables.js.map +1 -1
- package/dist/navigation/xml-scan.d.ts +40 -0
- package/dist/navigation/xml-scan.d.ts.map +1 -0
- package/dist/navigation/xml-scan.js +269 -0
- package/dist/navigation/xml-scan.js.map +1 -0
- package/dist/resolution/cross-file.d.ts +44 -0
- package/dist/resolution/cross-file.d.ts.map +1 -1
- package/dist/resolution/cross-file.js +259 -13
- package/dist/resolution/cross-file.js.map +1 -1
- package/dist/stable-ids/files.d.ts +22 -0
- package/dist/stable-ids/files.d.ts.map +1 -0
- package/dist/stable-ids/files.js +28 -0
- package/dist/stable-ids/files.js.map +1 -0
- package/dist/stable-ids/hash.d.ts +16 -4
- package/dist/stable-ids/hash.d.ts.map +1 -1
- package/dist/stable-ids/hash.js +266 -80
- package/dist/stable-ids/hash.js.map +1 -1
- package/dist/stable-ids/index.d.ts +6 -5
- package/dist/stable-ids/index.d.ts.map +1 -1
- package/dist/stable-ids/index.js +19 -6
- package/dist/stable-ids/index.js.map +1 -1
- package/dist/stable-ids/nodes.d.ts +61 -7
- package/dist/stable-ids/nodes.d.ts.map +1 -1
- package/dist/stable-ids/nodes.js +134 -21
- package/dist/stable-ids/nodes.js.map +1 -1
- package/dist/stable-ids/ts-parse-errors.d.ts +5 -1
- package/dist/stable-ids/ts-parse-errors.d.ts.map +1 -1
- package/dist/stable-ids/ts-parse-errors.js +55 -3
- package/dist/stable-ids/ts-parse-errors.js.map +1 -1
- package/dist/stable-ids/typescript.d.ts +5 -0
- package/dist/stable-ids/typescript.d.ts.map +1 -1
- package/dist/stable-ids/typescript.js +41 -8
- package/dist/stable-ids/typescript.js.map +1 -1
- package/dist/types/index.d.ts +21 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/docs/SPEC.md +9 -0
- package/package.json +9 -5
- package/schemas/facts@1.json +134 -0
- package/schemas/facts@2.json +216 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workarounds for tree-sitter-typescript 0.23.2 recoveries that hide
|
|
3
|
+
* declarations when later exports appear in the same file (cognium-dev#1193).
|
|
4
|
+
*/
|
|
5
|
+
import type { Node, Tree } from './parser.js';
|
|
6
|
+
/** Parenthesize unparenthesized conditional type defaults in type-parameter lists. */
|
|
7
|
+
export declare function stabilizeTypeScriptConditionalDefaults(code: string): string;
|
|
8
|
+
/** Split a module into top-level `export …` statement sources (order preserved). */
|
|
9
|
+
export declare function splitTopLevelExportStatements(code: string): string[];
|
|
10
|
+
/** True when the grammar grouped one or more trailing exports into a program-level ERROR. */
|
|
11
|
+
export declare function hasExportTailProgramError(root: Node): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Parse each top-level export in isolation. Used when a full-file parse leaves a
|
|
14
|
+
* program-level ERROR so later declarations never appear in the combined tree.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseTypeScriptExportChunkTrees(code: string, language?: 'typescript' | 'javascript'): Promise<Tree[]>;
|
|
17
|
+
export declare function withTypeScriptExportChunkTrees<T>(code: string, language: 'typescript' | 'javascript', fn: (trees: Tree[]) => T): Promise<T>;
|
|
18
|
+
//# sourceMappingURL=ts-grammar-workarounds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ts-grammar-workarounds.d.ts","sourceRoot":"","sources":["../../src/core/ts-grammar-workarounds.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAG9C,sFAAsF;AACtF,wBAAgB,sCAAsC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAK3E;AAED,oFAAoF;AACpF,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAKpE;AAED,6FAA6F;AAC7F,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAE7D;AAED;;;GAGG;AACH,wBAAsB,+BAA+B,CACnD,IAAI,EAAE,MAAM,EACZ,QAAQ,GAAE,YAAY,GAAG,YAA2B,GACnD,OAAO,CAAC,IAAI,EAAE,CAAC,CAQjB;AAED,wBAAsB,8BAA8B,CAAC,CAAC,EACpD,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,YAAY,GAAG,YAAY,EACrC,EAAE,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,GACvB,OAAO,CAAC,CAAC,CAAC,CAOZ"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { parse, disposeTree } from './parser.js';
|
|
2
|
+
/** Parenthesize unparenthesized conditional type defaults in type-parameter lists. */
|
|
3
|
+
export function stabilizeTypeScriptConditionalDefaults(code) {
|
|
4
|
+
return code.replace(/(=\s*)([A-Za-z_$][\w$.]*)\s+extends\s+((?:[^{}]|\{[^{}]*\})*)\?\s*([^:]+):\s*([^,>\n]+)/g, '$1($2 extends $3 ? $4 : $5)');
|
|
5
|
+
}
|
|
6
|
+
/** Split a module into top-level `export …` statement sources (order preserved). */
|
|
7
|
+
export function splitTopLevelExportStatements(code) {
|
|
8
|
+
return code
|
|
9
|
+
.split(/(?=^export )/m)
|
|
10
|
+
.map((s) => s.trim())
|
|
11
|
+
.filter(Boolean);
|
|
12
|
+
}
|
|
13
|
+
/** True when the grammar grouped one or more trailing exports into a program-level ERROR. */
|
|
14
|
+
export function hasExportTailProgramError(root) {
|
|
15
|
+
return root.type === 'program' && root.namedChildren.some((c) => c?.type === 'ERROR');
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Parse each top-level export in isolation. Used when a full-file parse leaves a
|
|
19
|
+
* program-level ERROR so later declarations never appear in the combined tree.
|
|
20
|
+
*/
|
|
21
|
+
export async function parseTypeScriptExportChunkTrees(code, language = 'typescript') {
|
|
22
|
+
const stabilized = stabilizeTypeScriptConditionalDefaults(code);
|
|
23
|
+
const chunks = splitTopLevelExportStatements(stabilized);
|
|
24
|
+
const trees = [];
|
|
25
|
+
for (const chunk of chunks) {
|
|
26
|
+
trees.push(await parse(chunk, language));
|
|
27
|
+
}
|
|
28
|
+
return trees;
|
|
29
|
+
}
|
|
30
|
+
export async function withTypeScriptExportChunkTrees(code, language, fn) {
|
|
31
|
+
const trees = await parseTypeScriptExportChunkTrees(code, language);
|
|
32
|
+
try {
|
|
33
|
+
return fn(trees);
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
for (const t of trees)
|
|
37
|
+
disposeTree(t);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=ts-grammar-workarounds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ts-grammar-workarounds.js","sourceRoot":"","sources":["../../src/core/ts-grammar-workarounds.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEjD,sFAAsF;AACtF,MAAM,UAAU,sCAAsC,CAAC,IAAY;IACjE,OAAO,IAAI,CAAC,OAAO,CACjB,0FAA0F,EAC1F,6BAA6B,CAC9B,CAAC;AACJ,CAAC;AAED,oFAAoF;AACpF,MAAM,UAAU,6BAA6B,CAAC,IAAY;IACxD,OAAO,IAAI;SACR,KAAK,CAAC,eAAe,CAAC;SACtB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SACpB,MAAM,CAAC,OAAO,CAAC,CAAC;AACrB,CAAC;AAED,6FAA6F;AAC7F,MAAM,UAAU,yBAAyB,CAAC,IAAU;IAClD,OAAO,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC;AACxF,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,+BAA+B,CACnD,IAAY,EACZ,QAAQ,GAAgC,YAAY;IAEpD,MAAM,UAAU,GAAG,sCAAsC,CAAC,IAAI,CAAC,CAAC;IAChE,MAAM,MAAM,GAAG,6BAA6B,CAAC,UAAU,CAAC,CAAC;IACzD,MAAM,KAAK,GAAW,EAAE,CAAC;IACzB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAClD,IAAY,EACZ,QAAqC,EACrC,EAAwB;IAExB,MAAM,KAAK,GAAG,MAAM,+BAA+B,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACpE,IAAI,CAAC;QACH,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;YAAS,CAAC;QACT,KAAK,MAAM,CAAC,IAAI,KAAK;YAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `facts@1` and `facts@2` tables → Arrow IPC file bytes, one file per
|
|
3
|
+
* relation, plus the manifest. The wire form the graph store reads
|
|
4
|
+
* (graph-store design §3). The two schemes share the writer; only the
|
|
5
|
+
* relation table and the `facts` metadata value differ.
|
|
6
|
+
*
|
|
7
|
+
* `apache-arrow` is an optional dependency loaded on first use, so the library
|
|
8
|
+
* keeps running where it is not installed (browser bundles leave it external)
|
|
9
|
+
* and nothing is paid until a caller asks for facts. Determinism: Arrow JS
|
|
10
|
+
* writes no timestamps or random ids, dictionary ids are assigned here by
|
|
11
|
+
* column position (never by the library's global counter), the full
|
|
12
|
+
* vocabulary is written as every dictionary, and batches are cut at
|
|
13
|
+
* `FACTS_CHUNK_ROWS` after the canonical sort — two runs over the same facts
|
|
14
|
+
* give identical bytes (locked by `tests/facts/arrow.test.ts`). Columns arrive
|
|
15
|
+
* as typed arrays (`FactTable`), so a batch is buffer slices, not cells.
|
|
16
|
+
*/
|
|
17
|
+
import type * as ArrowNs from 'apache-arrow';
|
|
18
|
+
import { FACTS_SCHEME, type FactRow, type FactsRelationName } from './schema.js';
|
|
19
|
+
import { type Facts2RelationName, type Facts2Scheme } from './schema2.js';
|
|
20
|
+
import { type FactTable } from './table.js';
|
|
21
|
+
import type { FactSet } from './java-facts.js';
|
|
22
|
+
import type { Fact2Set } from './facts2.js';
|
|
23
|
+
export interface FactsArrowOptions {
|
|
24
|
+
/** The engine that produced the facts, e.g. `circle-ir@4.19.0`; written as schema metadata. */
|
|
25
|
+
engine?: string;
|
|
26
|
+
/** The parser the engine ran, e.g. `tree-sitter-java@0.23.5`; written as schema metadata. */
|
|
27
|
+
parser?: string;
|
|
28
|
+
/** The graph scheme the facts were derived from; recorded in the manifest. */
|
|
29
|
+
source?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface FactsManifestRelation {
|
|
32
|
+
/** The file name the relation is written under: `<relation>.arrow`. */
|
|
33
|
+
file: string;
|
|
34
|
+
/** Rows written (a set: after the dedupe). */
|
|
35
|
+
rows: number;
|
|
36
|
+
batches: number;
|
|
37
|
+
bytes: number;
|
|
38
|
+
/** blake3 of the IPC file bytes, hex: the cache key (the canonical row digest is the store's). */
|
|
39
|
+
blake3: string;
|
|
40
|
+
/** Exact duplicate rows dropped after the canonical sort (relations are sets). */
|
|
41
|
+
duplicates_dropped: number;
|
|
42
|
+
}
|
|
43
|
+
export interface FactsManifest {
|
|
44
|
+
facts: typeof FACTS_SCHEME;
|
|
45
|
+
ids: 'ids@0.1';
|
|
46
|
+
source?: string;
|
|
47
|
+
engine?: string;
|
|
48
|
+
parser?: string;
|
|
49
|
+
chunk_rows: number;
|
|
50
|
+
relations: Record<FactsRelationName, FactsManifestRelation>;
|
|
51
|
+
}
|
|
52
|
+
export interface FactsArrow {
|
|
53
|
+
scheme: typeof FACTS_SCHEME;
|
|
54
|
+
/** Arrow IPC *file* bytes per relation, in canonical order, `facts@1` schema. */
|
|
55
|
+
relations: Record<FactsRelationName, Uint8Array>;
|
|
56
|
+
manifest: FactsManifest;
|
|
57
|
+
}
|
|
58
|
+
/** The `facts@2` manifest: the `facts@1` fields, over the twelve `facts@2` relations. */
|
|
59
|
+
export interface Facts2Manifest {
|
|
60
|
+
facts: Facts2Scheme;
|
|
61
|
+
ids: 'ids@0.1';
|
|
62
|
+
source?: string;
|
|
63
|
+
engine?: string;
|
|
64
|
+
parser?: string;
|
|
65
|
+
chunk_rows: number;
|
|
66
|
+
relations: Record<Facts2RelationName, FactsManifestRelation>;
|
|
67
|
+
}
|
|
68
|
+
export interface Facts2Arrow {
|
|
69
|
+
scheme: Facts2Scheme;
|
|
70
|
+
/** Arrow IPC *file* bytes per relation, in canonical order, `facts@2` schema. */
|
|
71
|
+
relations: Record<Facts2RelationName, Uint8Array>;
|
|
72
|
+
manifest: Facts2Manifest;
|
|
73
|
+
}
|
|
74
|
+
type Arrow = typeof ArrowNs;
|
|
75
|
+
/** The `apache-arrow` module, loaded once; a clear error when it is not installed. */
|
|
76
|
+
export declare function loadArrow(): Promise<Arrow>;
|
|
77
|
+
/** Lowercase hex of the bytes. */
|
|
78
|
+
export declare function hex(bytes: Uint8Array): string;
|
|
79
|
+
interface RelationIpc {
|
|
80
|
+
bytes: Uint8Array;
|
|
81
|
+
batches: number;
|
|
82
|
+
rows: number;
|
|
83
|
+
duplicatesDropped: number;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Arrow IPC file bytes for one relation. A `FactTable` is written as given
|
|
87
|
+
* (it must already be canonical: sorted, no duplicates); rows in the row form
|
|
88
|
+
* are put in canonical form first (sorted and deduplicated).
|
|
89
|
+
*/
|
|
90
|
+
export declare function relationToArrowIpc(name: FactsRelationName, input: FactTable | readonly FactRow[], options?: FactsArrowOptions): Promise<RelationIpc>;
|
|
91
|
+
/** `relationToArrowIpc` for a `facts@2` relation: the `facts@2` columns and `facts` metadata value. */
|
|
92
|
+
export declare function relation2ToArrowIpc(name: Facts2RelationName, input: FactTable | readonly FactRow[], options?: FactsArrowOptions): Promise<RelationIpc>;
|
|
93
|
+
/**
|
|
94
|
+
* Every relation as IPC file bytes plus the manifest. Takes the emitter's
|
|
95
|
+
* `FactSet` (canonical tables with their dedupe counts) or a record of
|
|
96
|
+
* relations in either form.
|
|
97
|
+
*/
|
|
98
|
+
export declare function factsToArrow(input: FactSet | Readonly<Record<FactsRelationName, FactTable | readonly FactRow[]>>, options?: FactsArrowOptions): Promise<FactsArrow>;
|
|
99
|
+
/**
|
|
100
|
+
* Every `facts@2` relation as IPC file bytes plus the manifest. Takes the
|
|
101
|
+
* `facts@2` emitter's `Fact2Set` or a record of the twelve relations in
|
|
102
|
+
* either form.
|
|
103
|
+
*/
|
|
104
|
+
export declare function facts2ToArrow(input: Fact2Set | Readonly<Record<Facts2RelationName, FactTable | readonly FactRow[]>>, options?: FactsArrowOptions): Promise<Facts2Arrow>;
|
|
105
|
+
export {};
|
|
106
|
+
//# sourceMappingURL=arrow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrow.d.ts","sourceRoot":"","sources":["../../src/facts/arrow.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,KAAK,OAAO,MAAM,cAAc,CAAC;AAE7C,OAAO,EAKL,YAAY,EACZ,KAAK,OAAO,EAGZ,KAAK,iBAAiB,EACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAA0D,KAAK,kBAAkB,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAClI,OAAO,EAAsD,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAChG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,WAAW,iBAAiB;IAChC,+FAA+F;IAC/F,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6FAA6F;IAC7F,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8EAA8E;IAC9E,MAAM,CAAC,EAAE,MAA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us the manifest. The wire form the graph store reads
|
|
4
|
+
* (graph-store design §3). The two schemes share the writer; only the
|
|
5
|
+
* relation table and the `facts` metadata value differ.
|
|
6
|
+
*
|
|
7
|
+
* `apache-arrow` is an optional dependency loaded on first use, so the library
|
|
8
|
+
* keeps running where it is not installed (browser bundles leave it external)
|
|
9
|
+
* and nothing is paid until a caller asks for facts. Determinism: Arrow JS
|
|
10
|
+
* writes no timestamps or random ids, dictionary ids are assigned here by
|
|
11
|
+
* column position (never by the library's global counter), the full
|
|
12
|
+
* vocabulary is written as every dictionary, and batches are cut at
|
|
13
|
+
* `FACTS_CHUNK_ROWS` after the canonical sort — two runs over the same facts
|
|
14
|
+
* give identical bytes (locked by `tests/facts/arrow.test.ts`). Columns arrive
|
|
15
|
+
* as typed arrays (`FactTable`), so a batch is buffer slices, not cells.
|
|
16
|
+
*/
|
|
17
|
+
import { blake3 } from '../stable-ids/hash.js';
|
|
18
|
+
import { FACTS_CHUNK_ROWS, FACTS_ID_WIDTH, FACTS_RELATION_NAMES, FACTS_RELATIONS, FACTS_SCHEME, } from './schema.js';
|
|
19
|
+
import { FACTS2_RELATION_NAMES, FACTS2_RELATIONS, FACTS2_SCHEME } from './schema2.js';
|
|
20
|
+
import { canonicalTable, tableFromRows } from './table.js';
|
|
21
|
+
const FACTS1_SPEC = { scheme: FACTS_SCHEME, names: FACTS_RELATION_NAMES, relations: FACTS_RELATIONS };
|
|
22
|
+
const FACTS2_SPEC = { scheme: FACTS2_SCHEME, names: FACTS2_RELATION_NAMES, relations: FACTS2_RELATIONS };
|
|
23
|
+
let arrowModule;
|
|
24
|
+
/** The `apache-arrow` module, loaded once; a clear error when it is not installed. */
|
|
25
|
+
export async function loadArrow() {
|
|
26
|
+
arrowModule ??= import('apache-arrow').catch((e) => {
|
|
27
|
+
arrowModule = undefined;
|
|
28
|
+
throw new Error(`facts@1: emitting Arrow needs the optional dependency apache-arrow (npm install apache-arrow): ${e instanceof Error ? e.message : String(e)}`);
|
|
29
|
+
});
|
|
30
|
+
return arrowModule;
|
|
31
|
+
}
|
|
32
|
+
const encoder = new TextEncoder();
|
|
33
|
+
const HEX = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));
|
|
34
|
+
/** Lowercase hex of the bytes. */
|
|
35
|
+
export function hex(bytes) {
|
|
36
|
+
let s = '';
|
|
37
|
+
for (let i = 0; i < bytes.length; i++)
|
|
38
|
+
s += HEX[bytes[i]];
|
|
39
|
+
return s;
|
|
40
|
+
}
|
|
41
|
+
function arrowType(arrow, c, dictionaryId) {
|
|
42
|
+
switch (c.type) {
|
|
43
|
+
case 'fixed16': return new arrow.FixedSizeBinary(FACTS_ID_WIDTH);
|
|
44
|
+
case 'u32': return new arrow.Uint32();
|
|
45
|
+
case 'utf8': return new arrow.Utf8();
|
|
46
|
+
case 'bool': return new arrow.Bool();
|
|
47
|
+
case 'dict': return new arrow.Dictionary(new arrow.Utf8(), new arrow.Int8(), dictionaryId, false);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/** Arrow Utf8 buffers for `strings[start, end)`: offsets and the UTF-8 bytes, encoded in place into one buffer. */
|
|
51
|
+
function utf8Data(strings, start, end) {
|
|
52
|
+
const n = end - start;
|
|
53
|
+
const offsets = new Int32Array(n + 1);
|
|
54
|
+
let bound = 0;
|
|
55
|
+
for (let i = start; i < end; i++)
|
|
56
|
+
bound += strings[i].length * 3;
|
|
57
|
+
const buffer = new Uint8Array(bound);
|
|
58
|
+
let total = 0;
|
|
59
|
+
for (let i = 0; i < n; i++) {
|
|
60
|
+
const s = strings[start + i];
|
|
61
|
+
if (s.length > 0)
|
|
62
|
+
total += encoder.encodeInto(s, buffer.subarray(total)).written;
|
|
63
|
+
offsets[i + 1] = total;
|
|
64
|
+
}
|
|
65
|
+
return { offsets, bytes: buffer.subarray(0, total) };
|
|
66
|
+
}
|
|
67
|
+
function bitmap(flags, start, end) {
|
|
68
|
+
const n = end - start;
|
|
69
|
+
const out = new Uint8Array(Math.ceil(n / 8) || 1);
|
|
70
|
+
for (let i = 0; i < n; i++)
|
|
71
|
+
if (flags[start + i] !== 0)
|
|
72
|
+
out[i >> 3] |= 1 << (i & 7);
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
function columnData(arrow, c, type, data, start, end, dictionary) {
|
|
76
|
+
const n = end - start;
|
|
77
|
+
switch (c.type) {
|
|
78
|
+
case 'fixed16':
|
|
79
|
+
return arrow.makeData({ type: type, length: n, nullCount: 0, data: data.subarray(start * FACTS_ID_WIDTH, end * FACTS_ID_WIDTH) });
|
|
80
|
+
case 'u32':
|
|
81
|
+
return arrow.makeData({ type: type, length: n, nullCount: 0, data: data.subarray(start, end) });
|
|
82
|
+
case 'bool':
|
|
83
|
+
return arrow.makeData({ type: type, length: n, nullCount: 0, data: bitmap(data, start, end) });
|
|
84
|
+
case 'utf8': {
|
|
85
|
+
const u = utf8Data(data, start, end);
|
|
86
|
+
return arrow.makeData({ type: type, length: n, nullCount: 0, valueOffsets: u.offsets, data: u.bytes });
|
|
87
|
+
}
|
|
88
|
+
case 'dict':
|
|
89
|
+
return arrow.makeData({ type: type, length: n, nullCount: 0, data: data.subarray(start, end), dictionary });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function isTable(x) {
|
|
93
|
+
return !Array.isArray(x);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Arrow IPC file bytes for one relation. A `FactTable` is written as given
|
|
97
|
+
* (it must already be canonical: sorted, no duplicates); rows in the row form
|
|
98
|
+
* are put in canonical form first (sorted and deduplicated).
|
|
99
|
+
*/
|
|
100
|
+
export async function relationToArrowIpc(name, input, options = {}) {
|
|
101
|
+
return writeRelation(FACTS1_SPEC, name, input, options);
|
|
102
|
+
}
|
|
103
|
+
/** `relationToArrowIpc` for a `facts@2` relation: the `facts@2` columns and `facts` metadata value. */
|
|
104
|
+
export async function relation2ToArrowIpc(name, input, options = {}) {
|
|
105
|
+
return writeRelation(FACTS2_SPEC, name, input, options);
|
|
106
|
+
}
|
|
107
|
+
async function writeRelation(spec, name, input, options) {
|
|
108
|
+
const arrow = await loadArrow();
|
|
109
|
+
const relation = spec.relations[name];
|
|
110
|
+
if (!relation)
|
|
111
|
+
throw new Error(`${spec.scheme}: no relation ${String(name)}`);
|
|
112
|
+
let table;
|
|
113
|
+
let duplicatesDropped = 0;
|
|
114
|
+
if (isTable(input)) {
|
|
115
|
+
if (input.columns.length !== relation.columns.length)
|
|
116
|
+
throw new Error(`${spec.scheme}: a ${name} table has ${input.columns.length} columns, the relation ${relation.columns.length}`);
|
|
117
|
+
table = input;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
const c = canonicalTable(relation, tableFromRows(relation, input).columns, input.length);
|
|
121
|
+
table = c.table;
|
|
122
|
+
duplicatesDropped = c.duplicatesDropped;
|
|
123
|
+
}
|
|
124
|
+
const types = relation.columns.map((c, i) => arrowType(arrow, c, i));
|
|
125
|
+
const dictionaries = relation.columns.map(c => {
|
|
126
|
+
if (c.type !== 'dict')
|
|
127
|
+
return undefined;
|
|
128
|
+
const vocab = c.values;
|
|
129
|
+
const u = utf8Data(vocab, 0, vocab.length);
|
|
130
|
+
return arrow.makeVector(arrow.makeData({ type: new arrow.Utf8(), length: vocab.length, nullCount: 0, valueOffsets: u.offsets, data: u.bytes }));
|
|
131
|
+
});
|
|
132
|
+
const fields = relation.columns.map((c, i) => new arrow.Field(c.name, types[i], c.nullable));
|
|
133
|
+
const metadata = new Map([['facts', spec.scheme], ['ids', 'ids@0.1']]);
|
|
134
|
+
if (options.engine)
|
|
135
|
+
metadata.set('engine', options.engine);
|
|
136
|
+
if (options.parser)
|
|
137
|
+
metadata.set('parser', options.parser);
|
|
138
|
+
const schema = new arrow.Schema(fields, metadata);
|
|
139
|
+
const batches = [];
|
|
140
|
+
for (let start = 0; start < table.length; start += FACTS_CHUNK_ROWS) {
|
|
141
|
+
const end = Math.min(start + FACTS_CHUNK_ROWS, table.length);
|
|
142
|
+
const children = relation.columns.map((c, i) => columnData(arrow, c, types[i], table.columns[i], start, end, dictionaries[i]));
|
|
143
|
+
const struct = arrow.makeData({ type: new arrow.Struct(fields), length: end - start, nullCount: 0, children });
|
|
144
|
+
batches.push(new arrow.RecordBatch(schema, struct));
|
|
145
|
+
}
|
|
146
|
+
const bytes = arrow.RecordBatchFileWriter.writeAll(new arrow.Table(schema, batches)).toUint8Array(true);
|
|
147
|
+
return { bytes, batches: batches.length, rows: table.length, duplicatesDropped };
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Every relation as IPC file bytes plus the manifest. Takes the emitter's
|
|
151
|
+
* `FactSet` (canonical tables with their dedupe counts) or a record of
|
|
152
|
+
* relations in either form.
|
|
153
|
+
*/
|
|
154
|
+
export async function factsToArrow(input, options = {}) {
|
|
155
|
+
const { relations, manifest } = await writeAll(FACTS1_SPEC, input, options);
|
|
156
|
+
return { scheme: FACTS_SCHEME, relations, manifest: { facts: FACTS_SCHEME, ...manifest } };
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Every `facts@2` relation as IPC file bytes plus the manifest. Takes the
|
|
160
|
+
* `facts@2` emitter's `Fact2Set` or a record of the twelve relations in
|
|
161
|
+
* either form.
|
|
162
|
+
*/
|
|
163
|
+
export async function facts2ToArrow(input, options = {}) {
|
|
164
|
+
const { relations, manifest } = await writeAll(FACTS2_SPEC, input, options);
|
|
165
|
+
return { scheme: FACTS2_SCHEME, relations, manifest: { facts: FACTS2_SCHEME, ...manifest } };
|
|
166
|
+
}
|
|
167
|
+
async function writeAll(spec, input, options) {
|
|
168
|
+
const set = 'relations' in input && 'duplicatesDropped' in input ? input : undefined;
|
|
169
|
+
const relations = {};
|
|
170
|
+
const manifestRelations = {};
|
|
171
|
+
for (const name of spec.names) {
|
|
172
|
+
const data = set ? set.relations[name] : input[name];
|
|
173
|
+
if (data === undefined)
|
|
174
|
+
throw new Error(`${spec.scheme}: relation ${name} is missing`);
|
|
175
|
+
const { bytes, batches, rows, duplicatesDropped } = await writeRelation(spec, name, data, options);
|
|
176
|
+
relations[name] = bytes;
|
|
177
|
+
manifestRelations[name] = {
|
|
178
|
+
file: `${name}.arrow`,
|
|
179
|
+
rows,
|
|
180
|
+
batches,
|
|
181
|
+
bytes: bytes.length,
|
|
182
|
+
blake3: hex(blake3(bytes)),
|
|
183
|
+
duplicates_dropped: set ? set.duplicatesDropped[name] : duplicatesDropped,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
const manifest = {
|
|
187
|
+
ids: 'ids@0.1',
|
|
188
|
+
...(options.source ? { source: options.source } : {}),
|
|
189
|
+
...(options.engine ? { engine: options.engine } : {}),
|
|
190
|
+
...(options.parser ? { parser: options.parser } : {}),
|
|
191
|
+
chunk_rows: FACTS_CHUNK_ROWS,
|
|
192
|
+
relations: manifestRelations,
|
|
193
|
+
};
|
|
194
|
+
return { relations, manifest };
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=arrow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrow.js","sourceRoot":"","sources":["../../src/facts/arrow.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,oBAAoB,EACpB,eAAe,EACf,YAAY,GAKb,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,aAAa,EAA8C,MAAM,cAAc,CAAC;AAClI,OAAO,EAAE,cAAc,EAAE,aAAa,EAAuC,MAAM,YAAY,CAAC;AAoEhG,MAAM,WAAW,GAAuD,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,oBAAoB,EAAE,SAAS,EAAE,eAAe,EAAE,CAAC;AAC1J,MAAM,WAAW,GAAiD,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,qBAAqB,EAAE,SAAS,EAAE,gBAAgB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CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QACxB,iBAAiB,CAAC,IAAI,CAAC,GAAG;YACxB,IAAI,EAAE,GAAG,IAAI,QAAQ;YACrB,IAAI;YACJ,OAAO;YACP,KAAK,EAAE,KAAK,CAAC,MAAM;YACnB,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC1B,kBAAkB,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,iBAAiB;SAC1E,CAAC;IACJ,CAAC;IACD,MAAM,QAAQ,GAAG;QACf,GAAG,EAAE,SAAkB;QACvB,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrD,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrD,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrD,UAAU,EAAE,gBAAgB;QAC5B,SAAS,EAAE,iBAAiB;KAC7B,CAAC;IACF,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `facts@2` rows from a call graph: a post-pass over the graph the engine
|
|
3
|
+
* already builds (`java-graph@0.1`, or `ts-call-edges@0.1` for TypeScript and
|
|
4
|
+
* JavaScript), the counterpart of `javaGraphFactSet` for the `facts@2`
|
|
5
|
+
* schema. Opt-in: `facts@1` stays the default (`JavaGraphOptions.factsScheme`).
|
|
6
|
+
*
|
|
7
|
+
* Against the `facts@1` post-pass:
|
|
8
|
+
* - every relation that names a file carries the stable file key
|
|
9
|
+
* (`fileKey(path)`), never a dense index;
|
|
10
|
+
* - a site (`call`, `unresolved`, `ref`, `registration`) carries `rel_line` =
|
|
11
|
+
* its line minus the start line of the declaration whose body holds it, and
|
|
12
|
+
* its column, and no file (the file is that declaration's file);
|
|
13
|
+
* - `decl` has no position (`decl_pos` holds it) and gains `name`,
|
|
14
|
+
* `parent_id`, `type_only`, the two `ids@0.1` flags, `contained` (the
|
|
15
|
+
* reach walk's `contains` rule, `containedIn`) and `loads_parent` (the
|
|
16
|
+
* graph's member-initializes-its-class `loads`);
|
|
17
|
+
* - `call.declaring` marks the polymorphic row whose callee is the member the
|
|
18
|
+
* receiver's static type declares;
|
|
19
|
+
* - `ref` (references), `registration` (unresolved registrations),
|
|
20
|
+
* `files.partial` and `parse_error` (the first blocking parse error, its
|
|
21
|
+
* column 0-based) are new.
|
|
22
|
+
*
|
|
23
|
+
* The `#n` re-key of a declaration id two files derive is the `facts@1` one,
|
|
24
|
+
* and it rewrites `parent_id` and every site's declaration as it rewrites
|
|
25
|
+
* `caller_id`. Built as columns, then each relation goes through
|
|
26
|
+
* `canonicalTable` (sorted, duplicates dropped and counted).
|
|
27
|
+
*/
|
|
28
|
+
import type { JavaGraph } from '../navigation/java-graph.js';
|
|
29
|
+
import type { CallEdge, ReferenceEdge, TsCallGraph, TsEntry, UnresolvedCall, UnresolvedRegistration } from '../navigation/ts-call-edges.js';
|
|
30
|
+
import { type StableIdFile } from '../stable-ids/types.js';
|
|
31
|
+
import { type Facts2RelationName } from './schema2.js';
|
|
32
|
+
import { type FactTable } from './table.js';
|
|
33
|
+
import { type JavaFactsInput } from './java-facts.js';
|
|
34
|
+
/** One file's source as the post-pass reads it: path, code (for `content_hash`), its imports and, optionally, its DFG (for `flow`). */
|
|
35
|
+
export type Facts2Input = JavaFactsInput;
|
|
36
|
+
/** The twelve relations in canonical form (sorted sets) with what the dedupe dropped from each. */
|
|
37
|
+
export interface Fact2Set {
|
|
38
|
+
relations: Readonly<Record<Facts2RelationName, FactTable>>;
|
|
39
|
+
duplicatesDropped: Readonly<Record<Facts2RelationName, number>>;
|
|
40
|
+
}
|
|
41
|
+
/** What the post-pass reads from a graph; `JavaGraph` and `TsCallGraph` both have it. */
|
|
42
|
+
export interface Facts2Graph {
|
|
43
|
+
ids: 'ids@0.1';
|
|
44
|
+
files: readonly StableIdFile[];
|
|
45
|
+
edges: readonly CallEdge[];
|
|
46
|
+
unresolved: readonly UnresolvedCall[];
|
|
47
|
+
references: readonly ReferenceEdge[];
|
|
48
|
+
entries: readonly Pick<TsEntry, 'id' | 'kind' | 'certainty' | 'evidence'>[];
|
|
49
|
+
unresolvedRegistrations: readonly UnresolvedRegistration[];
|
|
50
|
+
typeOnly: readonly string[];
|
|
51
|
+
}
|
|
52
|
+
/** Mark `edge` as the declaring row of its polymorphic site (for `call.declaring`). */
|
|
53
|
+
export declare function markDeclaringEdge(edge: CallEdge): void;
|
|
54
|
+
/**
|
|
55
|
+
* The `facts@2` relations of a `java-graph@0.1` graph. Every file the graph
|
|
56
|
+
* holds must be in `inputs`; an input the graph does not hold is written as a
|
|
57
|
+
* Java file with no declarations.
|
|
58
|
+
*/
|
|
59
|
+
export declare function javaGraphFact2Set(graph: JavaGraph, inputs: readonly Facts2Input[]): Fact2Set;
|
|
60
|
+
/**
|
|
61
|
+
* The `facts@2` relations of a `ts-call-edges@0.1` graph (TypeScript and
|
|
62
|
+
* JavaScript). Every file the graph holds must be in `inputs`, and every
|
|
63
|
+
* input must be a file of the graph. The TypeScript-only edges (field uses,
|
|
64
|
+
* module imports and loads) have no relation in `facts@2`; `imports` holds
|
|
65
|
+
* whatever the inputs list.
|
|
66
|
+
*/
|
|
67
|
+
export declare function tsGraphFact2Set(graph: TsCallGraph, inputs: readonly Facts2Input[]): Fact2Set;
|
|
68
|
+
//# sourceMappingURL=facts2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"facts2.d.ts","source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