@pavanyn/docugen 1.0.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/LICENSE +5 -0
- package/README.md +164 -0
- package/dist/adapters/block.d.ts +26 -0
- package/dist/adapters/block.d.ts.map +1 -0
- package/dist/adapters/block.js +38 -0
- package/dist/adapters/block.js.map +1 -0
- package/dist/adapters/ci.d.ts +39 -0
- package/dist/adapters/ci.d.ts.map +1 -0
- package/dist/adapters/ci.js +98 -0
- package/dist/adapters/ci.js.map +1 -0
- package/dist/adapters/hooks.d.ts +5 -0
- package/dist/adapters/hooks.d.ts.map +1 -0
- package/dist/adapters/hooks.js +58 -0
- package/dist/adapters/hooks.js.map +1 -0
- package/dist/adapters/install.d.ts +29 -0
- package/dist/adapters/install.d.ts.map +1 -0
- package/dist/adapters/install.js +101 -0
- package/dist/adapters/install.js.map +1 -0
- package/dist/adapters/instructions.d.ts +23 -0
- package/dist/adapters/instructions.d.ts.map +1 -0
- package/dist/adapters/instructions.js +69 -0
- package/dist/adapters/instructions.js.map +1 -0
- package/dist/adapters/mcp.d.ts +11 -0
- package/dist/adapters/mcp.d.ts.map +1 -0
- package/dist/adapters/mcp.js +76 -0
- package/dist/adapters/mcp.js.map +1 -0
- package/dist/adapters/skills.d.ts +6 -0
- package/dist/adapters/skills.d.ts.map +1 -0
- package/dist/adapters/skills.js +20 -0
- package/dist/adapters/skills.js.map +1 -0
- package/dist/agents/api.d.ts +3 -0
- package/dist/agents/api.d.ts.map +1 -0
- package/dist/agents/api.js +90 -0
- package/dist/agents/api.js.map +1 -0
- package/dist/agents/cli-backend.d.ts +55 -0
- package/dist/agents/cli-backend.d.ts.map +1 -0
- package/dist/agents/cli-backend.js +138 -0
- package/dist/agents/cli-backend.js.map +1 -0
- package/dist/agents/registry.d.ts +19 -0
- package/dist/agents/registry.d.ts.map +1 -0
- package/dist/agents/registry.js +115 -0
- package/dist/agents/registry.js.map +1 -0
- package/dist/agents/types.d.ts +45 -0
- package/dist/agents/types.d.ts.map +1 -0
- package/dist/agents/types.js +12 -0
- package/dist/agents/types.js.map +1 -0
- package/dist/analysis/findings.d.ts +35 -0
- package/dist/analysis/findings.d.ts.map +1 -0
- package/dist/analysis/findings.js +229 -0
- package/dist/analysis/findings.js.map +1 -0
- package/dist/changes/graph.d.ts +5 -0
- package/dist/changes/graph.d.ts.map +1 -0
- package/dist/changes/graph.js +126 -0
- package/dist/changes/graph.js.map +1 -0
- package/dist/changes/schema.d.ts +81 -0
- package/dist/changes/schema.d.ts.map +1 -0
- package/dist/changes/schema.js +32 -0
- package/dist/changes/schema.js.map +1 -0
- package/dist/changes/store.d.ts +5 -0
- package/dist/changes/store.d.ts.map +1 -0
- package/dist/changes/store.js +96 -0
- package/dist/changes/store.js.map +1 -0
- package/dist/cli.d.ts +12 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +865 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/answer.d.ts +24 -0
- package/dist/commands/answer.d.ts.map +1 -0
- package/dist/commands/answer.js +104 -0
- package/dist/commands/answer.js.map +1 -0
- package/dist/commands/ask.d.ts +25 -0
- package/dist/commands/ask.d.ts.map +1 -0
- package/dist/commands/ask.js +106 -0
- package/dist/commands/ask.js.map +1 -0
- package/dist/commands/bootstrap.d.ts +22 -0
- package/dist/commands/bootstrap.d.ts.map +1 -0
- package/dist/commands/bootstrap.js +168 -0
- package/dist/commands/bootstrap.js.map +1 -0
- package/dist/commands/change.d.ts +18 -0
- package/dist/commands/change.d.ts.map +1 -0
- package/dist/commands/change.js +136 -0
- package/dist/commands/change.js.map +1 -0
- package/dist/commands/check.d.ts +26 -0
- package/dist/commands/check.d.ts.map +1 -0
- package/dist/commands/check.js +115 -0
- package/dist/commands/check.js.map +1 -0
- package/dist/commands/doctor.d.ts +24 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +110 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/extract.d.ts +23 -0
- package/dist/commands/extract.d.ts.map +1 -0
- package/dist/commands/extract.js +179 -0
- package/dist/commands/extract.js.map +1 -0
- package/dist/commands/feature.d.ts +29 -0
- package/dist/commands/feature.d.ts.map +1 -0
- package/dist/commands/feature.js +117 -0
- package/dist/commands/feature.js.map +1 -0
- package/dist/commands/fleet.d.ts +22 -0
- package/dist/commands/fleet.d.ts.map +1 -0
- package/dist/commands/fleet.js +56 -0
- package/dist/commands/fleet.js.map +1 -0
- package/dist/commands/handoff.d.ts +14 -0
- package/dist/commands/handoff.d.ts.map +1 -0
- package/dist/commands/handoff.js +133 -0
- package/dist/commands/handoff.js.map +1 -0
- package/dist/commands/impact.d.ts +13 -0
- package/dist/commands/impact.d.ts.map +1 -0
- package/dist/commands/impact.js +105 -0
- package/dist/commands/impact.js.map +1 -0
- package/dist/commands/index-graph.d.ts +14 -0
- package/dist/commands/index-graph.d.ts.map +1 -0
- package/dist/commands/index-graph.js +297 -0
- package/dist/commands/index-graph.js.map +1 -0
- package/dist/commands/init.d.ts +36 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +107 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/legacy.d.ts +53 -0
- package/dist/commands/legacy.d.ts.map +1 -0
- package/dist/commands/legacy.js +539 -0
- package/dist/commands/legacy.js.map +1 -0
- package/dist/commands/migrate.d.ts +10 -0
- package/dist/commands/migrate.d.ts.map +1 -0
- package/dist/commands/migrate.js +30 -0
- package/dist/commands/migrate.js.map +1 -0
- package/dist/commands/pilot.d.ts +10 -0
- package/dist/commands/pilot.d.ts.map +1 -0
- package/dist/commands/pilot.js +20 -0
- package/dist/commands/pilot.js.map +1 -0
- package/dist/commands/plan.d.ts +35 -0
- package/dist/commands/plan.d.ts.map +1 -0
- package/dist/commands/plan.js +144 -0
- package/dist/commands/plan.js.map +1 -0
- package/dist/commands/policy.d.ts +28 -0
- package/dist/commands/policy.d.ts.map +1 -0
- package/dist/commands/policy.js +69 -0
- package/dist/commands/policy.js.map +1 -0
- package/dist/commands/query-graph.d.ts +32 -0
- package/dist/commands/query-graph.d.ts.map +1 -0
- package/dist/commands/query-graph.js +109 -0
- package/dist/commands/query-graph.js.map +1 -0
- package/dist/commands/report.d.ts +18 -0
- package/dist/commands/report.d.ts.map +1 -0
- package/dist/commands/report.js +119 -0
- package/dist/commands/report.js.map +1 -0
- package/dist/commands/security.d.ts +19 -0
- package/dist/commands/security.d.ts.map +1 -0
- package/dist/commands/security.js +66 -0
- package/dist/commands/security.js.map +1 -0
- package/dist/commands/session.d.ts +15 -0
- package/dist/commands/session.d.ts.map +1 -0
- package/dist/commands/session.js +95 -0
- package/dist/commands/session.js.map +1 -0
- package/dist/commands/status.d.ts +17 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +51 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/sync.d.ts +25 -0
- package/dist/commands/sync.d.ts.map +1 -0
- package/dist/commands/sync.js +54 -0
- package/dist/commands/sync.js.map +1 -0
- package/dist/commands/trace.d.ts +20 -0
- package/dist/commands/trace.d.ts.map +1 -0
- package/dist/commands/trace.js +92 -0
- package/dist/commands/trace.js.map +1 -0
- package/dist/commands/triage.d.ts +26 -0
- package/dist/commands/triage.d.ts.map +1 -0
- package/dist/commands/triage.js +191 -0
- package/dist/commands/triage.js.map +1 -0
- package/dist/config/define.d.ts +10 -0
- package/dist/config/define.d.ts.map +1 -0
- package/dist/config/define.js +11 -0
- package/dist/config/define.js.map +1 -0
- package/dist/config/gitignore.d.ts +44 -0
- package/dist/config/gitignore.d.ts.map +1 -0
- package/dist/config/gitignore.js +75 -0
- package/dist/config/gitignore.js.map +1 -0
- package/dist/config/load.d.ts +21 -0
- package/dist/config/load.d.ts.map +1 -0
- package/dist/config/load.js +158 -0
- package/dist/config/load.js.map +1 -0
- package/dist/config/paths.d.ts +41 -0
- package/dist/config/paths.d.ts.map +1 -0
- package/dist/config/paths.js +51 -0
- package/dist/config/paths.js.map +1 -0
- package/dist/config/schema.d.ts +356 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +195 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/detect/signatures.d.ts +28 -0
- package/dist/detect/signatures.d.ts.map +1 -0
- package/dist/detect/signatures.js +207 -0
- package/dist/detect/signatures.js.map +1 -0
- package/dist/detect/stack.d.ts +42 -0
- package/dist/detect/stack.d.ts.map +1 -0
- package/dist/detect/stack.js +199 -0
- package/dist/detect/stack.js.map +1 -0
- package/dist/detect/workspaces.d.ts +26 -0
- package/dist/detect/workspaces.d.ts.map +1 -0
- package/dist/detect/workspaces.js +72 -0
- package/dist/detect/workspaces.js.map +1 -0
- package/dist/extract/config/index.d.ts +31 -0
- package/dist/extract/config/index.d.ts.map +1 -0
- package/dist/extract/config/index.js +226 -0
- package/dist/extract/config/index.js.map +1 -0
- package/dist/extract/deps/index.d.ts +13 -0
- package/dist/extract/deps/index.d.ts.map +1 -0
- package/dist/extract/deps/index.js +211 -0
- package/dist/extract/deps/index.js.map +1 -0
- package/dist/extract/endpoints/django.d.ts +50 -0
- package/dist/extract/endpoints/django.d.ts.map +1 -0
- package/dist/extract/endpoints/django.js +258 -0
- package/dist/extract/endpoints/django.js.map +1 -0
- package/dist/extract/endpoints/express.d.ts +42 -0
- package/dist/extract/endpoints/express.d.ts.map +1 -0
- package/dist/extract/endpoints/express.js +454 -0
- package/dist/extract/endpoints/express.js.map +1 -0
- package/dist/extract/endpoints/fastapi.d.ts +41 -0
- package/dist/extract/endpoints/fastapi.d.ts.map +1 -0
- package/dist/extract/endpoints/fastapi.js +227 -0
- package/dist/extract/endpoints/fastapi.js.map +1 -0
- package/dist/extract/endpoints/index.d.ts +10 -0
- package/dist/extract/endpoints/index.d.ts.map +1 -0
- package/dist/extract/endpoints/index.js +129 -0
- package/dist/extract/endpoints/index.js.map +1 -0
- package/dist/extract/endpoints/nest.d.ts +16 -0
- package/dist/extract/endpoints/nest.d.ts.map +1 -0
- package/dist/extract/endpoints/nest.js +141 -0
- package/dist/extract/endpoints/nest.js.map +1 -0
- package/dist/extract/endpoints/next-api.d.ts +20 -0
- package/dist/extract/endpoints/next-api.d.ts.map +1 -0
- package/dist/extract/endpoints/next-api.js +145 -0
- package/dist/extract/endpoints/next-api.js.map +1 -0
- package/dist/extract/endpoints/openapi.d.ts +41 -0
- package/dist/extract/endpoints/openapi.d.ts.map +1 -0
- package/dist/extract/endpoints/openapi.js +191 -0
- package/dist/extract/endpoints/openapi.js.map +1 -0
- package/dist/extract/endpoints/paths.d.ts +6 -0
- package/dist/extract/endpoints/paths.d.ts.map +1 -0
- package/dist/extract/endpoints/paths.js +24 -0
- package/dist/extract/endpoints/paths.js.map +1 -0
- package/dist/extract/endpoints/python.d.ts +35 -0
- package/dist/extract/endpoints/python.d.ts.map +1 -0
- package/dist/extract/endpoints/python.js +143 -0
- package/dist/extract/endpoints/python.js.map +1 -0
- package/dist/extract/jobs/amqp.d.ts +19 -0
- package/dist/extract/jobs/amqp.d.ts.map +1 -0
- package/dist/extract/jobs/amqp.js +67 -0
- package/dist/extract/jobs/amqp.js.map +1 -0
- package/dist/extract/jobs/code-jobs.d.ts +12 -0
- package/dist/extract/jobs/code-jobs.d.ts.map +1 -0
- package/dist/extract/jobs/code-jobs.js +218 -0
- package/dist/extract/jobs/code-jobs.js.map +1 -0
- package/dist/extract/jobs/index.d.ts +12 -0
- package/dist/extract/jobs/index.d.ts.map +1 -0
- package/dist/extract/jobs/index.js +132 -0
- package/dist/extract/jobs/index.js.map +1 -0
- package/dist/extract/jobs/manifests.d.ts +26 -0
- package/dist/extract/jobs/manifests.d.ts.map +1 -0
- package/dist/extract/jobs/manifests.js +127 -0
- package/dist/extract/jobs/manifests.js.map +1 -0
- package/dist/extract/registry.d.ts +7 -0
- package/dist/extract/registry.d.ts.map +1 -0
- package/dist/extract/registry.js +33 -0
- package/dist/extract/registry.js.map +1 -0
- package/dist/extract/routes/detect.d.ts +28 -0
- package/dist/extract/routes/detect.d.ts.map +1 -0
- package/dist/extract/routes/detect.js +103 -0
- package/dist/extract/routes/detect.js.map +1 -0
- package/dist/extract/routes/index.d.ts +11 -0
- package/dist/extract/routes/index.d.ts.map +1 -0
- package/dist/extract/routes/index.js +160 -0
- package/dist/extract/routes/index.js.map +1 -0
- package/dist/extract/routes/middleware.d.ts +47 -0
- package/dist/extract/routes/middleware.d.ts.map +1 -0
- package/dist/extract/routes/middleware.js +223 -0
- package/dist/extract/routes/middleware.js.map +1 -0
- package/dist/extract/routes/next-fs.d.ts +32 -0
- package/dist/extract/routes/next-fs.d.ts.map +1 -0
- package/dist/extract/routes/next-fs.js +187 -0
- package/dist/extract/routes/next-fs.js.map +1 -0
- package/dist/extract/routes/react-router.d.ts +13 -0
- package/dist/extract/routes/react-router.d.ts.map +1 -0
- package/dist/extract/routes/react-router.js +315 -0
- package/dist/extract/routes/react-router.js.map +1 -0
- package/dist/extract/routes/segments.d.ts +42 -0
- package/dist/extract/routes/segments.d.ts.map +1 -0
- package/dist/extract/routes/segments.js +103 -0
- package/dist/extract/routes/segments.js.map +1 -0
- package/dist/extract/schema/decorated-orm.d.ts +14 -0
- package/dist/extract/schema/decorated-orm.d.ts.map +1 -0
- package/dist/extract/schema/decorated-orm.js +250 -0
- package/dist/extract/schema/decorated-orm.js.map +1 -0
- package/dist/extract/schema/index.d.ts +4 -0
- package/dist/extract/schema/index.d.ts.map +1 -0
- package/dist/extract/schema/index.js +113 -0
- package/dist/extract/schema/index.js.map +1 -0
- package/dist/extract/schema/mongoose.d.ts +19 -0
- package/dist/extract/schema/mongoose.d.ts.map +1 -0
- package/dist/extract/schema/mongoose.js +284 -0
- package/dist/extract/schema/mongoose.js.map +1 -0
- package/dist/extract/schema/prisma.d.ts +17 -0
- package/dist/extract/schema/prisma.d.ts.map +1 -0
- package/dist/extract/schema/prisma.js +187 -0
- package/dist/extract/schema/prisma.js.map +1 -0
- package/dist/extract/schema/python-models.d.ts +22 -0
- package/dist/extract/schema/python-models.d.ts.map +1 -0
- package/dist/extract/schema/python-models.js +201 -0
- package/dist/extract/schema/python-models.js.map +1 -0
- package/dist/extract/schema/sql-ddl.d.ts +30 -0
- package/dist/extract/schema/sql-ddl.d.ts.map +1 -0
- package/dist/extract/schema/sql-ddl.js +364 -0
- package/dist/extract/schema/sql-ddl.js.map +1 -0
- package/dist/extract/schema/types.d.ts +24 -0
- package/dist/extract/schema/types.d.ts.map +1 -0
- package/dist/extract/schema/types.js +2 -0
- package/dist/extract/schema/types.js.map +1 -0
- package/dist/extract/types.d.ts +37 -0
- package/dist/extract/types.d.ts.map +1 -0
- package/dist/extract/types.js +40 -0
- package/dist/extract/types.js.map +1 -0
- package/dist/features/graph.d.ts +12 -0
- package/dist/features/graph.d.ts.map +1 -0
- package/dist/features/graph.js +80 -0
- package/dist/features/graph.js.map +1 -0
- package/dist/features/history.d.ts +15 -0
- package/dist/features/history.d.ts.map +1 -0
- package/dist/features/history.js +44 -0
- package/dist/features/history.js.map +1 -0
- package/dist/features/schema.d.ts +94 -0
- package/dist/features/schema.d.ts.map +1 -0
- package/dist/features/schema.js +44 -0
- package/dist/features/schema.js.map +1 -0
- package/dist/features/store.d.ts +5 -0
- package/dist/features/store.d.ts.map +1 -0
- package/dist/features/store.js +122 -0
- package/dist/features/store.js.map +1 -0
- package/dist/governance/evaluate.d.ts +35 -0
- package/dist/governance/evaluate.d.ts.map +1 -0
- package/dist/governance/evaluate.js +156 -0
- package/dist/governance/evaluate.js.map +1 -0
- package/dist/governance/expected.d.ts +4 -0
- package/dist/governance/expected.d.ts.map +1 -0
- package/dist/governance/expected.js +51 -0
- package/dist/governance/expected.js.map +1 -0
- package/dist/governance/render.d.ts +22 -0
- package/dist/governance/render.d.ts.map +1 -0
- package/dist/governance/render.js +127 -0
- package/dist/governance/render.js.map +1 -0
- package/dist/governance/schema.d.ts +104 -0
- package/dist/governance/schema.d.ts.map +1 -0
- package/dist/governance/schema.js +26 -0
- package/dist/governance/schema.js.map +1 -0
- package/dist/governance/store.d.ts +9 -0
- package/dist/governance/store.d.ts.map +1 -0
- package/dist/governance/store.js +55 -0
- package/dist/governance/store.js.map +1 -0
- package/dist/graph/builder.d.ts +12 -0
- package/dist/graph/builder.d.ts.map +1 -0
- package/dist/graph/builder.js +218 -0
- package/dist/graph/builder.js.map +1 -0
- package/dist/graph/fingerprints.d.ts +36 -0
- package/dist/graph/fingerprints.d.ts.map +1 -0
- package/dist/graph/fingerprints.js +160 -0
- package/dist/graph/fingerprints.js.map +1 -0
- package/dist/graph/from-extraction.d.ts +5 -0
- package/dist/graph/from-extraction.d.ts.map +1 -0
- package/dist/graph/from-extraction.js +388 -0
- package/dist/graph/from-extraction.js.map +1 -0
- package/dist/graph/ids.d.ts +6 -0
- package/dist/graph/ids.d.ts.map +1 -0
- package/dist/graph/ids.js +13 -0
- package/dist/graph/ids.js.map +1 -0
- package/dist/graph/impact-summary.d.ts +17 -0
- package/dist/graph/impact-summary.d.ts.map +1 -0
- package/dist/graph/impact-summary.js +88 -0
- package/dist/graph/impact-summary.js.map +1 -0
- package/dist/graph/impact.d.ts +29 -0
- package/dist/graph/impact.d.ts.map +1 -0
- package/dist/graph/impact.js +101 -0
- package/dist/graph/impact.js.map +1 -0
- package/dist/graph/language-adapters.d.ts +42 -0
- package/dist/graph/language-adapters.d.ts.map +1 -0
- package/dist/graph/language-adapters.js +106 -0
- package/dist/graph/language-adapters.js.map +1 -0
- package/dist/graph/partition-store.d.ts +13 -0
- package/dist/graph/partition-store.d.ts.map +1 -0
- package/dist/graph/partition-store.js +129 -0
- package/dist/graph/partition-store.js.map +1 -0
- package/dist/graph/partitions.d.ts +79 -0
- package/dist/graph/partitions.d.ts.map +1 -0
- package/dist/graph/partitions.js +269 -0
- package/dist/graph/partitions.js.map +1 -0
- package/dist/graph/python-symbols.d.ts +10 -0
- package/dist/graph/python-symbols.d.ts.map +1 -0
- package/dist/graph/python-symbols.js +627 -0
- package/dist/graph/python-symbols.js.map +1 -0
- package/dist/graph/query.d.ts +43 -0
- package/dist/graph/query.d.ts.map +1 -0
- package/dist/graph/query.js +135 -0
- package/dist/graph/query.js.map +1 -0
- package/dist/graph/serialize.d.ts +4 -0
- package/dist/graph/serialize.d.ts.map +1 -0
- package/dist/graph/serialize.js +13 -0
- package/dist/graph/serialize.js.map +1 -0
- package/dist/graph/store.d.ts +230 -0
- package/dist/graph/store.d.ts.map +1 -0
- package/dist/graph/store.js +174 -0
- package/dist/graph/store.js.map +1 -0
- package/dist/graph/surfaces.d.ts +12 -0
- package/dist/graph/surfaces.d.ts.map +1 -0
- package/dist/graph/surfaces.js +158 -0
- package/dist/graph/surfaces.js.map +1 -0
- package/dist/graph/symbols.d.ts +10 -0
- package/dist/graph/symbols.d.ts.map +1 -0
- package/dist/graph/symbols.js +1306 -0
- package/dist/graph/symbols.js.map +1 -0
- package/dist/graph/types.d.ts +53 -0
- package/dist/graph/types.d.ts.map +1 -0
- package/dist/graph/types.js +51 -0
- package/dist/graph/types.js.map +1 -0
- package/dist/handoff/render.d.ts +26 -0
- package/dist/handoff/render.d.ts.map +1 -0
- package/dist/handoff/render.js +122 -0
- package/dist/handoff/render.js.map +1 -0
- package/dist/index.d.ts +98 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +67 -0
- package/dist/index.js.map +1 -0
- package/dist/infer/behaviour.d.ts +34 -0
- package/dist/infer/behaviour.d.ts.map +1 -0
- package/dist/infer/behaviour.js +175 -0
- package/dist/infer/behaviour.js.map +1 -0
- package/dist/infer/cards.d.ts +63 -0
- package/dist/infer/cards.d.ts.map +1 -0
- package/dist/infer/cards.js +237 -0
- package/dist/infer/cards.js.map +1 -0
- package/dist/infer/context.d.ts +37 -0
- package/dist/infer/context.d.ts.map +1 -0
- package/dist/infer/context.js +181 -0
- package/dist/infer/context.js.map +1 -0
- package/dist/infer/facts.d.ts +20 -0
- package/dist/infer/facts.d.ts.map +1 -0
- package/dist/infer/facts.js +44 -0
- package/dist/infer/facts.js.map +1 -0
- package/dist/infer/graph-context.d.ts +19 -0
- package/dist/infer/graph-context.d.ts.map +1 -0
- package/dist/infer/graph-context.js +95 -0
- package/dist/infer/graph-context.js.map +1 -0
- package/dist/infer/store.d.ts +14 -0
- package/dist/infer/store.d.ts.map +1 -0
- package/dist/infer/store.js +98 -0
- package/dist/infer/store.js.map +1 -0
- package/dist/infer/types.d.ts +310 -0
- package/dist/infer/types.d.ts.map +1 -0
- package/dist/infer/types.js +57 -0
- package/dist/infer/types.js.map +1 -0
- package/dist/infer/write-behaviour.d.ts +25 -0
- package/dist/infer/write-behaviour.d.ts.map +1 -0
- package/dist/infer/write-behaviour.js +63 -0
- package/dist/infer/write-behaviour.js.map +1 -0
- package/dist/legacy/inventory.d.ts +23 -0
- package/dist/legacy/inventory.d.ts.map +1 -0
- package/dist/legacy/inventory.js +148 -0
- package/dist/legacy/inventory.js.map +1 -0
- package/dist/legacy/mapping.d.ts +12 -0
- package/dist/legacy/mapping.d.ts.map +1 -0
- package/dist/legacy/mapping.js +170 -0
- package/dist/legacy/mapping.js.map +1 -0
- package/dist/legacy/plans.d.ts +148 -0
- package/dist/legacy/plans.d.ts.map +1 -0
- package/dist/legacy/plans.js +152 -0
- package/dist/legacy/plans.js.map +1 -0
- package/dist/legacy/schema.d.ts +784 -0
- package/dist/legacy/schema.d.ts.map +1 -0
- package/dist/legacy/schema.js +134 -0
- package/dist/legacy/schema.js.map +1 -0
- package/dist/legacy/store.d.ts +8 -0
- package/dist/legacy/store.d.ts.map +1 -0
- package/dist/legacy/store.js +109 -0
- package/dist/legacy/store.js.map +1 -0
- package/dist/mcp/server.d.ts +15 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +137 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/migrations/engine.d.ts +18 -0
- package/dist/migrations/engine.d.ts.map +1 -0
- package/dist/migrations/engine.js +270 -0
- package/dist/migrations/engine.js.map +1 -0
- package/dist/migrations/schema.d.ts +89 -0
- package/dist/migrations/schema.d.ts.map +1 -0
- package/dist/migrations/schema.js +19 -0
- package/dist/migrations/schema.js.map +1 -0
- package/dist/pilot/evaluate.d.ts +36 -0
- package/dist/pilot/evaluate.d.ts.map +1 -0
- package/dist/pilot/evaluate.js +102 -0
- package/dist/pilot/evaluate.js.map +1 -0
- package/dist/pilot/schema.d.ts +132 -0
- package/dist/pilot/schema.d.ts.map +1 -0
- package/dist/pilot/schema.js +22 -0
- package/dist/pilot/schema.js.map +1 -0
- package/dist/pipeline.d.ts +53 -0
- package/dist/pipeline.d.ts.map +1 -0
- package/dist/pipeline.js +100 -0
- package/dist/pipeline.js.map +1 -0
- package/dist/plans/graph.d.ts +5 -0
- package/dist/plans/graph.d.ts.map +1 -0
- package/dist/plans/graph.js +85 -0
- package/dist/plans/graph.js.map +1 -0
- package/dist/plans/schema.d.ts +167 -0
- package/dist/plans/schema.d.ts.map +1 -0
- package/dist/plans/schema.js +63 -0
- package/dist/plans/schema.js.map +1 -0
- package/dist/plans/store.d.ts +14 -0
- package/dist/plans/store.d.ts.map +1 -0
- package/dist/plans/store.js +156 -0
- package/dist/plans/store.js.map +1 -0
- package/dist/privacy/redact.d.ts +8 -0
- package/dist/privacy/redact.d.ts.map +1 -0
- package/dist/privacy/redact.js +28 -0
- package/dist/privacy/redact.js.map +1 -0
- package/dist/questions/queue.d.ts +62 -0
- package/dist/questions/queue.d.ts.map +1 -0
- package/dist/questions/queue.js +81 -0
- package/dist/questions/queue.js.map +1 -0
- package/dist/questions/store.d.ts +55 -0
- package/dist/questions/store.d.ts.map +1 -0
- package/dist/questions/store.js +123 -0
- package/dist/questions/store.js.map +1 -0
- package/dist/render/common.d.ts +24 -0
- package/dist/render/common.d.ts.map +1 -0
- package/dist/render/common.js +72 -0
- package/dist/render/common.js.map +1 -0
- package/dist/render/diagrams.d.ts +26 -0
- package/dist/render/diagrams.d.ts.map +1 -0
- package/dist/render/diagrams.js +255 -0
- package/dist/render/diagrams.js.map +1 -0
- package/dist/render/index.d.ts +36 -0
- package/dist/render/index.d.ts.map +1 -0
- package/dist/render/index.js +164 -0
- package/dist/render/index.js.map +1 -0
- package/dist/render/markdown.d.ts +59 -0
- package/dist/render/markdown.d.ts.map +1 -0
- package/dist/render/markdown.js +102 -0
- package/dist/render/markdown.js.map +1 -0
- package/dist/render/mermaid-validate.d.ts +22 -0
- package/dist/render/mermaid-validate.d.ts.map +1 -0
- package/dist/render/mermaid-validate.js +147 -0
- package/dist/render/mermaid-validate.js.map +1 -0
- package/dist/render/pages/api.d.ts +14 -0
- package/dist/render/pages/api.d.ts.map +1 -0
- package/dist/render/pages/api.js +86 -0
- package/dist/render/pages/api.js.map +1 -0
- package/dist/render/pages/config.d.ts +16 -0
- package/dist/render/pages/config.d.ts.map +1 -0
- package/dist/render/pages/config.js +67 -0
- package/dist/render/pages/config.js.map +1 -0
- package/dist/render/pages/jobs.d.ts +17 -0
- package/dist/render/pages/jobs.d.ts.map +1 -0
- package/dist/render/pages/jobs.js +61 -0
- package/dist/render/pages/jobs.js.map +1 -0
- package/dist/render/pages/readme.d.ts +18 -0
- package/dist/render/pages/readme.d.ts.map +1 -0
- package/dist/render/pages/readme.js +176 -0
- package/dist/render/pages/readme.js.map +1 -0
- package/dist/render/pages/routes.d.ts +17 -0
- package/dist/render/pages/routes.d.ts.map +1 -0
- package/dist/render/pages/routes.js +71 -0
- package/dist/render/pages/routes.js.map +1 -0
- package/dist/render/pages/schema.d.ts +11 -0
- package/dist/render/pages/schema.d.ts.map +1 -0
- package/dist/render/pages/schema.js +84 -0
- package/dist/render/pages/schema.js.map +1 -0
- package/dist/render/projection.d.ts +21 -0
- package/dist/render/projection.d.ts.map +1 -0
- package/dist/render/projection.js +64 -0
- package/dist/render/projection.js.map +1 -0
- package/dist/requirements/graph.d.ts +11 -0
- package/dist/requirements/graph.d.ts.map +1 -0
- package/dist/requirements/graph.js +112 -0
- package/dist/requirements/graph.js.map +1 -0
- package/dist/requirements/pending.d.ts +22 -0
- package/dist/requirements/pending.d.ts.map +1 -0
- package/dist/requirements/pending.js +21 -0
- package/dist/requirements/pending.js.map +1 -0
- package/dist/requirements/render.d.ts +21 -0
- package/dist/requirements/render.d.ts.map +1 -0
- package/dist/requirements/render.js +85 -0
- package/dist/requirements/render.js.map +1 -0
- package/dist/requirements/store.d.ts +37 -0
- package/dist/requirements/store.d.ts.map +1 -0
- package/dist/requirements/store.js +179 -0
- package/dist/requirements/store.js.map +1 -0
- package/dist/requirements/types.d.ts +46 -0
- package/dist/requirements/types.d.ts.map +1 -0
- package/dist/requirements/types.js +31 -0
- package/dist/requirements/types.js.map +1 -0
- package/dist/security/sbom.d.ts +41 -0
- package/dist/security/sbom.d.ts.map +1 -0
- package/dist/security/sbom.js +68 -0
- package/dist/security/sbom.js.map +1 -0
- package/dist/security/scan.d.ts +3 -0
- package/dist/security/scan.d.ts.map +1 -0
- package/dist/security/scan.js +327 -0
- package/dist/security/scan.js.map +1 -0
- package/dist/security/types.d.ts +38 -0
- package/dist/security/types.d.ts.map +1 -0
- package/dist/security/types.js +2 -0
- package/dist/security/types.js.map +1 -0
- package/dist/status/collect.d.ts +50 -0
- package/dist/status/collect.d.ts.map +1 -0
- package/dist/status/collect.js +73 -0
- package/dist/status/collect.js.map +1 -0
- package/dist/status/render.d.ts +22 -0
- package/dist/status/render.d.ts.map +1 -0
- package/dist/status/render.js +104 -0
- package/dist/status/render.js.map +1 -0
- package/dist/surface/chunk.d.ts +23 -0
- package/dist/surface/chunk.d.ts.map +1 -0
- package/dist/surface/chunk.js +238 -0
- package/dist/surface/chunk.js.map +1 -0
- package/dist/surface/group.d.ts +45 -0
- package/dist/surface/group.d.ts.map +1 -0
- package/dist/surface/group.js +104 -0
- package/dist/surface/group.js.map +1 -0
- package/dist/surface/slug.d.ts +24 -0
- package/dist/surface/slug.d.ts.map +1 -0
- package/dist/surface/slug.js +55 -0
- package/dist/surface/slug.js.map +1 -0
- package/dist/surface/types.d.ts +55 -0
- package/dist/surface/types.d.ts.map +1 -0
- package/dist/surface/types.js +2 -0
- package/dist/surface/types.js.map +1 -0
- package/dist/trace/matrix.d.ts +48 -0
- package/dist/trace/matrix.d.ts.map +1 -0
- package/dist/trace/matrix.js +84 -0
- package/dist/trace/matrix.js.map +1 -0
- package/dist/trace/render.d.ts +27 -0
- package/dist/trace/render.d.ts.map +1 -0
- package/dist/trace/render.js +132 -0
- package/dist/trace/render.js.map +1 -0
- package/dist/trace/scan.d.ts +12 -0
- package/dist/trace/scan.d.ts.map +1 -0
- package/dist/trace/scan.js +49 -0
- package/dist/trace/scan.js.map +1 -0
- package/dist/types/core.d.ts +125 -0
- package/dist/types/core.d.ts.map +1 -0
- package/dist/types/core.js +15 -0
- package/dist/types/core.js.map +1 -0
- package/dist/types/entries.d.ts +151 -0
- package/dist/types/entries.d.ts.map +1 -0
- package/dist/types/entries.js +2 -0
- package/dist/types/entries.js.map +1 -0
- package/dist/util/atomic.d.ts +22 -0
- package/dist/util/atomic.d.ts.map +1 -0
- package/dist/util/atomic.js +68 -0
- package/dist/util/atomic.js.map +1 -0
- package/dist/util/boundaries.d.ts +23 -0
- package/dist/util/boundaries.d.ts.map +1 -0
- package/dist/util/boundaries.js +72 -0
- package/dist/util/boundaries.js.map +1 -0
- package/dist/util/capture.d.ts +4 -0
- package/dist/util/capture.d.ts.map +1 -0
- package/dist/util/capture.js +19 -0
- package/dist/util/capture.js.map +1 -0
- package/dist/util/colors.d.ts +21 -0
- package/dist/util/colors.d.ts.map +1 -0
- package/dist/util/colors.js +32 -0
- package/dist/util/colors.js.map +1 -0
- package/dist/util/errors.d.ts +26 -0
- package/dist/util/errors.d.ts.map +1 -0
- package/dist/util/errors.js +40 -0
- package/dist/util/errors.js.map +1 -0
- package/dist/util/git.d.ts +47 -0
- package/dist/util/git.d.ts.map +1 -0
- package/dist/util/git.js +183 -0
- package/dist/util/git.js.map +1 -0
- package/dist/util/logger.d.ts +20 -0
- package/dist/util/logger.d.ts.map +1 -0
- package/dist/util/logger.js +27 -0
- package/dist/util/logger.js.map +1 -0
- package/dist/util/modules.d.ts +71 -0
- package/dist/util/modules.d.ts.map +1 -0
- package/dist/util/modules.js +210 -0
- package/dist/util/modules.js.map +1 -0
- package/dist/util/paths.d.ts +14 -0
- package/dist/util/paths.d.ts.map +1 -0
- package/dist/util/paths.js +23 -0
- package/dist/util/paths.js.map +1 -0
- package/dist/util/sort.d.ts +11 -0
- package/dist/util/sort.d.ts.map +1 -0
- package/dist/util/sort.js +15 -0
- package/dist/util/sort.js.map +1 -0
- package/dist/util/ts-ast.d.ts +31 -0
- package/dist/util/ts-ast.d.ts.map +1 -0
- package/dist/util/ts-ast.js +84 -0
- package/dist/util/ts-ast.js.map +1 -0
- package/dist/util/tsconfig.d.ts +48 -0
- package/dist/util/tsconfig.d.ts.map +1 -0
- package/dist/util/tsconfig.js +141 -0
- package/dist/util/tsconfig.js.map +1 -0
- package/dist/util/version.d.ts +2 -0
- package/dist/util/version.d.ts.map +1 -0
- package/dist/util/version.js +37 -0
- package/dist/util/version.js.map +1 -0
- package/dist/verify/expected.d.ts +30 -0
- package/dist/verify/expected.d.ts.map +1 -0
- package/dist/verify/expected.js +143 -0
- package/dist/verify/expected.js.map +1 -0
- package/dist/verify/write.d.ts +25 -0
- package/dist/verify/write.d.ts.map +1 -0
- package/dist/verify/write.js +50 -0
- package/dist/verify/write.js.map +1 -0
- package/package.json +82 -0
- package/prompts/feature-card.v1.md +86 -0
- package/prompts/feature-card.v2.md +87 -0
|
@@ -0,0 +1,1306 @@
|
|
|
1
|
+
import fg from 'fast-glob';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { resolveImport } from '../util/modules.js';
|
|
5
|
+
import { readModuleBindings } from '../util/modules.js';
|
|
6
|
+
import { compareStrings } from '../util/sort.js';
|
|
7
|
+
import { loadPathAliases } from '../util/tsconfig.js';
|
|
8
|
+
import { literalString, parseSourceFile, positionOf, ts } from '../util/ts-ast.js';
|
|
9
|
+
import { toPosix } from '../util/paths.js';
|
|
10
|
+
import { EvidenceGraphBuilder } from './builder.js';
|
|
11
|
+
import { graphEdgeId, graphNodeId } from './ids.js';
|
|
12
|
+
function propertyName(node) {
|
|
13
|
+
if (node === undefined)
|
|
14
|
+
return undefined;
|
|
15
|
+
if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node))
|
|
16
|
+
return node.text;
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
function hasModifier(node, kind) {
|
|
20
|
+
return ts.canHaveModifiers(node) && ts.getModifiers(node)?.some((modifier) => modifier.kind === kind) === true;
|
|
21
|
+
}
|
|
22
|
+
function isExported(node) {
|
|
23
|
+
if (hasModifier(node, ts.SyntaxKind.ExportKeyword))
|
|
24
|
+
return true;
|
|
25
|
+
if (ts.isVariableDeclaration(node)) {
|
|
26
|
+
const statement = node.parent.parent;
|
|
27
|
+
return ts.isVariableStatement(statement) && hasModifier(statement, ts.SyntaxKind.ExportKeyword);
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
function isDefaultExport(node) {
|
|
32
|
+
return hasModifier(node, ts.SyntaxKind.DefaultKeyword);
|
|
33
|
+
}
|
|
34
|
+
function isAsync(node) {
|
|
35
|
+
return hasModifier(node, ts.SyntaxKind.AsyncKeyword);
|
|
36
|
+
}
|
|
37
|
+
function symbolProvenance(source) {
|
|
38
|
+
return {
|
|
39
|
+
origin: 'extracted',
|
|
40
|
+
extractionMethods: ['ast'],
|
|
41
|
+
certainty: 'high',
|
|
42
|
+
evidence: [source],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function symbolId(file, qualifiedName, kind) {
|
|
46
|
+
return graphNodeId('symbol', `${file}#${kind}:${qualifiedName}`);
|
|
47
|
+
}
|
|
48
|
+
function analyseModule(file, contents) {
|
|
49
|
+
const source = parseSourceFile(file, contents);
|
|
50
|
+
const symbols = [];
|
|
51
|
+
const symbolByNode = new Map();
|
|
52
|
+
const add = (args) => {
|
|
53
|
+
const qualifiedName = [...args.scope, args.name].join('.');
|
|
54
|
+
const exportedNames = [
|
|
55
|
+
...(args.exported === true ? [args.name] : []),
|
|
56
|
+
...(args.defaultExport === true ? ['default'] : []),
|
|
57
|
+
];
|
|
58
|
+
const record = {
|
|
59
|
+
id: symbolId(file, qualifiedName, args.kind),
|
|
60
|
+
file,
|
|
61
|
+
name: args.name,
|
|
62
|
+
qualifiedName,
|
|
63
|
+
scope: args.scope,
|
|
64
|
+
kind: args.kind,
|
|
65
|
+
source: positionOf(source, args.node, file),
|
|
66
|
+
node: args.node,
|
|
67
|
+
exportedNames,
|
|
68
|
+
isAsync: args.async === true,
|
|
69
|
+
};
|
|
70
|
+
symbols.push(record);
|
|
71
|
+
symbolByNode.set(args.node, record);
|
|
72
|
+
return record;
|
|
73
|
+
};
|
|
74
|
+
const visit = (node, scope) => {
|
|
75
|
+
if (ts.isFunctionDeclaration(node)) {
|
|
76
|
+
const name = node.name?.text ?? (isDefaultExport(node) ? 'default' : undefined);
|
|
77
|
+
if (name !== undefined) {
|
|
78
|
+
const record = add({
|
|
79
|
+
node,
|
|
80
|
+
name,
|
|
81
|
+
scope,
|
|
82
|
+
kind: 'function',
|
|
83
|
+
exported: isExported(node),
|
|
84
|
+
defaultExport: isDefaultExport(node),
|
|
85
|
+
async: isAsync(node),
|
|
86
|
+
});
|
|
87
|
+
node.forEachChild((child) => visit(child, [...scope, record.name]));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (ts.isClassDeclaration(node)) {
|
|
92
|
+
const name = node.name?.text ?? (isDefaultExport(node) ? 'default' : undefined);
|
|
93
|
+
if (name !== undefined) {
|
|
94
|
+
const record = add({
|
|
95
|
+
node,
|
|
96
|
+
name,
|
|
97
|
+
scope,
|
|
98
|
+
kind: 'class',
|
|
99
|
+
exported: isExported(node),
|
|
100
|
+
defaultExport: isDefaultExport(node),
|
|
101
|
+
});
|
|
102
|
+
node.forEachChild((child) => visit(child, [...scope, record.name]));
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (ts.isInterfaceDeclaration(node)) {
|
|
107
|
+
const record = add({
|
|
108
|
+
node,
|
|
109
|
+
name: node.name.text,
|
|
110
|
+
scope,
|
|
111
|
+
kind: 'interface',
|
|
112
|
+
exported: isExported(node),
|
|
113
|
+
});
|
|
114
|
+
node.forEachChild((child) => visit(child, [...scope, record.name]));
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (ts.isMethodDeclaration(node) || ts.isMethodSignature(node) || ts.isConstructorDeclaration(node)) {
|
|
118
|
+
const constructor = ts.isConstructorDeclaration(node);
|
|
119
|
+
const name = constructor ? 'constructor' : propertyName(node.name);
|
|
120
|
+
if (name !== undefined) {
|
|
121
|
+
const record = add({
|
|
122
|
+
node,
|
|
123
|
+
name,
|
|
124
|
+
scope,
|
|
125
|
+
kind: constructor ? 'constructor' : 'method',
|
|
126
|
+
async: isAsync(node),
|
|
127
|
+
});
|
|
128
|
+
node.forEachChild((child) => visit(child, [...scope, record.name]));
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (ts.isVariableDeclaration(node) &&
|
|
133
|
+
ts.isIdentifier(node.name) &&
|
|
134
|
+
node.initializer !== undefined &&
|
|
135
|
+
(ts.isArrowFunction(node.initializer) || ts.isFunctionExpression(node.initializer))) {
|
|
136
|
+
const record = add({
|
|
137
|
+
node,
|
|
138
|
+
name: node.name.text,
|
|
139
|
+
scope,
|
|
140
|
+
kind: 'function',
|
|
141
|
+
exported: isExported(node),
|
|
142
|
+
async: isAsync(node.initializer),
|
|
143
|
+
});
|
|
144
|
+
node.initializer.forEachChild((child) => visit(child, [...scope, record.name]));
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
node.forEachChild((child) => visit(child, scope));
|
|
148
|
+
};
|
|
149
|
+
visit(source, []);
|
|
150
|
+
// `export { local as public }` and `export default local` are separate AST
|
|
151
|
+
// statements. Attach those names after declarations have been collected.
|
|
152
|
+
const bindings = readModuleBindings(source);
|
|
153
|
+
const withBindings = symbols.map((record) => {
|
|
154
|
+
if (record.scope.length > 0)
|
|
155
|
+
return record;
|
|
156
|
+
const aliases = [...bindings.exports.entries()]
|
|
157
|
+
.filter(([, binding]) => binding.kind === 'local' && binding.localName === record.name)
|
|
158
|
+
.map(([name]) => name);
|
|
159
|
+
if (aliases.length === 0)
|
|
160
|
+
return record;
|
|
161
|
+
const updated = { ...record, exportedNames: [...new Set([...record.exportedNames, ...aliases])].sort(compareStrings) };
|
|
162
|
+
symbolByNode.set(record.node, updated);
|
|
163
|
+
return updated;
|
|
164
|
+
});
|
|
165
|
+
return {
|
|
166
|
+
file,
|
|
167
|
+
source,
|
|
168
|
+
symbols: withBindings.sort((a, b) => compareStrings(a.id, b.id)),
|
|
169
|
+
symbolByNode,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function nearestCaller(node, symbols) {
|
|
173
|
+
let current = node.parent;
|
|
174
|
+
while (current !== undefined) {
|
|
175
|
+
const symbol = symbols.get(current);
|
|
176
|
+
if (symbol !== undefined && symbol.kind !== 'class')
|
|
177
|
+
return symbol;
|
|
178
|
+
current = current.parent;
|
|
179
|
+
}
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
function scopeIsVisible(candidate, caller) {
|
|
183
|
+
if (candidate.scope.length > caller.scope.length)
|
|
184
|
+
return false;
|
|
185
|
+
return candidate.scope.every((part, index) => caller.scope[index] === part);
|
|
186
|
+
}
|
|
187
|
+
function resolveLocalSymbol(module, caller, name) {
|
|
188
|
+
const candidates = module.symbols
|
|
189
|
+
.filter((symbol) => symbol.name === name && scopeIsVisible(symbol, caller))
|
|
190
|
+
.sort((a, b) => b.scope.length - a.scope.length || compareStrings(a.id, b.id));
|
|
191
|
+
const best = candidates[0];
|
|
192
|
+
if (best === undefined)
|
|
193
|
+
return undefined;
|
|
194
|
+
if (candidates[1]?.scope.length === best.scope.length)
|
|
195
|
+
return undefined;
|
|
196
|
+
return best;
|
|
197
|
+
}
|
|
198
|
+
function bindingContainsName(name, expected) {
|
|
199
|
+
if (ts.isIdentifier(name))
|
|
200
|
+
return name.text === expected;
|
|
201
|
+
return name.elements.some((element) => ts.isBindingElement(element) && bindingContainsName(element.name, expected));
|
|
202
|
+
}
|
|
203
|
+
/** Conservatively avoid resolving a top-level symbol through a local value binding. */
|
|
204
|
+
function hasLocalValueBinding(module, caller, name) {
|
|
205
|
+
let found = false;
|
|
206
|
+
const visit = (node) => {
|
|
207
|
+
if (found)
|
|
208
|
+
return;
|
|
209
|
+
if (node !== caller.node && module.symbolByNode.has(node))
|
|
210
|
+
return;
|
|
211
|
+
if ((ts.isParameter(node) || ts.isVariableDeclaration(node) || ts.isBindingElement(node)) &&
|
|
212
|
+
bindingContainsName(node.name, name) &&
|
|
213
|
+
!module.symbolByNode.has(node)) {
|
|
214
|
+
found = true;
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
node.forEachChild(visit);
|
|
218
|
+
};
|
|
219
|
+
caller.node.forEachChild(visit);
|
|
220
|
+
return found;
|
|
221
|
+
}
|
|
222
|
+
function resolveValueExpression(module, caller, expression, context, kinds) {
|
|
223
|
+
if (ts.isIdentifier(expression)) {
|
|
224
|
+
if (hasLocalValueBinding(module, caller, expression.text))
|
|
225
|
+
return undefined;
|
|
226
|
+
const local = resolveLocalSymbol(module, caller, expression.text);
|
|
227
|
+
if (local !== undefined && (kinds === undefined || kinds.has(local.kind)))
|
|
228
|
+
return local;
|
|
229
|
+
return resolveTopLevelSymbol(module, expression.text, context, kinds);
|
|
230
|
+
}
|
|
231
|
+
if (ts.isPropertyAccessExpression(expression) && ts.isIdentifier(expression.expression)) {
|
|
232
|
+
return resolveNamespaceMember(module, expression.expression.text, expression.name.text, context, kinds);
|
|
233
|
+
}
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
function addSymbolNodes(builder, modules) {
|
|
237
|
+
for (const module of modules) {
|
|
238
|
+
const fileId = graphNodeId('file', module.file);
|
|
239
|
+
const fileRef = { file: module.file, line: 1 };
|
|
240
|
+
builder.addNode({ id: fileId, kind: 'file', label: module.file, provenance: symbolProvenance(fileRef) });
|
|
241
|
+
const byQualifiedName = new Map(module.symbols.map((symbol) => [symbol.qualifiedName, symbol]));
|
|
242
|
+
for (const symbol of module.symbols) {
|
|
243
|
+
const provenance = symbolProvenance(symbol.source);
|
|
244
|
+
builder.addNode({
|
|
245
|
+
id: symbol.id,
|
|
246
|
+
kind: 'symbol',
|
|
247
|
+
label: symbol.qualifiedName,
|
|
248
|
+
provenance,
|
|
249
|
+
properties: {
|
|
250
|
+
symbolKind: symbol.kind,
|
|
251
|
+
name: symbol.name,
|
|
252
|
+
exportedNames: symbol.exportedNames,
|
|
253
|
+
isAsync: symbol.isAsync,
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
builder.addEdge({
|
|
257
|
+
id: graphEdgeId('defined-in', symbol.id, fileId),
|
|
258
|
+
kind: 'defined-in',
|
|
259
|
+
from: symbol.id,
|
|
260
|
+
to: fileId,
|
|
261
|
+
provenance,
|
|
262
|
+
});
|
|
263
|
+
const parentName = symbol.scope.join('.');
|
|
264
|
+
const parent = parentName.length === 0 ? undefined : byQualifiedName.get(parentName);
|
|
265
|
+
if (parent !== undefined) {
|
|
266
|
+
builder.addEdge({
|
|
267
|
+
id: graphEdgeId('contains', parent.id, symbol.id),
|
|
268
|
+
kind: 'contains',
|
|
269
|
+
from: parent.id,
|
|
270
|
+
to: symbol.id,
|
|
271
|
+
provenance,
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
function exportedSymbol(module, name, kinds) {
|
|
278
|
+
const matches = module.symbols.filter((symbol) => symbol.scope.length === 0 &&
|
|
279
|
+
symbol.exportedNames.includes(name) &&
|
|
280
|
+
(kinds === undefined || kinds.has(symbol.kind)));
|
|
281
|
+
return matches.length === 1 ? matches[0] : undefined;
|
|
282
|
+
}
|
|
283
|
+
function emitsModule(context, file) {
|
|
284
|
+
return context.outputFiles === undefined || context.outputFiles.has(file);
|
|
285
|
+
}
|
|
286
|
+
/** Follow explicit and star re-exports without guessing through ambiguity. */
|
|
287
|
+
function resolveExportedSymbol(file, name, context, kinds, seen = new Set()) {
|
|
288
|
+
const key = `${file}#${name}`;
|
|
289
|
+
if (seen.has(key) || seen.size >= 16)
|
|
290
|
+
return undefined;
|
|
291
|
+
const nextSeen = new Set(seen).add(key);
|
|
292
|
+
const module = context.moduleByFile.get(file);
|
|
293
|
+
if (module === undefined)
|
|
294
|
+
return undefined;
|
|
295
|
+
const direct = exportedSymbol(module, name, kinds);
|
|
296
|
+
if (direct !== undefined)
|
|
297
|
+
return direct;
|
|
298
|
+
const bindings = context.bindingsByFile.get(file);
|
|
299
|
+
const explicit = bindings?.exports.get(name);
|
|
300
|
+
if (explicit?.kind === 'local') {
|
|
301
|
+
const matches = module.symbols.filter((symbol) => symbol.scope.length === 0 &&
|
|
302
|
+
symbol.name === explicit.localName &&
|
|
303
|
+
(kinds === undefined || kinds.has(symbol.kind)));
|
|
304
|
+
return matches.length === 1 ? matches[0] : undefined;
|
|
305
|
+
}
|
|
306
|
+
if (explicit?.kind === 'reexport') {
|
|
307
|
+
const target = resolveImport(file, explicit.specifier, context.files, context.aliases);
|
|
308
|
+
return target === undefined
|
|
309
|
+
? undefined
|
|
310
|
+
: resolveExportedSymbol(target, explicit.importedName, context, kinds, nextSeen);
|
|
311
|
+
}
|
|
312
|
+
const candidates = new Map();
|
|
313
|
+
for (const specifier of bindings?.starExports ?? []) {
|
|
314
|
+
const target = resolveImport(file, specifier, context.files, context.aliases);
|
|
315
|
+
if (target === undefined)
|
|
316
|
+
continue;
|
|
317
|
+
const candidate = resolveExportedSymbol(target, name, context, kinds, nextSeen);
|
|
318
|
+
if (candidate !== undefined)
|
|
319
|
+
candidates.set(candidate.id, candidate);
|
|
320
|
+
}
|
|
321
|
+
return candidates.size === 1 ? [...candidates.values()][0] : undefined;
|
|
322
|
+
}
|
|
323
|
+
function resolveTopLevelSymbol(module, name, context, kinds) {
|
|
324
|
+
const local = module.symbols.filter((symbol) => symbol.scope.length === 0 &&
|
|
325
|
+
symbol.name === name &&
|
|
326
|
+
(kinds === undefined || kinds.has(symbol.kind)));
|
|
327
|
+
if (local.length === 1)
|
|
328
|
+
return local[0];
|
|
329
|
+
if (local.length > 1)
|
|
330
|
+
return undefined;
|
|
331
|
+
const imported = context.bindingsByFile.get(module.file)?.imports.get(name);
|
|
332
|
+
if (imported === undefined || imported.importedName === '*')
|
|
333
|
+
return undefined;
|
|
334
|
+
const targetFile = resolveImport(module.file, imported.specifier, context.files, context.aliases);
|
|
335
|
+
return targetFile === undefined
|
|
336
|
+
? undefined
|
|
337
|
+
: resolveExportedSymbol(targetFile, imported.importedName, context, kinds);
|
|
338
|
+
}
|
|
339
|
+
function resolveNamespaceMember(module, namespace, member, context, kinds) {
|
|
340
|
+
const imported = context.bindingsByFile.get(module.file)?.imports.get(namespace);
|
|
341
|
+
if (imported?.importedName !== '*')
|
|
342
|
+
return undefined;
|
|
343
|
+
const target = resolveImport(module.file, imported.specifier, context.files, context.aliases);
|
|
344
|
+
return target === undefined ? undefined : resolveExportedSymbol(target, member, context, kinds);
|
|
345
|
+
}
|
|
346
|
+
function resolveTopLevelExpression(module, expression, context, kinds) {
|
|
347
|
+
if (ts.isIdentifier(expression)) {
|
|
348
|
+
return resolveTopLevelSymbol(module, expression.text, context, kinds);
|
|
349
|
+
}
|
|
350
|
+
if (ts.isPropertyAccessExpression(expression) && ts.isIdentifier(expression.expression)) {
|
|
351
|
+
return resolveNamespaceMember(module, expression.expression.text, expression.name.text, context, kinds);
|
|
352
|
+
}
|
|
353
|
+
return undefined;
|
|
354
|
+
}
|
|
355
|
+
function addHeritageEdges(builder, context) {
|
|
356
|
+
const typeKinds = new Set(['class', 'interface']);
|
|
357
|
+
for (const module of context.modules) {
|
|
358
|
+
if (!emitsModule(context, module.file))
|
|
359
|
+
continue;
|
|
360
|
+
for (const symbol of module.symbols) {
|
|
361
|
+
if (!ts.isClassDeclaration(symbol.node) && !ts.isInterfaceDeclaration(symbol.node))
|
|
362
|
+
continue;
|
|
363
|
+
for (const clause of symbol.node.heritageClauses ?? []) {
|
|
364
|
+
const kind = clause.token === ts.SyntaxKind.ImplementsKeyword ? 'implements' : 'extends';
|
|
365
|
+
for (const type of clause.types) {
|
|
366
|
+
const target = resolveTopLevelExpression(module, type.expression, context, typeKinds);
|
|
367
|
+
if (target === undefined || target.id === symbol.id)
|
|
368
|
+
continue;
|
|
369
|
+
const source = positionOf(module.source, type.expression, module.file);
|
|
370
|
+
builder.addEdge({
|
|
371
|
+
id: graphEdgeId(kind, symbol.id, target.id),
|
|
372
|
+
kind,
|
|
373
|
+
from: symbol.id,
|
|
374
|
+
to: target.id,
|
|
375
|
+
provenance: symbolProvenance(source),
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
function typeNameOf(node) {
|
|
383
|
+
if (node === undefined || !ts.isTypeReferenceNode(node))
|
|
384
|
+
return undefined;
|
|
385
|
+
return ts.isIdentifier(node.typeName) ? node.typeName.text : undefined;
|
|
386
|
+
}
|
|
387
|
+
function constructedTypeName(node) {
|
|
388
|
+
if (node === undefined || !ts.isNewExpression(node))
|
|
389
|
+
return undefined;
|
|
390
|
+
return ts.isIdentifier(node.expression) ? node.expression.text : undefined;
|
|
391
|
+
}
|
|
392
|
+
function declarationTypeName(node) {
|
|
393
|
+
return typeNameOf(node.type) ?? constructedTypeName(node.initializer);
|
|
394
|
+
}
|
|
395
|
+
function functionLikeNode(symbol) {
|
|
396
|
+
if (ts.isFunctionDeclaration(symbol.node) ||
|
|
397
|
+
ts.isMethodDeclaration(symbol.node) ||
|
|
398
|
+
ts.isConstructorDeclaration(symbol.node)) {
|
|
399
|
+
return symbol.node;
|
|
400
|
+
}
|
|
401
|
+
if (ts.isVariableDeclaration(symbol.node) &&
|
|
402
|
+
symbol.node.initializer !== undefined &&
|
|
403
|
+
(ts.isArrowFunction(symbol.node.initializer) || ts.isFunctionExpression(symbol.node.initializer))) {
|
|
404
|
+
return symbol.node.initializer;
|
|
405
|
+
}
|
|
406
|
+
return undefined;
|
|
407
|
+
}
|
|
408
|
+
function identifierReceiverType(caller, name, beforePosition) {
|
|
409
|
+
const functionNode = functionLikeNode(caller);
|
|
410
|
+
const parameter = functionNode?.parameters.find((candidate) => ts.isIdentifier(candidate.name) && candidate.name.text === name);
|
|
411
|
+
if (parameter !== undefined)
|
|
412
|
+
return declarationTypeName(parameter);
|
|
413
|
+
const candidates = [];
|
|
414
|
+
const visit = (node) => {
|
|
415
|
+
if (ts.isVariableDeclaration(node) &&
|
|
416
|
+
ts.isIdentifier(node.name) &&
|
|
417
|
+
node.name.text === name &&
|
|
418
|
+
node.getStart() <= beforePosition) {
|
|
419
|
+
const candidate = declarationTypeName(node);
|
|
420
|
+
if (candidate !== undefined)
|
|
421
|
+
candidates.push({ position: node.getStart(), typeName: candidate });
|
|
422
|
+
}
|
|
423
|
+
node.forEachChild(visit);
|
|
424
|
+
};
|
|
425
|
+
caller.node.forEachChild(visit);
|
|
426
|
+
candidates.sort((a, b) => b.position - a.position || compareStrings(a.typeName, b.typeName));
|
|
427
|
+
return candidates[0]?.typeName;
|
|
428
|
+
}
|
|
429
|
+
function enclosingClass(module, caller) {
|
|
430
|
+
for (let length = caller.scope.length; length > 0; length -= 1) {
|
|
431
|
+
const qualifiedName = caller.scope.slice(0, length).join('.');
|
|
432
|
+
const match = module.symbols.find((symbol) => symbol.qualifiedName === qualifiedName && symbol.kind === 'class');
|
|
433
|
+
if (match !== undefined)
|
|
434
|
+
return match;
|
|
435
|
+
}
|
|
436
|
+
return undefined;
|
|
437
|
+
}
|
|
438
|
+
function classPropertyType(classSymbol, property) {
|
|
439
|
+
if (!ts.isClassDeclaration(classSymbol.node))
|
|
440
|
+
return undefined;
|
|
441
|
+
for (const member of classSymbol.node.members) {
|
|
442
|
+
if (ts.isPropertyDeclaration(member) && propertyName(member.name) === property) {
|
|
443
|
+
return declarationTypeName(member);
|
|
444
|
+
}
|
|
445
|
+
if (ts.isConstructorDeclaration(member)) {
|
|
446
|
+
const parameter = member.parameters.find((candidate) => ts.isIdentifier(candidate.name) && candidate.name.text === property);
|
|
447
|
+
if (parameter !== undefined)
|
|
448
|
+
return declarationTypeName(parameter);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return undefined;
|
|
452
|
+
}
|
|
453
|
+
function receiverTypeName(module, caller, receiver, beforePosition) {
|
|
454
|
+
if (ts.isIdentifier(receiver)) {
|
|
455
|
+
return identifierReceiverType(caller, receiver.text, beforePosition);
|
|
456
|
+
}
|
|
457
|
+
if (ts.isPropertyAccessExpression(receiver) &&
|
|
458
|
+
receiver.expression.kind === ts.SyntaxKind.ThisKeyword) {
|
|
459
|
+
const owner = enclosingClass(module, caller);
|
|
460
|
+
return owner === undefined ? undefined : classPropertyType(owner, receiver.name.text);
|
|
461
|
+
}
|
|
462
|
+
return constructedTypeName(receiver);
|
|
463
|
+
}
|
|
464
|
+
function methodOnType(module, caller, receiver, method, beforePosition, context) {
|
|
465
|
+
const typeName = receiverTypeName(module, caller, receiver, beforePosition);
|
|
466
|
+
if (typeName === undefined)
|
|
467
|
+
return undefined;
|
|
468
|
+
const owner = resolveTopLevelSymbol(module, typeName, context, new Set(['class', 'interface']));
|
|
469
|
+
if (owner === undefined)
|
|
470
|
+
return undefined;
|
|
471
|
+
const targetModule = context.moduleByFile.get(owner.file);
|
|
472
|
+
if (targetModule === undefined)
|
|
473
|
+
return undefined;
|
|
474
|
+
const matches = targetModule.symbols.filter((symbol) => symbol.kind === 'method' && symbol.scope.join('.') === owner.qualifiedName && symbol.name === method);
|
|
475
|
+
return matches.length === 1 ? matches[0] : undefined;
|
|
476
|
+
}
|
|
477
|
+
function addCallEdges(builder, context) {
|
|
478
|
+
for (const module of context.modules) {
|
|
479
|
+
if (!emitsModule(context, module.file))
|
|
480
|
+
continue;
|
|
481
|
+
const visit = (node) => {
|
|
482
|
+
if (ts.isCallExpression(node)) {
|
|
483
|
+
const caller = nearestCaller(node, module.symbolByNode);
|
|
484
|
+
if (caller !== undefined) {
|
|
485
|
+
let target;
|
|
486
|
+
if (ts.isIdentifier(node.expression)) {
|
|
487
|
+
target = resolveValueExpression(module, caller, node.expression, context);
|
|
488
|
+
}
|
|
489
|
+
else if (ts.isPropertyAccessExpression(node.expression)) {
|
|
490
|
+
if (node.expression.expression.kind === ts.SyntaxKind.ThisKeyword) {
|
|
491
|
+
target = resolveLocalSymbol(module, caller, node.expression.name.text);
|
|
492
|
+
}
|
|
493
|
+
if (ts.isIdentifier(node.expression.expression)) {
|
|
494
|
+
target ??= resolveNamespaceMember(module, node.expression.expression.text, node.expression.name.text, context);
|
|
495
|
+
}
|
|
496
|
+
target ??= methodOnType(module, caller, node.expression.expression, node.expression.name.text, node.getStart(), context);
|
|
497
|
+
}
|
|
498
|
+
if (target !== undefined && target.id !== caller.id) {
|
|
499
|
+
const source = positionOf(module.source, node.expression, module.file);
|
|
500
|
+
builder.addEdge({
|
|
501
|
+
id: graphEdgeId('calls', caller.id, target.id),
|
|
502
|
+
kind: 'calls',
|
|
503
|
+
from: caller.id,
|
|
504
|
+
to: target.id,
|
|
505
|
+
provenance: symbolProvenance(source),
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
node.forEachChild(visit);
|
|
511
|
+
};
|
|
512
|
+
visit(module.source);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
function isDeclarationName(node) {
|
|
516
|
+
const parent = node.parent;
|
|
517
|
+
return (((ts.isVariableDeclaration(parent) ||
|
|
518
|
+
ts.isParameter(parent) ||
|
|
519
|
+
ts.isBindingElement(parent) ||
|
|
520
|
+
ts.isFunctionDeclaration(parent) ||
|
|
521
|
+
ts.isFunctionExpression(parent) ||
|
|
522
|
+
ts.isClassDeclaration(parent) ||
|
|
523
|
+
ts.isClassExpression(parent) ||
|
|
524
|
+
ts.isInterfaceDeclaration(parent) ||
|
|
525
|
+
ts.isMethodDeclaration(parent) ||
|
|
526
|
+
ts.isMethodSignature(parent) ||
|
|
527
|
+
ts.isPropertyDeclaration(parent) ||
|
|
528
|
+
ts.isPropertySignature(parent)) &&
|
|
529
|
+
parent.name === node) ||
|
|
530
|
+
(ts.isPropertyAssignment(parent) && parent.name === node));
|
|
531
|
+
}
|
|
532
|
+
function isInsideTypeOrModuleBinding(node) {
|
|
533
|
+
let current = node.parent;
|
|
534
|
+
while (current !== undefined && !ts.isStatement(current) && !ts.isSourceFile(current)) {
|
|
535
|
+
if (ts.isTypeNode(current))
|
|
536
|
+
return true;
|
|
537
|
+
if (ts.isImportClause(current) ||
|
|
538
|
+
ts.isImportSpecifier(current) ||
|
|
539
|
+
ts.isNamespaceImport(current) ||
|
|
540
|
+
ts.isExportSpecifier(current)) {
|
|
541
|
+
return true;
|
|
542
|
+
}
|
|
543
|
+
current = current.parent;
|
|
544
|
+
}
|
|
545
|
+
return false;
|
|
546
|
+
}
|
|
547
|
+
function isExistingRelationshipExpression(node) {
|
|
548
|
+
const parent = node.parent;
|
|
549
|
+
return (((ts.isCallExpression(parent) || ts.isNewExpression(parent)) && parent.expression === node) ||
|
|
550
|
+
((ts.isJsxOpeningElement(parent) || ts.isJsxSelfClosingElement(parent)) && parent.tagName === node) ||
|
|
551
|
+
(ts.isExpressionWithTypeArguments(parent) && parent.expression === node));
|
|
552
|
+
}
|
|
553
|
+
/** Add non-call value uses such as callbacks, factories, and returned implementations. */
|
|
554
|
+
function addValueReferenceEdges(builder, context) {
|
|
555
|
+
for (const module of context.modules) {
|
|
556
|
+
if (!emitsModule(context, module.file))
|
|
557
|
+
continue;
|
|
558
|
+
const add = (expression) => {
|
|
559
|
+
if (isExistingRelationshipExpression(expression) || isInsideTypeOrModuleBinding(expression))
|
|
560
|
+
return;
|
|
561
|
+
const caller = nearestCaller(expression, module.symbolByNode);
|
|
562
|
+
if (caller === undefined)
|
|
563
|
+
return;
|
|
564
|
+
const target = resolveValueExpression(module, caller, expression, context);
|
|
565
|
+
if (target === undefined || target.id === caller.id)
|
|
566
|
+
return;
|
|
567
|
+
const source = positionOf(module.source, expression, module.file);
|
|
568
|
+
builder.addEdge({
|
|
569
|
+
id: graphEdgeId('references-symbol', caller.id, target.id),
|
|
570
|
+
kind: 'references-symbol',
|
|
571
|
+
from: caller.id,
|
|
572
|
+
to: target.id,
|
|
573
|
+
provenance: symbolProvenance(source),
|
|
574
|
+
});
|
|
575
|
+
};
|
|
576
|
+
const visit = (node) => {
|
|
577
|
+
if (ts.isPropertyAccessExpression(node)) {
|
|
578
|
+
if (!ts.isPropertyAccessExpression(node.parent) || node.parent.expression !== node)
|
|
579
|
+
add(node);
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
if (ts.isIdentifier(node)) {
|
|
583
|
+
if (!isDeclarationName(node) &&
|
|
584
|
+
!ts.isPropertyAccessExpression(node.parent) &&
|
|
585
|
+
!ts.isQualifiedName(node.parent)) {
|
|
586
|
+
add(node);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
node.forEachChild(visit);
|
|
590
|
+
};
|
|
591
|
+
visit(module.source);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
const PRISMA_OPERATIONS = new Set([
|
|
595
|
+
'aggregate',
|
|
596
|
+
'count',
|
|
597
|
+
'create',
|
|
598
|
+
'createMany',
|
|
599
|
+
'delete',
|
|
600
|
+
'deleteMany',
|
|
601
|
+
'findFirst',
|
|
602
|
+
'findFirstOrThrow',
|
|
603
|
+
'findMany',
|
|
604
|
+
'findUnique',
|
|
605
|
+
'findUniqueOrThrow',
|
|
606
|
+
'groupBy',
|
|
607
|
+
'update',
|
|
608
|
+
'updateMany',
|
|
609
|
+
'upsert',
|
|
610
|
+
]);
|
|
611
|
+
function isPrismaClientType(module, node, context) {
|
|
612
|
+
if (node === undefined || !ts.isTypeReferenceNode(node))
|
|
613
|
+
return false;
|
|
614
|
+
if (ts.isIdentifier(node.typeName)) {
|
|
615
|
+
const binding = context.bindingsByFile.get(module.file)?.imports.get(node.typeName.text);
|
|
616
|
+
if (binding?.specifier === '@prisma/client' && binding.importedName === 'PrismaClient') {
|
|
617
|
+
return true;
|
|
618
|
+
}
|
|
619
|
+
const target = resolveTopLevelSymbol(module, node.typeName.text, context, new Set(['class']));
|
|
620
|
+
return target !== undefined && symbolExtendsPrismaClient(target, context);
|
|
621
|
+
}
|
|
622
|
+
if (ts.isQualifiedName(node.typeName) && ts.isIdentifier(node.typeName.left)) {
|
|
623
|
+
const binding = context.bindingsByFile.get(module.file)?.imports.get(node.typeName.left.text);
|
|
624
|
+
if (binding?.specifier === '@prisma/client' &&
|
|
625
|
+
binding.importedName === '*' &&
|
|
626
|
+
node.typeName.right.text === 'PrismaClient') {
|
|
627
|
+
return true;
|
|
628
|
+
}
|
|
629
|
+
const target = resolveNamespaceMember(module, node.typeName.left.text, node.typeName.right.text, context, new Set(['class']));
|
|
630
|
+
return target !== undefined && symbolExtendsPrismaClient(target, context);
|
|
631
|
+
}
|
|
632
|
+
return false;
|
|
633
|
+
}
|
|
634
|
+
function directPrismaClientClass(module, expression, context) {
|
|
635
|
+
if (ts.isIdentifier(expression)) {
|
|
636
|
+
const binding = context.bindingsByFile.get(module.file)?.imports.get(expression.text);
|
|
637
|
+
return binding?.specifier === '@prisma/client' && binding.importedName === 'PrismaClient';
|
|
638
|
+
}
|
|
639
|
+
if (ts.isPropertyAccessExpression(expression) && ts.isIdentifier(expression.expression)) {
|
|
640
|
+
const binding = context.bindingsByFile.get(module.file)?.imports.get(expression.expression.text);
|
|
641
|
+
return (binding?.specifier === '@prisma/client' &&
|
|
642
|
+
binding.importedName === '*' &&
|
|
643
|
+
expression.name.text === 'PrismaClient');
|
|
644
|
+
}
|
|
645
|
+
return false;
|
|
646
|
+
}
|
|
647
|
+
function symbolExtendsPrismaClient(symbol, context, seen = new Set()) {
|
|
648
|
+
if (seen.has(symbol.id) || !ts.isClassDeclaration(symbol.node))
|
|
649
|
+
return false;
|
|
650
|
+
const module = context.moduleByFile.get(symbol.file);
|
|
651
|
+
if (module === undefined)
|
|
652
|
+
return false;
|
|
653
|
+
const nextSeen = new Set(seen).add(symbol.id);
|
|
654
|
+
for (const clause of symbol.node.heritageClauses ?? []) {
|
|
655
|
+
if (clause.token !== ts.SyntaxKind.ExtendsKeyword)
|
|
656
|
+
continue;
|
|
657
|
+
for (const type of clause.types) {
|
|
658
|
+
if (directPrismaClientClass(module, type.expression, context))
|
|
659
|
+
return true;
|
|
660
|
+
const target = resolveTopLevelExpression(module, type.expression, context, new Set(['class']));
|
|
661
|
+
if (target !== undefined && symbolExtendsPrismaClient(target, context, nextSeen))
|
|
662
|
+
return true;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
return false;
|
|
666
|
+
}
|
|
667
|
+
function isPrismaClientConstruction(module, expression, context) {
|
|
668
|
+
if (expression === undefined || !ts.isNewExpression(expression))
|
|
669
|
+
return false;
|
|
670
|
+
if (ts.isIdentifier(expression.expression)) {
|
|
671
|
+
const binding = context.bindingsByFile.get(module.file)?.imports.get(expression.expression.text);
|
|
672
|
+
return binding?.specifier === '@prisma/client' && binding.importedName === 'PrismaClient';
|
|
673
|
+
}
|
|
674
|
+
if (ts.isPropertyAccessExpression(expression.expression) &&
|
|
675
|
+
ts.isIdentifier(expression.expression.expression)) {
|
|
676
|
+
const binding = context.bindingsByFile
|
|
677
|
+
.get(module.file)
|
|
678
|
+
?.imports.get(expression.expression.expression.text);
|
|
679
|
+
return (binding?.specifier === '@prisma/client' &&
|
|
680
|
+
binding.importedName === '*' &&
|
|
681
|
+
expression.expression.name.text === 'PrismaClient');
|
|
682
|
+
}
|
|
683
|
+
return false;
|
|
684
|
+
}
|
|
685
|
+
function declarationIsPrismaClient(module, declaration, context) {
|
|
686
|
+
return (isPrismaClientType(module, declaration.type, context) ||
|
|
687
|
+
isPrismaClientConstruction(module, declaration.initializer, context));
|
|
688
|
+
}
|
|
689
|
+
function topLevelPrismaClient(module, name, context) {
|
|
690
|
+
for (const statement of module.source.statements) {
|
|
691
|
+
if (!ts.isVariableStatement(statement))
|
|
692
|
+
continue;
|
|
693
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
694
|
+
if (ts.isIdentifier(declaration.name) &&
|
|
695
|
+
declaration.name.text === name &&
|
|
696
|
+
declarationIsPrismaClient(module, declaration, context)) {
|
|
697
|
+
return true;
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
return false;
|
|
702
|
+
}
|
|
703
|
+
function exportedPrismaClient(file, exportedName, context, seen = new Set()) {
|
|
704
|
+
const key = `${file}#${exportedName}`;
|
|
705
|
+
if (seen.has(key) || seen.size >= 16)
|
|
706
|
+
return false;
|
|
707
|
+
const module = context.moduleByFile.get(file);
|
|
708
|
+
const bindings = context.bindingsByFile.get(file);
|
|
709
|
+
if (module === undefined || bindings === undefined)
|
|
710
|
+
return false;
|
|
711
|
+
const nextSeen = new Set(seen).add(key);
|
|
712
|
+
const binding = bindings.exports.get(exportedName);
|
|
713
|
+
if (binding?.kind === 'local')
|
|
714
|
+
return topLevelPrismaClient(module, binding.localName, context);
|
|
715
|
+
if (binding?.kind === 'reexport') {
|
|
716
|
+
const target = resolveImport(file, binding.specifier, context.files, context.aliases);
|
|
717
|
+
return (target !== undefined &&
|
|
718
|
+
exportedPrismaClient(target, binding.importedName, context, nextSeen));
|
|
719
|
+
}
|
|
720
|
+
if (topLevelPrismaClient(module, exportedName, context))
|
|
721
|
+
return true;
|
|
722
|
+
const candidates = bindings.starExports.filter((specifier) => {
|
|
723
|
+
const target = resolveImport(file, specifier, context.files, context.aliases);
|
|
724
|
+
return target !== undefined && exportedPrismaClient(target, exportedName, context, nextSeen);
|
|
725
|
+
});
|
|
726
|
+
return candidates.length === 1;
|
|
727
|
+
}
|
|
728
|
+
function identifierIsPrismaClient(module, caller, name, context) {
|
|
729
|
+
const functionNode = functionLikeNode(caller);
|
|
730
|
+
for (const parameter of functionNode?.parameters ?? []) {
|
|
731
|
+
if (ts.isIdentifier(parameter.name) &&
|
|
732
|
+
parameter.name.text === name &&
|
|
733
|
+
declarationIsPrismaClient(module, parameter, context)) {
|
|
734
|
+
return true;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
let local = false;
|
|
738
|
+
const visit = (node) => {
|
|
739
|
+
if (local || (node !== caller.node && module.symbolByNode.has(node)))
|
|
740
|
+
return;
|
|
741
|
+
if (ts.isVariableDeclaration(node) &&
|
|
742
|
+
ts.isIdentifier(node.name) &&
|
|
743
|
+
node.name.text === name &&
|
|
744
|
+
declarationIsPrismaClient(module, node, context)) {
|
|
745
|
+
local = true;
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
node.forEachChild(visit);
|
|
749
|
+
};
|
|
750
|
+
caller.node.forEachChild(visit);
|
|
751
|
+
if (local || topLevelPrismaClient(module, name, context))
|
|
752
|
+
return true;
|
|
753
|
+
const imported = context.bindingsByFile.get(module.file)?.imports.get(name);
|
|
754
|
+
if (imported === undefined || imported.importedName === '*')
|
|
755
|
+
return false;
|
|
756
|
+
const target = resolveImport(module.file, imported.specifier, context.files, context.aliases);
|
|
757
|
+
return target !== undefined && exportedPrismaClient(target, imported.importedName, context);
|
|
758
|
+
}
|
|
759
|
+
function receiverIsPrismaClient(module, caller, receiver, context) {
|
|
760
|
+
if (ts.isIdentifier(receiver)) {
|
|
761
|
+
return identifierIsPrismaClient(module, caller, receiver.text, context);
|
|
762
|
+
}
|
|
763
|
+
if (ts.isPropertyAccessExpression(receiver) &&
|
|
764
|
+
receiver.expression.kind === ts.SyntaxKind.ThisKeyword) {
|
|
765
|
+
const owner = enclosingClass(module, caller);
|
|
766
|
+
if (owner === undefined || !ts.isClassDeclaration(owner.node))
|
|
767
|
+
return false;
|
|
768
|
+
for (const member of owner.node.members) {
|
|
769
|
+
if (ts.isPropertyDeclaration(member) &&
|
|
770
|
+
propertyName(member.name) === receiver.name.text &&
|
|
771
|
+
declarationIsPrismaClient(module, member, context)) {
|
|
772
|
+
return true;
|
|
773
|
+
}
|
|
774
|
+
if (ts.isConstructorDeclaration(member)) {
|
|
775
|
+
const parameter = member.parameters.find((candidate) => ts.isIdentifier(candidate.name) && candidate.name.text === receiver.name.text);
|
|
776
|
+
if (parameter !== undefined && declarationIsPrismaClient(module, parameter, context)) {
|
|
777
|
+
return true;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
return false;
|
|
783
|
+
}
|
|
784
|
+
function prismaSchemaCandidates(graph, model) {
|
|
785
|
+
const key = model.toLocaleLowerCase('en-US');
|
|
786
|
+
return graph.nodes.filter((node) => {
|
|
787
|
+
if (node.kind !== 'schema')
|
|
788
|
+
return false;
|
|
789
|
+
if (!node.provenance.evidence.some((ref) => ref.file.endsWith('.prisma')))
|
|
790
|
+
return false;
|
|
791
|
+
const modelName = typeof node.properties?.modelName === 'string' ? node.properties.modelName : undefined;
|
|
792
|
+
return [node.label, modelName]
|
|
793
|
+
.filter((value) => value !== undefined)
|
|
794
|
+
.some((value) => value.toLocaleLowerCase('en-US') === key);
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
function addPrismaAccessEdges(builder, graph, context) {
|
|
798
|
+
for (const module of context.modules) {
|
|
799
|
+
if (!emitsModule(context, module.file))
|
|
800
|
+
continue;
|
|
801
|
+
const visit = (node) => {
|
|
802
|
+
if (ts.isCallExpression(node) &&
|
|
803
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
804
|
+
PRISMA_OPERATIONS.has(node.expression.name.text) &&
|
|
805
|
+
ts.isPropertyAccessExpression(node.expression.expression)) {
|
|
806
|
+
const caller = nearestCaller(node, module.symbolByNode);
|
|
807
|
+
const delegate = node.expression.expression;
|
|
808
|
+
if (caller !== undefined &&
|
|
809
|
+
receiverIsPrismaClient(module, caller, delegate.expression, context)) {
|
|
810
|
+
const candidates = prismaSchemaCandidates(graph, delegate.name.text);
|
|
811
|
+
const source = positionOf(module.source, delegate.name, module.file);
|
|
812
|
+
if (candidates.length === 1) {
|
|
813
|
+
const target = candidates[0];
|
|
814
|
+
if (target !== undefined) {
|
|
815
|
+
builder.addEdge({
|
|
816
|
+
id: graphEdgeId('references', caller.id, target.id, `database:prisma:${node.expression.name.text}`),
|
|
817
|
+
kind: 'references',
|
|
818
|
+
from: caller.id,
|
|
819
|
+
to: target.id,
|
|
820
|
+
provenance: symbolProvenance(source),
|
|
821
|
+
properties: {
|
|
822
|
+
referenceKind: 'database-access',
|
|
823
|
+
orm: 'prisma',
|
|
824
|
+
operation: node.expression.name.text,
|
|
825
|
+
model: delegate.name.text,
|
|
826
|
+
},
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
else {
|
|
831
|
+
builder.addGap({
|
|
832
|
+
extractor: 'symbol',
|
|
833
|
+
kind: candidates.length === 0 ? 'database-model-unresolved' : 'database-model-ambiguous',
|
|
834
|
+
message: candidates.length === 0
|
|
835
|
+
? `Prisma delegate '${delegate.name.text}' did not match an extracted Prisma model.`
|
|
836
|
+
: `Prisma delegate '${delegate.name.text}' matched ${candidates.length} extracted Prisma models.`,
|
|
837
|
+
source,
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
node.forEachChild(visit);
|
|
843
|
+
};
|
|
844
|
+
visit(module.source);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
function queueConstruction(module, expression, context) {
|
|
848
|
+
if (expression === undefined || !ts.isNewExpression(expression))
|
|
849
|
+
return undefined;
|
|
850
|
+
if (!ts.isIdentifier(expression.expression))
|
|
851
|
+
return undefined;
|
|
852
|
+
const binding = context.bindingsByFile.get(module.file)?.imports.get(expression.expression.text);
|
|
853
|
+
let runtime;
|
|
854
|
+
if (binding?.specifier === 'bullmq' && binding.importedName === 'Queue')
|
|
855
|
+
runtime = 'bullmq';
|
|
856
|
+
if (binding?.specifier === 'bull' && binding.importedName === 'default')
|
|
857
|
+
runtime = 'bull';
|
|
858
|
+
if (runtime === undefined)
|
|
859
|
+
return undefined;
|
|
860
|
+
const channel = literalString(expression.arguments?.[0]);
|
|
861
|
+
return { runtime, ...(channel === undefined ? {} : { channel }) };
|
|
862
|
+
}
|
|
863
|
+
function topLevelQueue(module, name, context) {
|
|
864
|
+
for (const statement of module.source.statements) {
|
|
865
|
+
if (!ts.isVariableStatement(statement))
|
|
866
|
+
continue;
|
|
867
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
868
|
+
if (ts.isIdentifier(declaration.name) && declaration.name.text === name) {
|
|
869
|
+
const descriptor = queueConstruction(module, declaration.initializer, context);
|
|
870
|
+
if (descriptor !== undefined)
|
|
871
|
+
return descriptor;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
return undefined;
|
|
876
|
+
}
|
|
877
|
+
function exportedQueue(file, exportedName, context, seen = new Set()) {
|
|
878
|
+
const key = `${file}#${exportedName}`;
|
|
879
|
+
if (seen.has(key) || seen.size >= 16)
|
|
880
|
+
return undefined;
|
|
881
|
+
const module = context.moduleByFile.get(file);
|
|
882
|
+
const bindings = context.bindingsByFile.get(file);
|
|
883
|
+
if (module === undefined || bindings === undefined)
|
|
884
|
+
return undefined;
|
|
885
|
+
const nextSeen = new Set(seen).add(key);
|
|
886
|
+
const binding = bindings.exports.get(exportedName);
|
|
887
|
+
if (binding?.kind === 'local')
|
|
888
|
+
return topLevelQueue(module, binding.localName, context);
|
|
889
|
+
if (binding?.kind === 'reexport') {
|
|
890
|
+
const target = resolveImport(file, binding.specifier, context.files, context.aliases);
|
|
891
|
+
return target === undefined
|
|
892
|
+
? undefined
|
|
893
|
+
: exportedQueue(target, binding.importedName, context, nextSeen);
|
|
894
|
+
}
|
|
895
|
+
const direct = topLevelQueue(module, exportedName, context);
|
|
896
|
+
if (direct !== undefined)
|
|
897
|
+
return direct;
|
|
898
|
+
const candidates = bindings.starExports
|
|
899
|
+
.map((specifier) => {
|
|
900
|
+
const target = resolveImport(file, specifier, context.files, context.aliases);
|
|
901
|
+
return target === undefined ? undefined : exportedQueue(target, exportedName, context, nextSeen);
|
|
902
|
+
})
|
|
903
|
+
.filter((value) => value !== undefined);
|
|
904
|
+
if (candidates.length !== 1)
|
|
905
|
+
return undefined;
|
|
906
|
+
return candidates[0];
|
|
907
|
+
}
|
|
908
|
+
function identifierQueue(module, caller, name, context) {
|
|
909
|
+
let local;
|
|
910
|
+
const visit = (node) => {
|
|
911
|
+
if (local !== undefined || (node !== caller.node && module.symbolByNode.has(node)))
|
|
912
|
+
return;
|
|
913
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.name.text === name) {
|
|
914
|
+
local = queueConstruction(module, node.initializer, context);
|
|
915
|
+
if (local !== undefined)
|
|
916
|
+
return;
|
|
917
|
+
}
|
|
918
|
+
node.forEachChild(visit);
|
|
919
|
+
};
|
|
920
|
+
caller.node.forEachChild(visit);
|
|
921
|
+
if (local !== undefined)
|
|
922
|
+
return local;
|
|
923
|
+
const direct = topLevelQueue(module, name, context);
|
|
924
|
+
if (direct !== undefined)
|
|
925
|
+
return direct;
|
|
926
|
+
const imported = context.bindingsByFile.get(module.file)?.imports.get(name);
|
|
927
|
+
if (imported === undefined || imported.importedName === '*')
|
|
928
|
+
return undefined;
|
|
929
|
+
const target = resolveImport(module.file, imported.specifier, context.files, context.aliases);
|
|
930
|
+
return target === undefined ? undefined : exportedQueue(target, imported.importedName, context);
|
|
931
|
+
}
|
|
932
|
+
function queueReceiver(module, caller, receiver, context) {
|
|
933
|
+
if (ts.isIdentifier(receiver))
|
|
934
|
+
return identifierQueue(module, caller, receiver.text, context);
|
|
935
|
+
if (ts.isPropertyAccessExpression(receiver) &&
|
|
936
|
+
receiver.expression.kind === ts.SyntaxKind.ThisKeyword) {
|
|
937
|
+
const owner = enclosingClass(module, caller);
|
|
938
|
+
if (owner === undefined || !ts.isClassDeclaration(owner.node))
|
|
939
|
+
return undefined;
|
|
940
|
+
for (const member of owner.node.members) {
|
|
941
|
+
if (ts.isPropertyDeclaration(member) && propertyName(member.name) === receiver.name.text) {
|
|
942
|
+
const descriptor = queueConstruction(module, member.initializer, context);
|
|
943
|
+
if (descriptor !== undefined)
|
|
944
|
+
return descriptor;
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
return undefined;
|
|
949
|
+
}
|
|
950
|
+
function queueConsumerJobs(graph, descriptor) {
|
|
951
|
+
if (descriptor.channel === undefined)
|
|
952
|
+
return [];
|
|
953
|
+
return graph.nodes.filter((node) => {
|
|
954
|
+
const properties = node.properties;
|
|
955
|
+
return (node.kind === 'job' &&
|
|
956
|
+
properties !== undefined &&
|
|
957
|
+
properties.channel === descriptor.channel &&
|
|
958
|
+
properties.runtime === descriptor.runtime &&
|
|
959
|
+
properties.jobKind === 'queue-consumer');
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
function addQueueProducerEdges(builder, graph, context) {
|
|
963
|
+
for (const module of context.modules) {
|
|
964
|
+
if (!emitsModule(context, module.file))
|
|
965
|
+
continue;
|
|
966
|
+
const visit = (node) => {
|
|
967
|
+
if (ts.isCallExpression(node) &&
|
|
968
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
969
|
+
node.expression.name.text === 'add') {
|
|
970
|
+
const caller = nearestCaller(node, module.symbolByNode);
|
|
971
|
+
if (caller !== undefined) {
|
|
972
|
+
const descriptor = queueReceiver(module, caller, node.expression.expression, context);
|
|
973
|
+
if (descriptor !== undefined) {
|
|
974
|
+
const source = positionOf(module.source, node.expression, module.file);
|
|
975
|
+
if (descriptor.channel === undefined) {
|
|
976
|
+
builder.addGap({
|
|
977
|
+
extractor: 'symbol',
|
|
978
|
+
kind: 'queue-channel-unresolved',
|
|
979
|
+
message: `A proven ${descriptor.runtime} queue publishes with a non-literal channel name.`,
|
|
980
|
+
source,
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
else {
|
|
984
|
+
const jobName = literalString(node.arguments[0]);
|
|
985
|
+
for (const job of queueConsumerJobs(graph, descriptor)) {
|
|
986
|
+
builder.addEdge({
|
|
987
|
+
id: graphEdgeId('references', caller.id, job.id, `queue-producer:${descriptor.runtime}:${descriptor.channel}`),
|
|
988
|
+
kind: 'references',
|
|
989
|
+
from: caller.id,
|
|
990
|
+
to: job.id,
|
|
991
|
+
provenance: symbolProvenance(source),
|
|
992
|
+
properties: {
|
|
993
|
+
referenceKind: 'queue-producer',
|
|
994
|
+
runtime: descriptor.runtime,
|
|
995
|
+
channel: descriptor.channel,
|
|
996
|
+
operation: 'add',
|
|
997
|
+
...(jobName === undefined ? {} : { jobName }),
|
|
998
|
+
},
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
node.forEachChild(visit);
|
|
1006
|
+
};
|
|
1007
|
+
visit(module.source);
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
function unwrapAwait(expression) {
|
|
1011
|
+
return expression !== undefined && ts.isAwaitExpression(expression)
|
|
1012
|
+
? expression.expression
|
|
1013
|
+
: expression;
|
|
1014
|
+
}
|
|
1015
|
+
function amqpConnectionConstruction(module, expression, context) {
|
|
1016
|
+
const value = unwrapAwait(expression);
|
|
1017
|
+
if (value === undefined ||
|
|
1018
|
+
!ts.isCallExpression(value) ||
|
|
1019
|
+
!ts.isPropertyAccessExpression(value.expression) ||
|
|
1020
|
+
value.expression.name.text !== 'connect' ||
|
|
1021
|
+
!ts.isIdentifier(value.expression.expression)) {
|
|
1022
|
+
return false;
|
|
1023
|
+
}
|
|
1024
|
+
const binding = context.bindingsByFile
|
|
1025
|
+
.get(module.file)
|
|
1026
|
+
?.imports.get(value.expression.expression.text);
|
|
1027
|
+
return binding?.specifier === 'amqplib';
|
|
1028
|
+
}
|
|
1029
|
+
function topLevelAmqpConnection(module, name, context) {
|
|
1030
|
+
for (const statement of module.source.statements) {
|
|
1031
|
+
if (!ts.isVariableStatement(statement))
|
|
1032
|
+
continue;
|
|
1033
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
1034
|
+
if (ts.isIdentifier(declaration.name) &&
|
|
1035
|
+
declaration.name.text === name &&
|
|
1036
|
+
amqpConnectionConstruction(module, declaration.initializer, context)) {
|
|
1037
|
+
return true;
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
return false;
|
|
1042
|
+
}
|
|
1043
|
+
function identifierIsAmqpConnection(module, caller, name, context) {
|
|
1044
|
+
let local = false;
|
|
1045
|
+
const visit = (node) => {
|
|
1046
|
+
if (local || (caller !== undefined && node !== caller.node && module.symbolByNode.has(node)))
|
|
1047
|
+
return;
|
|
1048
|
+
if (ts.isVariableDeclaration(node) &&
|
|
1049
|
+
ts.isIdentifier(node.name) &&
|
|
1050
|
+
node.name.text === name &&
|
|
1051
|
+
amqpConnectionConstruction(module, node.initializer, context)) {
|
|
1052
|
+
local = true;
|
|
1053
|
+
return;
|
|
1054
|
+
}
|
|
1055
|
+
node.forEachChild(visit);
|
|
1056
|
+
};
|
|
1057
|
+
if (caller !== undefined)
|
|
1058
|
+
caller.node.forEachChild(visit);
|
|
1059
|
+
return local || topLevelAmqpConnection(module, name, context);
|
|
1060
|
+
}
|
|
1061
|
+
function amqpChannelConstruction(module, caller, expression, context) {
|
|
1062
|
+
const value = unwrapAwait(expression);
|
|
1063
|
+
if (value === undefined ||
|
|
1064
|
+
!ts.isCallExpression(value) ||
|
|
1065
|
+
!ts.isPropertyAccessExpression(value.expression) ||
|
|
1066
|
+
value.expression.name.text !== 'createChannel' ||
|
|
1067
|
+
!ts.isIdentifier(value.expression.expression)) {
|
|
1068
|
+
return false;
|
|
1069
|
+
}
|
|
1070
|
+
return identifierIsAmqpConnection(module, caller, value.expression.expression.text, context);
|
|
1071
|
+
}
|
|
1072
|
+
function topLevelAmqpChannel(module, name, context) {
|
|
1073
|
+
for (const statement of module.source.statements) {
|
|
1074
|
+
if (!ts.isVariableStatement(statement))
|
|
1075
|
+
continue;
|
|
1076
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
1077
|
+
if (ts.isIdentifier(declaration.name) &&
|
|
1078
|
+
declaration.name.text === name &&
|
|
1079
|
+
amqpChannelConstruction(module, undefined, declaration.initializer, context)) {
|
|
1080
|
+
return true;
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
return false;
|
|
1085
|
+
}
|
|
1086
|
+
function exportedAmqpChannel(file, exportedName, context, seen = new Set()) {
|
|
1087
|
+
const key = `${file}#${exportedName}`;
|
|
1088
|
+
if (seen.has(key) || seen.size >= 16)
|
|
1089
|
+
return false;
|
|
1090
|
+
const module = context.moduleByFile.get(file);
|
|
1091
|
+
const bindings = context.bindingsByFile.get(file);
|
|
1092
|
+
if (module === undefined || bindings === undefined)
|
|
1093
|
+
return false;
|
|
1094
|
+
const nextSeen = new Set(seen).add(key);
|
|
1095
|
+
const binding = bindings.exports.get(exportedName);
|
|
1096
|
+
if (binding?.kind === 'local')
|
|
1097
|
+
return topLevelAmqpChannel(module, binding.localName, context);
|
|
1098
|
+
if (binding?.kind === 'reexport') {
|
|
1099
|
+
const target = resolveImport(file, binding.specifier, context.files, context.aliases);
|
|
1100
|
+
return target !== undefined && exportedAmqpChannel(target, binding.importedName, context, nextSeen);
|
|
1101
|
+
}
|
|
1102
|
+
if (topLevelAmqpChannel(module, exportedName, context))
|
|
1103
|
+
return true;
|
|
1104
|
+
const candidates = bindings.starExports.filter((specifier) => {
|
|
1105
|
+
const target = resolveImport(file, specifier, context.files, context.aliases);
|
|
1106
|
+
return target !== undefined && exportedAmqpChannel(target, exportedName, context, nextSeen);
|
|
1107
|
+
});
|
|
1108
|
+
return candidates.length === 1;
|
|
1109
|
+
}
|
|
1110
|
+
function receiverIsAmqpChannel(module, caller, receiver, context) {
|
|
1111
|
+
if (!ts.isIdentifier(receiver))
|
|
1112
|
+
return false;
|
|
1113
|
+
let local = false;
|
|
1114
|
+
const visit = (node) => {
|
|
1115
|
+
if (local || (node !== caller.node && module.symbolByNode.has(node)))
|
|
1116
|
+
return;
|
|
1117
|
+
if (ts.isVariableDeclaration(node) &&
|
|
1118
|
+
ts.isIdentifier(node.name) &&
|
|
1119
|
+
node.name.text === receiver.text &&
|
|
1120
|
+
amqpChannelConstruction(module, caller, node.initializer, context)) {
|
|
1121
|
+
local = true;
|
|
1122
|
+
return;
|
|
1123
|
+
}
|
|
1124
|
+
node.forEachChild(visit);
|
|
1125
|
+
};
|
|
1126
|
+
caller.node.forEachChild(visit);
|
|
1127
|
+
if (local || topLevelAmqpChannel(module, receiver.text, context))
|
|
1128
|
+
return true;
|
|
1129
|
+
const imported = context.bindingsByFile.get(module.file)?.imports.get(receiver.text);
|
|
1130
|
+
if (imported === undefined || imported.importedName === '*')
|
|
1131
|
+
return false;
|
|
1132
|
+
const target = resolveImport(module.file, imported.specifier, context.files, context.aliases);
|
|
1133
|
+
return target !== undefined && exportedAmqpChannel(target, imported.importedName, context);
|
|
1134
|
+
}
|
|
1135
|
+
function addAmqpProducerEdges(builder, graph, context) {
|
|
1136
|
+
for (const module of context.modules) {
|
|
1137
|
+
if (!emitsModule(context, module.file))
|
|
1138
|
+
continue;
|
|
1139
|
+
const visit = (node) => {
|
|
1140
|
+
if (ts.isCallExpression(node) &&
|
|
1141
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
1142
|
+
node.expression.name.text === 'sendToQueue') {
|
|
1143
|
+
const caller = nearestCaller(node, module.symbolByNode);
|
|
1144
|
+
if (caller !== undefined &&
|
|
1145
|
+
receiverIsAmqpChannel(module, caller, node.expression.expression, context)) {
|
|
1146
|
+
const source = positionOf(module.source, node.expression, module.file);
|
|
1147
|
+
const channel = literalString(node.arguments[0]);
|
|
1148
|
+
if (channel === undefined) {
|
|
1149
|
+
builder.addGap({
|
|
1150
|
+
extractor: 'symbol',
|
|
1151
|
+
kind: 'queue-channel-unresolved',
|
|
1152
|
+
message: 'A proven amqplib channel publishes with a non-literal queue name.',
|
|
1153
|
+
source,
|
|
1154
|
+
});
|
|
1155
|
+
}
|
|
1156
|
+
else {
|
|
1157
|
+
const descriptor = { runtime: 'amqplib', channel };
|
|
1158
|
+
for (const job of queueConsumerJobs(graph, descriptor)) {
|
|
1159
|
+
builder.addEdge({
|
|
1160
|
+
id: graphEdgeId('references', caller.id, job.id, `queue-producer:amqplib:${channel}`),
|
|
1161
|
+
kind: 'references',
|
|
1162
|
+
from: caller.id,
|
|
1163
|
+
to: job.id,
|
|
1164
|
+
provenance: symbolProvenance(source),
|
|
1165
|
+
properties: {
|
|
1166
|
+
referenceKind: 'queue-producer',
|
|
1167
|
+
runtime: 'amqplib',
|
|
1168
|
+
channel,
|
|
1169
|
+
operation: 'sendToQueue',
|
|
1170
|
+
},
|
|
1171
|
+
});
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
node.forEachChild(visit);
|
|
1177
|
+
};
|
|
1178
|
+
visit(module.source);
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
function addReferenceEdges(builder, context) {
|
|
1182
|
+
const classKinds = new Set(['class']);
|
|
1183
|
+
const componentKinds = new Set(['function', 'class']);
|
|
1184
|
+
for (const module of context.modules) {
|
|
1185
|
+
if (!emitsModule(context, module.file))
|
|
1186
|
+
continue;
|
|
1187
|
+
const add = (node, expression, kind, kinds) => {
|
|
1188
|
+
const caller = nearestCaller(node, module.symbolByNode);
|
|
1189
|
+
if (caller === undefined)
|
|
1190
|
+
return;
|
|
1191
|
+
const target = resolveTopLevelExpression(module, expression, context, kinds);
|
|
1192
|
+
if (target === undefined || target.id === caller.id)
|
|
1193
|
+
return;
|
|
1194
|
+
const source = positionOf(module.source, expression, module.file);
|
|
1195
|
+
builder.addEdge({
|
|
1196
|
+
id: graphEdgeId(kind, caller.id, target.id),
|
|
1197
|
+
kind,
|
|
1198
|
+
from: caller.id,
|
|
1199
|
+
to: target.id,
|
|
1200
|
+
provenance: symbolProvenance(source),
|
|
1201
|
+
});
|
|
1202
|
+
};
|
|
1203
|
+
const visit = (node) => {
|
|
1204
|
+
if (ts.isNewExpression(node)) {
|
|
1205
|
+
add(node, node.expression, 'instantiates', classKinds);
|
|
1206
|
+
}
|
|
1207
|
+
else if (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) {
|
|
1208
|
+
const tag = node.tagName;
|
|
1209
|
+
if (ts.isIdentifier(tag)) {
|
|
1210
|
+
add(node, tag, 'references-symbol', componentKinds);
|
|
1211
|
+
}
|
|
1212
|
+
else if (ts.isPropertyAccessExpression(tag)) {
|
|
1213
|
+
add(node, tag, 'references-symbol', componentKinds);
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
node.forEachChild(visit);
|
|
1217
|
+
};
|
|
1218
|
+
visit(module.source);
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
/** Replace coarse file-only handler/component evidence with a symbol link when unique. */
|
|
1222
|
+
function addExtractedSymbolLinks(builder, graph, context) {
|
|
1223
|
+
for (const edge of graph.edges) {
|
|
1224
|
+
if (edge.kind !== 'handled-by' && edge.kind !== 'implemented-by')
|
|
1225
|
+
continue;
|
|
1226
|
+
const target = graph.nodes.find((node) => node.id === edge.to);
|
|
1227
|
+
if (target?.kind !== 'file')
|
|
1228
|
+
continue;
|
|
1229
|
+
const module = context.moduleByFile.get(target.label);
|
|
1230
|
+
if (module === undefined)
|
|
1231
|
+
continue;
|
|
1232
|
+
const evidence = edge.provenance.evidence.find((ref) => ref.file === module.file);
|
|
1233
|
+
let candidates;
|
|
1234
|
+
if (edge.kind === 'handled-by') {
|
|
1235
|
+
candidates = module.symbols.filter((symbol) => (symbol.kind === 'function' || symbol.kind === 'method') &&
|
|
1236
|
+
evidence?.line !== undefined &&
|
|
1237
|
+
symbol.source.line === evidence.line);
|
|
1238
|
+
}
|
|
1239
|
+
else {
|
|
1240
|
+
candidates = module.symbols.filter((symbol) => symbol.scope.length === 0 &&
|
|
1241
|
+
(symbol.kind === 'function' || symbol.kind === 'class') &&
|
|
1242
|
+
symbol.exportedNames.includes('default'));
|
|
1243
|
+
}
|
|
1244
|
+
if (candidates.length !== 1)
|
|
1245
|
+
continue;
|
|
1246
|
+
const symbol = candidates[0];
|
|
1247
|
+
if (symbol === undefined)
|
|
1248
|
+
continue;
|
|
1249
|
+
builder.addEdge({
|
|
1250
|
+
id: graphEdgeId(edge.kind, edge.from, symbol.id, 'resolved-symbol'),
|
|
1251
|
+
kind: edge.kind,
|
|
1252
|
+
from: edge.from,
|
|
1253
|
+
to: symbol.id,
|
|
1254
|
+
provenance: edge.provenance,
|
|
1255
|
+
properties: { resolution: 'symbol' },
|
|
1256
|
+
});
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
/** Add symbol definitions and statically provable calls to an existing graph. */
|
|
1260
|
+
export async function enrichGraphWithTypeScriptSymbols(options) {
|
|
1261
|
+
const files = (await fg(['**/*.{ts,tsx,js,jsx,mjs,cjs}'], {
|
|
1262
|
+
cwd: options.root,
|
|
1263
|
+
ignore: [...options.exclude],
|
|
1264
|
+
onlyFiles: true,
|
|
1265
|
+
}))
|
|
1266
|
+
.map(toPosix)
|
|
1267
|
+
.sort(compareStrings);
|
|
1268
|
+
const modules = [];
|
|
1269
|
+
for (const file of files) {
|
|
1270
|
+
try {
|
|
1271
|
+
modules.push(analyseModule(file, await fs.readFile(path.join(options.root, file), 'utf8')));
|
|
1272
|
+
}
|
|
1273
|
+
catch {
|
|
1274
|
+
// Other extractors follow the same read-failure policy: a file that
|
|
1275
|
+
// disappears during a scan is skipped rather than crashing the run.
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
const builder = new EvidenceGraphBuilder();
|
|
1279
|
+
for (const node of options.graph.nodes)
|
|
1280
|
+
builder.addNode(node);
|
|
1281
|
+
for (const edge of options.graph.edges)
|
|
1282
|
+
builder.addEdge(edge);
|
|
1283
|
+
for (const gap of options.graph.gaps)
|
|
1284
|
+
builder.addGap(gap);
|
|
1285
|
+
addSymbolNodes(builder, options.partitionFiles === undefined
|
|
1286
|
+
? modules
|
|
1287
|
+
: modules.filter((module) => options.partitionFiles?.has(module.file) === true));
|
|
1288
|
+
const context = {
|
|
1289
|
+
modules,
|
|
1290
|
+
moduleByFile: new Map(modules.map((module) => [module.file, module])),
|
|
1291
|
+
bindingsByFile: new Map(modules.map((module) => [module.file, readModuleBindings(module.source)])),
|
|
1292
|
+
files: new Set(files),
|
|
1293
|
+
aliases: await loadPathAliases(options.root),
|
|
1294
|
+
...(options.partitionFiles === undefined ? {} : { outputFiles: options.partitionFiles }),
|
|
1295
|
+
};
|
|
1296
|
+
addExtractedSymbolLinks(builder, options.graph, context);
|
|
1297
|
+
addHeritageEdges(builder, context);
|
|
1298
|
+
addCallEdges(builder, context);
|
|
1299
|
+
addReferenceEdges(builder, context);
|
|
1300
|
+
addValueReferenceEdges(builder, context);
|
|
1301
|
+
addPrismaAccessEdges(builder, options.graph, context);
|
|
1302
|
+
addQueueProducerEdges(builder, options.graph, context);
|
|
1303
|
+
addAmqpProducerEdges(builder, options.graph, context);
|
|
1304
|
+
return builder.build();
|
|
1305
|
+
}
|
|
1306
|
+
//# sourceMappingURL=symbols.js.map
|