@optave/codegraph 3.4.0 → 3.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/dist/ast-analysis/engine.d.ts.map +1 -1
- package/dist/ast-analysis/engine.js +3 -9
- package/dist/ast-analysis/engine.js.map +1 -1
- package/dist/ast-analysis/shared.d.ts.map +1 -1
- package/dist/ast-analysis/shared.js +0 -1
- package/dist/ast-analysis/shared.js.map +1 -1
- package/dist/ast-analysis/visitors/cfg-conditionals.d.ts +5 -0
- package/dist/ast-analysis/visitors/cfg-conditionals.d.ts.map +1 -0
- package/dist/ast-analysis/visitors/cfg-conditionals.js +166 -0
- package/dist/ast-analysis/visitors/cfg-conditionals.js.map +1 -0
- package/dist/ast-analysis/visitors/cfg-loops.d.ts +7 -0
- package/dist/ast-analysis/visitors/cfg-loops.d.ts.map +1 -0
- package/dist/ast-analysis/visitors/cfg-loops.js +73 -0
- package/dist/ast-analysis/visitors/cfg-loops.js.map +1 -0
- package/dist/ast-analysis/visitors/cfg-shared.d.ts +56 -0
- package/dist/ast-analysis/visitors/cfg-shared.d.ts.map +1 -0
- package/dist/ast-analysis/visitors/cfg-shared.js +107 -0
- package/dist/ast-analysis/visitors/cfg-shared.js.map +1 -0
- package/dist/ast-analysis/visitors/cfg-try-catch.d.ts +4 -0
- package/dist/ast-analysis/visitors/cfg-try-catch.d.ts.map +1 -0
- package/dist/ast-analysis/visitors/cfg-try-catch.js +100 -0
- package/dist/ast-analysis/visitors/cfg-try-catch.js.map +1 -0
- package/dist/ast-analysis/visitors/cfg-visitor.d.ts +2 -2
- package/dist/ast-analysis/visitors/cfg-visitor.d.ts.map +1 -1
- package/dist/ast-analysis/visitors/cfg-visitor.js +11 -445
- package/dist/ast-analysis/visitors/cfg-visitor.js.map +1 -1
- package/dist/ast-analysis/visitors/complexity-visitor.d.ts.map +1 -1
- package/dist/ast-analysis/visitors/complexity-visitor.js.map +1 -1
- package/dist/ast-analysis/visitors/dataflow-visitor.d.ts.map +1 -1
- package/dist/ast-analysis/visitors/dataflow-visitor.js.map +1 -1
- package/dist/cli/commands/batch.d.ts.map +1 -1
- package/dist/cli/commands/batch.js +4 -3
- package/dist/cli/commands/batch.js.map +1 -1
- package/dist/cli/commands/branch-compare.js +1 -1
- package/dist/cli/commands/branch-compare.js.map +1 -1
- package/dist/cli/commands/build.js +1 -1
- package/dist/cli/commands/build.js.map +1 -1
- package/dist/cli/commands/info.d.ts.map +1 -1
- package/dist/cli/commands/info.js +1 -2
- package/dist/cli/commands/info.js.map +1 -1
- package/dist/cli/commands/path.d.ts.map +1 -1
- package/dist/cli/commands/path.js +7 -2
- package/dist/cli/commands/path.js.map +1 -1
- package/dist/cli/commands/plot.d.ts.map +1 -1
- package/dist/cli/commands/plot.js +2 -2
- package/dist/cli/commands/plot.js.map +1 -1
- package/dist/cli/commands/watch.js +1 -1
- package/dist/cli/commands/watch.js.map +1 -1
- package/dist/cli/index.js +2 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/shared/open-graph.d.ts +2 -2
- package/dist/cli/shared/open-graph.d.ts.map +1 -1
- package/dist/cli/shared/open-graph.js.map +1 -1
- package/dist/cli/types.d.ts +1 -1
- package/dist/cli/types.d.ts.map +1 -1
- package/dist/cli.js +2 -3
- package/dist/cli.js.map +1 -1
- package/dist/db/connection.d.ts +17 -0
- package/dist/db/connection.d.ts.map +1 -1
- package/dist/db/connection.js +91 -2
- package/dist/db/connection.js.map +1 -1
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +1 -1
- package/dist/db/index.js.map +1 -1
- package/dist/db/migrations.d.ts.map +1 -1
- package/dist/db/migrations.js +7 -0
- package/dist/db/migrations.js.map +1 -1
- package/dist/domain/analysis/brief.d.ts.map +1 -1
- package/dist/domain/analysis/brief.js +1 -3
- package/dist/domain/analysis/brief.js.map +1 -1
- package/dist/domain/analysis/context.d.ts.map +1 -1
- package/dist/domain/analysis/context.js +2 -4
- package/dist/domain/analysis/context.js.map +1 -1
- package/dist/domain/analysis/dependencies.d.ts +49 -0
- package/dist/domain/analysis/dependencies.d.ts.map +1 -1
- package/dist/domain/analysis/dependencies.js +145 -0
- package/dist/domain/analysis/dependencies.js.map +1 -1
- package/dist/domain/analysis/diff-impact.d.ts +76 -0
- package/dist/domain/analysis/diff-impact.d.ts.map +1 -0
- package/dist/domain/analysis/diff-impact.js +282 -0
- package/dist/domain/analysis/diff-impact.js.map +1 -0
- package/dist/domain/analysis/exports.d.ts.map +1 -1
- package/dist/domain/analysis/exports.js +0 -1
- package/dist/domain/analysis/exports.js.map +1 -1
- package/dist/domain/analysis/fn-impact.d.ts +66 -0
- package/dist/domain/analysis/fn-impact.d.ts.map +1 -0
- package/dist/domain/analysis/fn-impact.js +189 -0
- package/dist/domain/analysis/fn-impact.js.map +1 -0
- package/dist/domain/analysis/impact.d.ts +8 -148
- package/dist/domain/analysis/impact.d.ts.map +1 -1
- package/dist/domain/analysis/impact.js +8 -568
- package/dist/domain/analysis/impact.js.map +1 -1
- package/dist/domain/analysis/module-map.d.ts.map +1 -1
- package/dist/domain/analysis/module-map.js +1 -3
- package/dist/domain/analysis/module-map.js.map +1 -1
- package/dist/domain/graph/builder/context.d.ts +2 -3
- package/dist/domain/graph/builder/context.d.ts.map +1 -1
- package/dist/domain/graph/builder/context.js.map +1 -1
- package/dist/domain/graph/builder/helpers.d.ts +4 -5
- package/dist/domain/graph/builder/helpers.d.ts.map +1 -1
- package/dist/domain/graph/builder/helpers.js +1 -2
- package/dist/domain/graph/builder/helpers.js.map +1 -1
- package/dist/domain/graph/builder/incremental.d.ts +2 -3
- package/dist/domain/graph/builder/incremental.d.ts.map +1 -1
- package/dist/domain/graph/builder/incremental.js.map +1 -1
- package/dist/domain/graph/builder/pipeline.d.ts.map +1 -1
- package/dist/domain/graph/builder/pipeline.js +6 -0
- package/dist/domain/graph/builder/pipeline.js.map +1 -1
- package/dist/domain/graph/builder/stages/build-edges.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/build-edges.js +12 -2
- package/dist/domain/graph/builder/stages/build-edges.js.map +1 -1
- package/dist/domain/graph/builder/stages/build-structure.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/build-structure.js +155 -59
- package/dist/domain/graph/builder/stages/build-structure.js.map +1 -1
- package/dist/domain/graph/builder/stages/detect-changes.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/detect-changes.js +6 -6
- package/dist/domain/graph/builder/stages/detect-changes.js.map +1 -1
- package/dist/domain/graph/builder/stages/finalize.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/finalize.js +85 -61
- package/dist/domain/graph/builder/stages/finalize.js.map +1 -1
- package/dist/domain/graph/builder/stages/insert-nodes.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/insert-nodes.js.map +1 -1
- package/dist/domain/graph/builder/stages/resolve-imports.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/resolve-imports.js +58 -11
- package/dist/domain/graph/builder/stages/resolve-imports.js.map +1 -1
- package/dist/domain/graph/cycles.js +2 -2
- package/dist/domain/graph/cycles.js.map +1 -1
- package/dist/domain/graph/resolve.d.ts.map +1 -1
- package/dist/domain/graph/resolve.js +10 -8
- package/dist/domain/graph/resolve.js.map +1 -1
- package/dist/domain/graph/watcher.d.ts.map +1 -1
- package/dist/domain/graph/watcher.js +1 -3
- package/dist/domain/graph/watcher.js.map +1 -1
- package/dist/domain/parser.d.ts.map +1 -1
- package/dist/domain/parser.js +11 -12
- package/dist/domain/parser.js.map +1 -1
- package/dist/domain/queries.d.ts +3 -2
- package/dist/domain/queries.d.ts.map +1 -1
- package/dist/domain/queries.js +3 -2
- package/dist/domain/queries.js.map +1 -1
- package/dist/domain/search/generator.d.ts.map +1 -1
- package/dist/domain/search/generator.js.map +1 -1
- package/dist/extractors/csharp.js +2 -2
- package/dist/extractors/csharp.js.map +1 -1
- package/dist/extractors/go.js +2 -2
- package/dist/extractors/go.js.map +1 -1
- package/dist/extractors/helpers.d.ts +5 -0
- package/dist/extractors/helpers.d.ts.map +1 -1
- package/dist/extractors/helpers.js +5 -0
- package/dist/extractors/helpers.js.map +1 -1
- package/dist/extractors/javascript.js +58 -60
- package/dist/extractors/javascript.js.map +1 -1
- package/dist/extractors/php.js +2 -2
- package/dist/extractors/php.js.map +1 -1
- package/dist/extractors/python.js +2 -2
- package/dist/extractors/python.js.map +1 -1
- package/dist/extractors/rust.js +2 -2
- package/dist/extractors/rust.js.map +1 -1
- package/dist/features/audit.d.ts.map +1 -1
- package/dist/features/audit.js +1 -2
- package/dist/features/audit.js.map +1 -1
- package/dist/features/branch-compare.d.ts.map +1 -1
- package/dist/features/branch-compare.js +2 -3
- package/dist/features/branch-compare.js.map +1 -1
- package/dist/features/cfg.d.ts.map +1 -1
- package/dist/features/cfg.js +2 -4
- package/dist/features/cfg.js.map +1 -1
- package/dist/features/cochange.js +4 -4
- package/dist/features/cochange.js.map +1 -1
- package/dist/features/communities.js +4 -4
- package/dist/features/communities.js.map +1 -1
- package/dist/features/complexity-query.d.ts +37 -0
- package/dist/features/complexity-query.d.ts.map +1 -0
- package/dist/features/complexity-query.js +263 -0
- package/dist/features/complexity-query.js.map +1 -0
- package/dist/features/complexity.d.ts +2 -30
- package/dist/features/complexity.d.ts.map +1 -1
- package/dist/features/complexity.js +7 -261
- package/dist/features/complexity.js.map +1 -1
- package/dist/features/dataflow.d.ts.map +1 -1
- package/dist/features/dataflow.js +8 -24
- package/dist/features/dataflow.js.map +1 -1
- package/dist/features/export.d.ts +7 -8
- package/dist/features/export.d.ts.map +1 -1
- package/dist/features/export.js.map +1 -1
- package/dist/features/flow.d.ts.map +1 -1
- package/dist/features/flow.js.map +1 -1
- package/dist/features/graph-enrichment.d.ts.map +1 -1
- package/dist/features/graph-enrichment.js +1 -3
- package/dist/features/graph-enrichment.js.map +1 -1
- package/dist/features/manifesto.js +8 -8
- package/dist/features/manifesto.js.map +1 -1
- package/dist/features/snapshot.d.ts.map +1 -1
- package/dist/features/snapshot.js +0 -1
- package/dist/features/snapshot.js.map +1 -1
- package/dist/features/structure-query.d.ts +76 -0
- package/dist/features/structure-query.d.ts.map +1 -0
- package/dist/features/structure-query.js +245 -0
- package/dist/features/structure-query.js.map +1 -0
- package/dist/features/structure.d.ts +12 -67
- package/dist/features/structure.d.ts.map +1 -1
- package/dist/features/structure.js +188 -244
- package/dist/features/structure.js.map +1 -1
- package/dist/features/triage.js +2 -2
- package/dist/features/triage.js.map +1 -1
- package/dist/graph/algorithms/leiden/adapter.d.ts.map +1 -1
- package/dist/graph/algorithms/leiden/adapter.js +2 -9
- package/dist/graph/algorithms/leiden/adapter.js.map +1 -1
- package/dist/graph/classifiers/roles.d.ts +5 -1
- package/dist/graph/classifiers/roles.d.ts.map +1 -1
- package/dist/graph/classifiers/roles.js +20 -12
- package/dist/graph/classifiers/roles.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/config.d.ts.map +1 -1
- package/dist/infrastructure/config.js +12 -11
- package/dist/infrastructure/config.js.map +1 -1
- package/dist/infrastructure/native.d.ts.map +1 -1
- package/dist/infrastructure/native.js +7 -3
- package/dist/infrastructure/native.js.map +1 -1
- package/dist/infrastructure/registry.d.ts.map +1 -1
- package/dist/infrastructure/registry.js +1 -1
- package/dist/infrastructure/registry.js.map +1 -1
- package/dist/infrastructure/update-check.js +3 -3
- package/dist/infrastructure/update-check.js.map +1 -1
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +2 -8
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tool-registry.d.ts.map +1 -1
- package/dist/mcp/tool-registry.js +9 -4
- package/dist/mcp/tool-registry.js.map +1 -1
- package/dist/mcp/tools/audit.js +1 -1
- package/dist/mcp/tools/audit.js.map +1 -1
- package/dist/mcp/tools/cfg.js +1 -1
- package/dist/mcp/tools/cfg.js.map +1 -1
- package/dist/mcp/tools/check.js +2 -2
- package/dist/mcp/tools/check.js.map +1 -1
- package/dist/mcp/tools/dataflow.js +2 -2
- package/dist/mcp/tools/dataflow.js.map +1 -1
- package/dist/mcp/tools/export-graph.js +1 -1
- package/dist/mcp/tools/export-graph.js.map +1 -1
- package/dist/mcp/tools/index.d.ts.map +1 -1
- package/dist/mcp/tools/index.js.map +1 -1
- package/dist/mcp/tools/path.d.ts +1 -0
- package/dist/mcp/tools/path.d.ts.map +1 -1
- package/dist/mcp/tools/path.js +9 -0
- package/dist/mcp/tools/path.js.map +1 -1
- package/dist/mcp/tools/query.js +1 -1
- package/dist/mcp/tools/query.js.map +1 -1
- package/dist/mcp/tools/semantic-search.js +1 -1
- package/dist/mcp/tools/semantic-search.js.map +1 -1
- package/dist/mcp/tools/sequence.js +1 -1
- package/dist/mcp/tools/sequence.js.map +1 -1
- package/dist/mcp/tools/symbol-children.js +1 -1
- package/dist/mcp/tools/symbol-children.js.map +1 -1
- package/dist/mcp/tools/triage.js +1 -1
- package/dist/mcp/tools/triage.js.map +1 -1
- package/dist/presentation/audit.d.ts.map +1 -1
- package/dist/presentation/audit.js +0 -1
- package/dist/presentation/audit.js.map +1 -1
- package/dist/presentation/diff-impact-mermaid.d.ts +11 -0
- package/dist/presentation/diff-impact-mermaid.d.ts.map +1 -0
- package/dist/presentation/diff-impact-mermaid.js +105 -0
- package/dist/presentation/diff-impact-mermaid.js.map +1 -0
- package/dist/presentation/flow.d.ts.map +1 -1
- package/dist/presentation/flow.js +0 -2
- package/dist/presentation/flow.js.map +1 -1
- package/dist/presentation/manifesto.d.ts.map +1 -1
- package/dist/presentation/manifesto.js +0 -1
- package/dist/presentation/manifesto.js.map +1 -1
- package/dist/presentation/queries-cli/inspect.d.ts.map +1 -1
- package/dist/presentation/queries-cli/inspect.js.map +1 -1
- package/dist/presentation/queries-cli/path.d.ts.map +1 -1
- package/dist/presentation/queries-cli/path.js +45 -1
- package/dist/presentation/queries-cli/path.js.map +1 -1
- package/dist/presentation/result-formatter.d.ts.map +1 -1
- package/dist/presentation/result-formatter.js +1 -3
- package/dist/presentation/result-formatter.js.map +1 -1
- package/dist/presentation/sequence.d.ts.map +1 -1
- package/dist/presentation/sequence.js +0 -1
- package/dist/presentation/sequence.js.map +1 -1
- package/dist/presentation/structure.d.ts.map +1 -1
- package/dist/presentation/structure.js.map +1 -1
- package/dist/presentation/triage.d.ts.map +1 -1
- package/dist/presentation/triage.js +0 -1
- package/dist/presentation/triage.js.map +1 -1
- package/dist/shared/constants.d.ts +9 -3
- package/dist/shared/constants.d.ts.map +1 -1
- package/dist/shared/constants.js +6 -3
- package/dist/shared/constants.js.map +1 -1
- package/dist/shared/errors.d.ts +2 -0
- package/dist/shared/errors.d.ts.map +1 -1
- package/dist/shared/errors.js +4 -0
- package/dist/shared/errors.js.map +1 -1
- package/dist/shared/version.d.ts +2 -0
- package/dist/shared/version.d.ts.map +1 -0
- package/dist/shared/version.js +5 -0
- package/dist/shared/version.js.map +1 -0
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -7
- package/src/ast-analysis/engine.ts +3 -9
- package/src/ast-analysis/shared.ts +0 -1
- package/src/ast-analysis/visitors/cfg-conditionals.ts +227 -0
- package/src/ast-analysis/visitors/cfg-loops.ts +136 -0
- package/src/ast-analysis/visitors/cfg-shared.ts +196 -0
- package/src/ast-analysis/visitors/cfg-try-catch.ts +142 -0
- package/src/ast-analysis/visitors/cfg-visitor.ts +34 -655
- package/src/ast-analysis/visitors/complexity-visitor.ts +0 -1
- package/src/ast-analysis/visitors/dataflow-visitor.ts +0 -1
- package/src/cli/commands/batch.ts +4 -3
- package/src/cli/commands/branch-compare.ts +1 -1
- package/src/cli/commands/build.ts +1 -1
- package/src/cli/commands/info.ts +1 -2
- package/src/cli/commands/path.ts +7 -2
- package/src/cli/commands/plot.ts +2 -2
- package/src/cli/commands/watch.ts +1 -1
- package/src/cli/index.ts +2 -2
- package/src/cli/shared/open-graph.ts +2 -2
- package/src/cli/types.ts +1 -1
- package/src/cli.ts +2 -3
- package/src/db/connection.ts +97 -13
- package/src/db/index.ts +2 -0
- package/src/db/migrations.ts +7 -0
- package/src/domain/analysis/brief.ts +0 -1
- package/src/domain/analysis/context.ts +2 -6
- package/src/domain/analysis/dependencies.ts +165 -0
- package/src/domain/analysis/diff-impact.ts +354 -0
- package/src/domain/analysis/exports.ts +0 -2
- package/src/domain/analysis/fn-impact.ts +241 -0
- package/src/domain/analysis/impact.ts +8 -718
- package/src/domain/analysis/module-map.ts +1 -5
- package/src/domain/graph/builder/context.ts +2 -2
- package/src/domain/graph/builder/helpers.ts +14 -11
- package/src/domain/graph/builder/incremental.ts +33 -28
- package/src/domain/graph/builder/pipeline.ts +8 -0
- package/src/domain/graph/builder/stages/build-edges.ts +17 -4
- package/src/domain/graph/builder/stages/build-structure.ts +205 -76
- package/src/domain/graph/builder/stages/detect-changes.ts +11 -12
- package/src/domain/graph/builder/stages/finalize.ts +100 -81
- package/src/domain/graph/builder/stages/insert-nodes.ts +12 -8
- package/src/domain/graph/builder/stages/resolve-imports.ts +75 -10
- package/src/domain/graph/cycles.ts +2 -2
- package/src/domain/graph/resolve.ts +14 -8
- package/src/domain/graph/watcher.ts +2 -4
- package/src/domain/parser.ts +11 -13
- package/src/domain/queries.ts +2 -2
- package/src/domain/search/generator.ts +3 -4
- package/src/extractors/csharp.ts +2 -2
- package/src/extractors/go.ts +2 -2
- package/src/extractors/helpers.ts +6 -0
- package/src/extractors/javascript.ts +58 -61
- package/src/extractors/php.ts +2 -2
- package/src/extractors/python.ts +2 -2
- package/src/extractors/rust.ts +2 -2
- package/src/features/audit.ts +1 -2
- package/src/features/branch-compare.ts +3 -9
- package/src/features/cfg.ts +2 -4
- package/src/features/cochange.ts +4 -4
- package/src/features/communities.ts +4 -4
- package/src/features/complexity-query.ts +370 -0
- package/src/features/complexity.ts +6 -365
- package/src/features/dataflow.ts +48 -70
- package/src/features/export.ts +12 -16
- package/src/features/flow.ts +0 -1
- package/src/features/graph-enrichment.ts +1 -3
- package/src/features/manifesto.ts +8 -8
- package/src/features/snapshot.ts +1 -2
- package/src/features/structure-query.ts +387 -0
- package/src/features/structure.ts +231 -376
- package/src/features/triage.ts +2 -2
- package/src/graph/algorithms/leiden/adapter.ts +2 -9
- package/src/graph/classifiers/roles.ts +22 -13
- package/src/index.ts +1 -0
- package/src/infrastructure/config.ts +12 -13
- package/src/infrastructure/native.ts +7 -3
- package/src/infrastructure/registry.ts +1 -1
- package/src/infrastructure/update-check.ts +3 -3
- package/src/mcp/server.ts +2 -10
- package/src/mcp/tool-registry.ts +11 -4
- package/src/mcp/tools/audit.ts +1 -1
- package/src/mcp/tools/cfg.ts +1 -1
- package/src/mcp/tools/check.ts +2 -2
- package/src/mcp/tools/dataflow.ts +2 -2
- package/src/mcp/tools/export-graph.ts +1 -1
- package/src/mcp/tools/index.ts +0 -1
- package/src/mcp/tools/path.ts +10 -0
- package/src/mcp/tools/query.ts +1 -1
- package/src/mcp/tools/semantic-search.ts +1 -1
- package/src/mcp/tools/sequence.ts +1 -1
- package/src/mcp/tools/symbol-children.ts +1 -1
- package/src/mcp/tools/triage.ts +1 -1
- package/src/presentation/audit.ts +0 -1
- package/src/presentation/diff-impact-mermaid.ts +127 -0
- package/src/presentation/flow.ts +0 -2
- package/src/presentation/manifesto.ts +0 -1
- package/src/presentation/queries-cli/inspect.ts +0 -1
- package/src/presentation/queries-cli/path.ts +71 -1
- package/src/presentation/result-formatter.ts +0 -1
- package/src/presentation/sequence.ts +0 -1
- package/src/presentation/structure.ts +0 -12
- package/src/presentation/triage.ts +0 -1
- package/src/shared/constants.ts +33 -19
- package/src/shared/errors.ts +5 -0
- package/src/shared/version.ts +10 -0
- package/src/types.ts +4 -10
- package/src/vendor.d.ts +0 -39
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { findDbPath, openReadonlyOrFail } from '../../db/index.js';
|
|
5
|
+
import { cachedStmt } from '../../db/repository/cached-stmt.js';
|
|
6
|
+
import { evaluateBoundaries } from '../../features/boundaries.js';
|
|
7
|
+
import { coChangeForFiles } from '../../features/cochange.js';
|
|
8
|
+
import { ownersForFiles } from '../../features/owners.js';
|
|
9
|
+
import { loadConfig } from '../../infrastructure/config.js';
|
|
10
|
+
import { debug } from '../../infrastructure/logger.js';
|
|
11
|
+
import { isTestFile } from '../../infrastructure/test-filter.js';
|
|
12
|
+
import { paginateResult } from '../../shared/paginate.js';
|
|
13
|
+
import type { BetterSqlite3Database, NodeRow, StmtCache } from '../../types.js';
|
|
14
|
+
import { bfsTransitiveCallers } from './fn-impact.js';
|
|
15
|
+
|
|
16
|
+
const _defsStmtCache: StmtCache<NodeRow> = new WeakMap();
|
|
17
|
+
|
|
18
|
+
// --- diffImpactData helpers ---
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Walk up from repoRoot until a .git directory is found.
|
|
22
|
+
* Returns true if a git root exists, false otherwise.
|
|
23
|
+
*/
|
|
24
|
+
function findGitRoot(repoRoot: string): boolean {
|
|
25
|
+
let checkDir = repoRoot;
|
|
26
|
+
while (checkDir) {
|
|
27
|
+
if (fs.existsSync(path.join(checkDir, '.git'))) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
const parent = path.dirname(checkDir);
|
|
31
|
+
if (parent === checkDir) break;
|
|
32
|
+
checkDir = parent;
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Execute git diff and return the raw output string.
|
|
39
|
+
* Returns `{ output: string }` on success or `{ error: string }` on failure.
|
|
40
|
+
*/
|
|
41
|
+
function runGitDiff(
|
|
42
|
+
repoRoot: string,
|
|
43
|
+
opts: { staged?: boolean; ref?: string },
|
|
44
|
+
): { output: string; error?: never } | { error: string; output?: never } {
|
|
45
|
+
try {
|
|
46
|
+
const args = opts.staged
|
|
47
|
+
? ['diff', '--cached', '--unified=0', '--no-color']
|
|
48
|
+
: ['diff', opts.ref || 'HEAD', '--unified=0', '--no-color'];
|
|
49
|
+
const output = execFileSync('git', args, {
|
|
50
|
+
cwd: repoRoot,
|
|
51
|
+
encoding: 'utf-8',
|
|
52
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
53
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
54
|
+
});
|
|
55
|
+
return { output };
|
|
56
|
+
} catch (e: unknown) {
|
|
57
|
+
return { error: `Failed to run git diff: ${(e as Error).message}` };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Parse raw git diff output into a changedRanges map and newFiles set.
|
|
63
|
+
*/
|
|
64
|
+
function parseGitDiff(diffOutput: string) {
|
|
65
|
+
const changedRanges = new Map<string, Array<{ start: number; end: number }>>();
|
|
66
|
+
const newFiles = new Set<string>();
|
|
67
|
+
let currentFile: string | null = null;
|
|
68
|
+
let prevIsDevNull = false;
|
|
69
|
+
|
|
70
|
+
for (const line of diffOutput.split('\n')) {
|
|
71
|
+
if (line.startsWith('--- /dev/null')) {
|
|
72
|
+
prevIsDevNull = true;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (line.startsWith('--- ')) {
|
|
76
|
+
prevIsDevNull = false;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const fileMatch = line.match(/^\+\+\+ b\/(.+)/);
|
|
80
|
+
if (fileMatch) {
|
|
81
|
+
currentFile = fileMatch[1]!;
|
|
82
|
+
if (!changedRanges.has(currentFile)) changedRanges.set(currentFile, []);
|
|
83
|
+
if (prevIsDevNull) newFiles.add(currentFile!);
|
|
84
|
+
prevIsDevNull = false;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const hunkMatch = line.match(/^@@ .+ \+(\d+)(?:,(\d+))? @@/);
|
|
88
|
+
if (hunkMatch && currentFile) {
|
|
89
|
+
const start = parseInt(hunkMatch[1]!, 10);
|
|
90
|
+
const count = parseInt(hunkMatch[2] || '1', 10);
|
|
91
|
+
changedRanges.get(currentFile)!.push({ start, end: start + count - 1 });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return { changedRanges, newFiles };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Find all function/method/class nodes whose line ranges overlap any changed range.
|
|
100
|
+
*/
|
|
101
|
+
function findAffectedFunctions(
|
|
102
|
+
db: BetterSqlite3Database,
|
|
103
|
+
changedRanges: Map<string, Array<{ start: number; end: number }>>,
|
|
104
|
+
noTests: boolean,
|
|
105
|
+
): NodeRow[] {
|
|
106
|
+
const affectedFunctions: NodeRow[] = [];
|
|
107
|
+
const defsStmt = cachedStmt(
|
|
108
|
+
_defsStmtCache,
|
|
109
|
+
db,
|
|
110
|
+
`SELECT * FROM nodes WHERE file = ? AND kind IN ('function', 'method', 'class') ORDER BY line`,
|
|
111
|
+
);
|
|
112
|
+
for (const [file, ranges] of changedRanges) {
|
|
113
|
+
if (noTests && isTestFile(file)) continue;
|
|
114
|
+
const defs = defsStmt.all(file) as NodeRow[];
|
|
115
|
+
for (let i = 0; i < defs.length; i++) {
|
|
116
|
+
const def = defs[i]!;
|
|
117
|
+
const endLine = def.end_line || (defs[i + 1] ? defs[i + 1]!.line - 1 : 999999);
|
|
118
|
+
for (const range of ranges) {
|
|
119
|
+
if (range.start <= endLine && range.end >= def.line) {
|
|
120
|
+
affectedFunctions.push(def);
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return affectedFunctions;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Run BFS per affected function, collecting per-function results and the full affected set.
|
|
131
|
+
*/
|
|
132
|
+
function buildFunctionImpactResults(
|
|
133
|
+
db: BetterSqlite3Database,
|
|
134
|
+
affectedFunctions: NodeRow[],
|
|
135
|
+
noTests: boolean,
|
|
136
|
+
maxDepth: number,
|
|
137
|
+
includeImplementors = true,
|
|
138
|
+
) {
|
|
139
|
+
const allAffected = new Set<string>();
|
|
140
|
+
const functionResults = affectedFunctions.map((fn) => {
|
|
141
|
+
const edges: Array<{ from: string; to: string }> = [];
|
|
142
|
+
const idToKey = new Map<number, string>();
|
|
143
|
+
idToKey.set(fn.id, `${fn.file}::${fn.name}:${fn.line}`);
|
|
144
|
+
|
|
145
|
+
const { levels, totalDependents } = bfsTransitiveCallers(db, fn.id, {
|
|
146
|
+
noTests,
|
|
147
|
+
maxDepth,
|
|
148
|
+
includeImplementors,
|
|
149
|
+
onVisit(c, parentId) {
|
|
150
|
+
allAffected.add(`${c.file}:${c.name}`);
|
|
151
|
+
const callerKey = `${c.file}::${c.name}:${c.line}`;
|
|
152
|
+
idToKey.set(c.id, callerKey);
|
|
153
|
+
edges.push({ from: idToKey.get(parentId)!, to: callerKey });
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
name: fn.name,
|
|
159
|
+
kind: fn.kind,
|
|
160
|
+
file: fn.file,
|
|
161
|
+
line: fn.line,
|
|
162
|
+
transitiveCallers: totalDependents,
|
|
163
|
+
levels,
|
|
164
|
+
edges,
|
|
165
|
+
};
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
return { functionResults, allAffected };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Look up historically co-changed files for the set of changed files.
|
|
173
|
+
* Returns an empty array if the co_changes table is unavailable.
|
|
174
|
+
*/
|
|
175
|
+
function lookupCoChanges(
|
|
176
|
+
db: BetterSqlite3Database,
|
|
177
|
+
changedRanges: Map<string, unknown>,
|
|
178
|
+
affectedFiles: Set<string>,
|
|
179
|
+
noTests: boolean,
|
|
180
|
+
) {
|
|
181
|
+
try {
|
|
182
|
+
db.prepare('SELECT 1 FROM co_changes LIMIT 1').get();
|
|
183
|
+
const changedFilesList = [...changedRanges.keys()];
|
|
184
|
+
const coResults = coChangeForFiles(changedFilesList, db, {
|
|
185
|
+
minJaccard: 0.3,
|
|
186
|
+
limit: 20,
|
|
187
|
+
noTests,
|
|
188
|
+
});
|
|
189
|
+
return coResults.filter((r: { file: string }) => !affectedFiles.has(r.file));
|
|
190
|
+
} catch (e: unknown) {
|
|
191
|
+
debug(`co_changes lookup skipped: ${(e as Error).message}`);
|
|
192
|
+
return [];
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Look up CODEOWNERS for changed and affected files.
|
|
198
|
+
* Returns null if no owners are found or lookup fails.
|
|
199
|
+
*/
|
|
200
|
+
function lookupOwnership(
|
|
201
|
+
changedRanges: Map<string, unknown>,
|
|
202
|
+
affectedFiles: Set<string>,
|
|
203
|
+
repoRoot: string,
|
|
204
|
+
) {
|
|
205
|
+
try {
|
|
206
|
+
const allFilePaths = [...new Set([...changedRanges.keys(), ...affectedFiles])];
|
|
207
|
+
const ownerResult = ownersForFiles(allFilePaths, repoRoot);
|
|
208
|
+
if (ownerResult.affectedOwners.length > 0) {
|
|
209
|
+
return {
|
|
210
|
+
owners: Object.fromEntries(ownerResult.owners),
|
|
211
|
+
affectedOwners: ownerResult.affectedOwners,
|
|
212
|
+
suggestedReviewers: ownerResult.suggestedReviewers,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
return null;
|
|
216
|
+
} catch (e: unknown) {
|
|
217
|
+
debug(`CODEOWNERS lookup skipped: ${(e as Error).message}`);
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Check manifesto boundary violations scoped to the changed files.
|
|
224
|
+
* Returns `{ boundaryViolations, boundaryViolationCount }`.
|
|
225
|
+
*/
|
|
226
|
+
function checkBoundaryViolations(
|
|
227
|
+
db: BetterSqlite3Database,
|
|
228
|
+
changedRanges: Map<string, unknown>,
|
|
229
|
+
noTests: boolean,
|
|
230
|
+
opts: any,
|
|
231
|
+
repoRoot: string,
|
|
232
|
+
) {
|
|
233
|
+
try {
|
|
234
|
+
const cfg = opts.config || loadConfig(repoRoot);
|
|
235
|
+
const boundaryConfig = cfg.manifesto?.boundaries;
|
|
236
|
+
if (boundaryConfig) {
|
|
237
|
+
const result = evaluateBoundaries(db, boundaryConfig, {
|
|
238
|
+
scopeFiles: [...changedRanges.keys()],
|
|
239
|
+
noTests,
|
|
240
|
+
});
|
|
241
|
+
return {
|
|
242
|
+
boundaryViolations: result.violations,
|
|
243
|
+
boundaryViolationCount: result.violationCount,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
} catch (e: unknown) {
|
|
247
|
+
debug(`boundary check skipped: ${(e as Error).message}`);
|
|
248
|
+
}
|
|
249
|
+
return { boundaryViolations: [], boundaryViolationCount: 0 };
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// --- diffImpactData ---
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Compute diff-impact analysis between two git refs (or staged changes).
|
|
256
|
+
* Uses execFileSync (via runGitDiff) to avoid shell injection.
|
|
257
|
+
*/
|
|
258
|
+
export function diffImpactData(
|
|
259
|
+
customDbPath: string,
|
|
260
|
+
opts: {
|
|
261
|
+
noTests?: boolean;
|
|
262
|
+
depth?: number;
|
|
263
|
+
staged?: boolean;
|
|
264
|
+
ref?: string;
|
|
265
|
+
includeImplementors?: boolean;
|
|
266
|
+
limit?: number;
|
|
267
|
+
offset?: number;
|
|
268
|
+
config?: any;
|
|
269
|
+
} = {},
|
|
270
|
+
) {
|
|
271
|
+
const db = openReadonlyOrFail(customDbPath);
|
|
272
|
+
try {
|
|
273
|
+
const noTests = opts.noTests || false;
|
|
274
|
+
const config = opts.config || loadConfig();
|
|
275
|
+
const maxDepth = opts.depth || config.analysis?.impactDepth || 3;
|
|
276
|
+
|
|
277
|
+
const dbPath = findDbPath(customDbPath);
|
|
278
|
+
const repoRoot = path.resolve(path.dirname(dbPath), '..');
|
|
279
|
+
|
|
280
|
+
if (!findGitRoot(repoRoot)) {
|
|
281
|
+
return { error: `Not a git repository: ${repoRoot}` };
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const gitResult = runGitDiff(repoRoot, opts);
|
|
285
|
+
if ('error' in gitResult) return { error: gitResult.error };
|
|
286
|
+
|
|
287
|
+
if (!gitResult.output.trim()) {
|
|
288
|
+
return {
|
|
289
|
+
changedFiles: 0,
|
|
290
|
+
newFiles: [],
|
|
291
|
+
affectedFunctions: [],
|
|
292
|
+
affectedFiles: [],
|
|
293
|
+
summary: null,
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const { changedRanges, newFiles } = parseGitDiff(gitResult.output);
|
|
298
|
+
|
|
299
|
+
if (changedRanges.size === 0) {
|
|
300
|
+
return {
|
|
301
|
+
changedFiles: 0,
|
|
302
|
+
newFiles: [],
|
|
303
|
+
affectedFunctions: [],
|
|
304
|
+
affectedFiles: [],
|
|
305
|
+
summary: null,
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const affectedFunctions = findAffectedFunctions(db, changedRanges, noTests);
|
|
310
|
+
const includeImplementors = opts.includeImplementors !== false;
|
|
311
|
+
const { functionResults, allAffected } = buildFunctionImpactResults(
|
|
312
|
+
db,
|
|
313
|
+
affectedFunctions,
|
|
314
|
+
noTests,
|
|
315
|
+
maxDepth,
|
|
316
|
+
includeImplementors,
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
const affectedFiles = new Set<string>();
|
|
320
|
+
for (const key of allAffected) affectedFiles.add(key.split(':')[0]!);
|
|
321
|
+
|
|
322
|
+
const historicallyCoupled = lookupCoChanges(db, changedRanges, affectedFiles, noTests);
|
|
323
|
+
const ownership = lookupOwnership(changedRanges, affectedFiles, repoRoot);
|
|
324
|
+
const { boundaryViolations, boundaryViolationCount } = checkBoundaryViolations(
|
|
325
|
+
db,
|
|
326
|
+
changedRanges,
|
|
327
|
+
noTests,
|
|
328
|
+
opts,
|
|
329
|
+
repoRoot,
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
const base = {
|
|
333
|
+
changedFiles: changedRanges.size,
|
|
334
|
+
newFiles: [...newFiles],
|
|
335
|
+
affectedFunctions: functionResults,
|
|
336
|
+
affectedFiles: [...affectedFiles],
|
|
337
|
+
historicallyCoupled,
|
|
338
|
+
ownership,
|
|
339
|
+
boundaryViolations,
|
|
340
|
+
boundaryViolationCount,
|
|
341
|
+
summary: {
|
|
342
|
+
functionsChanged: affectedFunctions.length,
|
|
343
|
+
callersAffected: allAffected.size,
|
|
344
|
+
filesAffected: affectedFiles.size,
|
|
345
|
+
historicallyCoupledCount: historicallyCoupled.length,
|
|
346
|
+
ownersAffected: ownership ? ownership.affectedOwners.length : 0,
|
|
347
|
+
boundaryViolationCount,
|
|
348
|
+
},
|
|
349
|
+
};
|
|
350
|
+
return paginateResult(base, 'affectedFunctions', { limit: opts.limit, offset: opts.offset });
|
|
351
|
+
} finally {
|
|
352
|
+
db.close();
|
|
353
|
+
}
|
|
354
|
+
}
|
|
@@ -34,7 +34,6 @@ export function exportsData(
|
|
|
34
34
|
unused?: boolean;
|
|
35
35
|
limit?: number;
|
|
36
36
|
offset?: number;
|
|
37
|
-
// biome-ignore lint/suspicious/noExplicitAny: config shape is dynamic
|
|
38
37
|
config?: any;
|
|
39
38
|
} = {},
|
|
40
39
|
) {
|
|
@@ -84,7 +83,6 @@ export function exportsData(
|
|
|
84
83
|
totalReexported: first.totalReexported,
|
|
85
84
|
totalReexportedUnused: first.totalReexportedUnused,
|
|
86
85
|
};
|
|
87
|
-
// biome-ignore lint/suspicious/noExplicitAny: paginateResult returns dynamic shape
|
|
88
86
|
const paginated: any = paginateResult(base, 'results', {
|
|
89
87
|
limit: opts.limit,
|
|
90
88
|
offset: opts.offset,
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import {
|
|
2
|
+
findDistinctCallers,
|
|
3
|
+
findFileNodes,
|
|
4
|
+
findImplementors,
|
|
5
|
+
findImportDependents,
|
|
6
|
+
findNodeById,
|
|
7
|
+
openReadonlyOrFail,
|
|
8
|
+
} from '../../db/index.js';
|
|
9
|
+
import { loadConfig } from '../../infrastructure/config.js';
|
|
10
|
+
import { isTestFile } from '../../infrastructure/test-filter.js';
|
|
11
|
+
import { normalizeSymbol } from '../../shared/normalize.js';
|
|
12
|
+
import { paginateResult } from '../../shared/paginate.js';
|
|
13
|
+
import type { BetterSqlite3Database, NodeRow, RelatedNodeRow } from '../../types.js';
|
|
14
|
+
import { findMatchingNodes } from './symbol-lookup.js';
|
|
15
|
+
|
|
16
|
+
// --- Shared BFS: transitive callers ---
|
|
17
|
+
|
|
18
|
+
const INTERFACE_LIKE_KINDS = new Set(['interface', 'trait']);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Check whether the graph contains any 'implements' edges.
|
|
22
|
+
* Cached per db handle so the query runs at most once per connection.
|
|
23
|
+
*/
|
|
24
|
+
const _hasImplementsCache: WeakMap<BetterSqlite3Database, boolean> = new WeakMap();
|
|
25
|
+
function hasImplementsEdges(db: BetterSqlite3Database): boolean {
|
|
26
|
+
if (_hasImplementsCache.has(db)) return _hasImplementsCache.get(db)!;
|
|
27
|
+
const row = db.prepare("SELECT 1 FROM edges WHERE kind = 'implements' LIMIT 1").get();
|
|
28
|
+
const result = !!row;
|
|
29
|
+
_hasImplementsCache.set(db, result);
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* BFS traversal to find transitive callers of a node.
|
|
35
|
+
* When an interface/trait node is encountered (either as the start node or
|
|
36
|
+
* during traversal), its concrete implementors are also added to the frontier
|
|
37
|
+
* so that changes to an interface signature propagate to all implementors.
|
|
38
|
+
*/
|
|
39
|
+
export function bfsTransitiveCallers(
|
|
40
|
+
db: BetterSqlite3Database,
|
|
41
|
+
startId: number,
|
|
42
|
+
{
|
|
43
|
+
noTests = false,
|
|
44
|
+
maxDepth = 3,
|
|
45
|
+
includeImplementors = true,
|
|
46
|
+
onVisit,
|
|
47
|
+
}: {
|
|
48
|
+
noTests?: boolean;
|
|
49
|
+
maxDepth?: number;
|
|
50
|
+
includeImplementors?: boolean;
|
|
51
|
+
onVisit?: (
|
|
52
|
+
caller: RelatedNodeRow & { viaImplements?: boolean },
|
|
53
|
+
parentId: number,
|
|
54
|
+
depth: number,
|
|
55
|
+
) => void;
|
|
56
|
+
} = {},
|
|
57
|
+
) {
|
|
58
|
+
// Skip all implementor lookups when the graph has no implements edges
|
|
59
|
+
const resolveImplementors = includeImplementors && hasImplementsEdges(db);
|
|
60
|
+
|
|
61
|
+
const visited = new Set([startId]);
|
|
62
|
+
const levels: Record<
|
|
63
|
+
number,
|
|
64
|
+
Array<{ name: string; kind: string; file: string; line: number; viaImplements?: boolean }>
|
|
65
|
+
> = {};
|
|
66
|
+
let frontier = [startId];
|
|
67
|
+
|
|
68
|
+
// Seed: if start node is an interface/trait, include its implementors at depth 1.
|
|
69
|
+
// Implementors go into a separate list so their callers appear at depth 2, not depth 1.
|
|
70
|
+
const implNextFrontier: number[] = [];
|
|
71
|
+
if (resolveImplementors) {
|
|
72
|
+
const startNode = findNodeById(db, startId) as NodeRow | undefined;
|
|
73
|
+
if (startNode && INTERFACE_LIKE_KINDS.has(startNode.kind)) {
|
|
74
|
+
const impls = findImplementors(db, startId) as RelatedNodeRow[];
|
|
75
|
+
for (const impl of impls) {
|
|
76
|
+
if (!visited.has(impl.id) && (!noTests || !isTestFile(impl.file))) {
|
|
77
|
+
visited.add(impl.id);
|
|
78
|
+
implNextFrontier.push(impl.id);
|
|
79
|
+
if (!levels[1]) levels[1] = [];
|
|
80
|
+
levels[1].push({
|
|
81
|
+
name: impl.name,
|
|
82
|
+
kind: impl.kind,
|
|
83
|
+
file: impl.file,
|
|
84
|
+
line: impl.line,
|
|
85
|
+
viaImplements: true,
|
|
86
|
+
});
|
|
87
|
+
if (onVisit) onVisit({ ...impl, viaImplements: true }, startId, 1);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
for (let d = 1; d <= maxDepth; d++) {
|
|
94
|
+
// On the first wave, merge seeded implementors so their callers appear at d=2
|
|
95
|
+
if (d === 1 && implNextFrontier.length > 0) {
|
|
96
|
+
frontier = [...frontier, ...implNextFrontier];
|
|
97
|
+
}
|
|
98
|
+
const nextFrontier: number[] = [];
|
|
99
|
+
for (const fid of frontier) {
|
|
100
|
+
const callers = findDistinctCallers(db, fid) as RelatedNodeRow[];
|
|
101
|
+
for (const c of callers) {
|
|
102
|
+
if (!visited.has(c.id) && (!noTests || !isTestFile(c.file))) {
|
|
103
|
+
visited.add(c.id);
|
|
104
|
+
nextFrontier.push(c.id);
|
|
105
|
+
if (!levels[d]) levels[d] = [];
|
|
106
|
+
levels[d]!.push({ name: c.name, kind: c.kind, file: c.file, line: c.line });
|
|
107
|
+
if (onVisit) onVisit(c, fid, d);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// If a caller is an interface/trait, also pull in its implementors
|
|
111
|
+
// Implementors are one extra hop away, so record at d+1
|
|
112
|
+
if (resolveImplementors && INTERFACE_LIKE_KINDS.has(c.kind)) {
|
|
113
|
+
const impls = findImplementors(db, c.id) as RelatedNodeRow[];
|
|
114
|
+
for (const impl of impls) {
|
|
115
|
+
if (!visited.has(impl.id) && (!noTests || !isTestFile(impl.file))) {
|
|
116
|
+
visited.add(impl.id);
|
|
117
|
+
nextFrontier.push(impl.id);
|
|
118
|
+
const implDepth = d + 1;
|
|
119
|
+
if (!levels[implDepth]) levels[implDepth] = [];
|
|
120
|
+
levels[implDepth].push({
|
|
121
|
+
name: impl.name,
|
|
122
|
+
kind: impl.kind,
|
|
123
|
+
file: impl.file,
|
|
124
|
+
line: impl.line,
|
|
125
|
+
viaImplements: true,
|
|
126
|
+
});
|
|
127
|
+
if (onVisit) onVisit({ ...impl, viaImplements: true }, c.id, implDepth);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
frontier = nextFrontier;
|
|
134
|
+
if (frontier.length === 0) break;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return { totalDependents: visited.size - 1, levels };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function impactAnalysisData(
|
|
141
|
+
file: string,
|
|
142
|
+
customDbPath: string,
|
|
143
|
+
opts: { noTests?: boolean } = {},
|
|
144
|
+
) {
|
|
145
|
+
const db = openReadonlyOrFail(customDbPath);
|
|
146
|
+
try {
|
|
147
|
+
const noTests = opts.noTests || false;
|
|
148
|
+
const fileNodes = findFileNodes(db, `%${file}%`) as NodeRow[];
|
|
149
|
+
if (fileNodes.length === 0) {
|
|
150
|
+
return { file, sources: [], levels: {}, totalDependents: 0 };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const visited = new Set<number>();
|
|
154
|
+
const queue: number[] = [];
|
|
155
|
+
const levels = new Map<number, number>();
|
|
156
|
+
|
|
157
|
+
for (const fn of fileNodes) {
|
|
158
|
+
visited.add(fn.id);
|
|
159
|
+
queue.push(fn.id);
|
|
160
|
+
levels.set(fn.id, 0);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
while (queue.length > 0) {
|
|
164
|
+
const current = queue.shift()!;
|
|
165
|
+
const level = levels.get(current)!;
|
|
166
|
+
const dependents = findImportDependents(db, current) as RelatedNodeRow[];
|
|
167
|
+
for (const dep of dependents) {
|
|
168
|
+
if (!visited.has(dep.id) && (!noTests || !isTestFile(dep.file))) {
|
|
169
|
+
visited.add(dep.id);
|
|
170
|
+
queue.push(dep.id);
|
|
171
|
+
levels.set(dep.id, level + 1);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const byLevel: Record<number, Array<{ file: string }>> = {};
|
|
177
|
+
for (const [id, level] of levels) {
|
|
178
|
+
if (level === 0) continue;
|
|
179
|
+
if (!byLevel[level]) byLevel[level] = [];
|
|
180
|
+
const node = findNodeById(db, id) as NodeRow | undefined;
|
|
181
|
+
if (node) byLevel[level].push({ file: node.file });
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
file,
|
|
186
|
+
sources: fileNodes.map((f) => f.file),
|
|
187
|
+
levels: byLevel,
|
|
188
|
+
totalDependents: visited.size - fileNodes.length,
|
|
189
|
+
};
|
|
190
|
+
} finally {
|
|
191
|
+
db.close();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export function fnImpactData(
|
|
196
|
+
name: string,
|
|
197
|
+
customDbPath: string,
|
|
198
|
+
opts: {
|
|
199
|
+
depth?: number;
|
|
200
|
+
noTests?: boolean;
|
|
201
|
+
file?: string;
|
|
202
|
+
kind?: string;
|
|
203
|
+
includeImplementors?: boolean;
|
|
204
|
+
limit?: number;
|
|
205
|
+
offset?: number;
|
|
206
|
+
config?: any;
|
|
207
|
+
} = {},
|
|
208
|
+
) {
|
|
209
|
+
const db = openReadonlyOrFail(customDbPath);
|
|
210
|
+
try {
|
|
211
|
+
const config = opts.config || loadConfig();
|
|
212
|
+
const maxDepth = opts.depth || config.analysis?.fnImpactDepth || 5;
|
|
213
|
+
const noTests = opts.noTests || false;
|
|
214
|
+
const hc = new Map();
|
|
215
|
+
|
|
216
|
+
const nodes = findMatchingNodes(db, name, { noTests, file: opts.file, kind: opts.kind });
|
|
217
|
+
if (nodes.length === 0) {
|
|
218
|
+
return { name, results: [] };
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const includeImplementors = opts.includeImplementors !== false;
|
|
222
|
+
|
|
223
|
+
const results = nodes.map((node) => {
|
|
224
|
+
const { levels, totalDependents } = bfsTransitiveCallers(db, node.id, {
|
|
225
|
+
noTests,
|
|
226
|
+
maxDepth,
|
|
227
|
+
includeImplementors,
|
|
228
|
+
});
|
|
229
|
+
return {
|
|
230
|
+
...normalizeSymbol(node, db, hc),
|
|
231
|
+
levels,
|
|
232
|
+
totalDependents,
|
|
233
|
+
};
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
const base = { name, results };
|
|
237
|
+
return paginateResult(base, 'results', { limit: opts.limit, offset: opts.offset });
|
|
238
|
+
} finally {
|
|
239
|
+
db.close();
|
|
240
|
+
}
|
|
241
|
+
}
|