loadwise 0.0.0-stage → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/PERFORMANCE.md +110 -0
- package/README.md +1429 -2
- package/bin/github-action.js +58 -0
- package/bin/loadwise.js +98 -0
- package/editor/README.md +47 -0
- package/editor/accessibility-examples.cjs +90 -0
- package/editor/apply-fix.cjs +187 -0
- package/editor/control-flow-comparison.cjs +133 -0
- package/editor/finding-comparison.cjs +77 -0
- package/editor/maintainability-examples.cjs +229 -0
- package/editor/perf-site-comparison.cjs +85 -0
- package/editor/performance-examples.cjs +438 -0
- package/editor/reliability-examples.cjs +77 -0
- package/editor/security-examples.cjs +59 -0
- package/editor/source-example.cjs +66 -0
- package/editor/standalone-performance-examples.cjs +487 -0
- package/examples/indexed.ts +19 -0
- package/examples/labels.py +6 -0
- package/examples/mongo-plan.json +8 -0
- package/examples/postgres-plan.json +10 -0
- package/examples/query-policy.json +24 -0
- package/examples/redis-keys.otlp.json +22 -0
- package/examples/repeated-db.otlp.json +73 -0
- package/examples/slow.ts +10 -0
- package/examples/tsconfig.json +4 -0
- package/lib/accessibility/analyze.js +26 -0
- package/lib/accessibility/angular-inline.js +43 -0
- package/lib/accessibility/aria-tables.js +231 -0
- package/lib/accessibility/cli.js +11 -0
- package/lib/accessibility/frontend-detect.js +98 -0
- package/lib/accessibility/jsx-elements.js +110 -0
- package/lib/accessibility/markup-files.js +41 -0
- package/lib/accessibility/markup.js +24 -0
- package/lib/accessibility/rule-ids.js +36 -0
- package/lib/accessibility/rules.js +293 -0
- package/lib/accessibility/site-fixes/buttons.js +35 -0
- package/lib/accessibility/template-attributes.js +135 -0
- package/lib/accessibility/template-elements.js +434 -0
- package/lib/accessibility/template-file.js +183 -0
- package/lib/accessibility/usage.js +12 -0
- package/lib/maintainability/advisory-context.js +182 -0
- package/lib/maintainability/analyze-source.js +93 -0
- package/lib/maintainability/ancestor-aliases.js +35 -0
- package/lib/maintainability/apply-fix.js +85 -0
- package/lib/maintainability/architecture-nest.js +103 -0
- package/lib/maintainability/architecture.js +482 -0
- package/lib/maintainability/branch-advice.js +135 -0
- package/lib/maintainability/changed-lines.js +135 -0
- package/lib/maintainability/changed-output.js +21 -0
- package/lib/maintainability/checklist-context.js +74 -0
- package/lib/maintainability/child-buffer.js +20 -0
- package/lib/maintainability/cli.js +410 -0
- package/lib/maintainability/config-entry-points.js +86 -0
- package/lib/maintainability/data-access.js +153 -0
- package/lib/maintainability/deprecated-apis.js +170 -0
- package/lib/maintainability/docker-entry-points.js +98 -0
- package/lib/maintainability/duplicates.js +326 -0
- package/lib/maintainability/entry-points.js +603 -0
- package/lib/maintainability/examples.js +122 -0
- package/lib/maintainability/finding-ids.js +46 -0
- package/lib/maintainability/fix-cli.js +235 -0
- package/lib/maintainability/fix-text.js +11 -0
- package/lib/maintainability/functions.js +315 -0
- package/lib/maintainability/graph.js +186 -0
- package/lib/maintainability/html-entry-points.js +75 -0
- package/lib/maintainability/inputs.js +231 -0
- package/lib/maintainability/layout.js +56 -0
- package/lib/maintainability/limits.js +3 -0
- package/lib/maintainability/mocha-entry-points.js +88 -0
- package/lib/maintainability/modifiers.js +6 -0
- package/lib/maintainability/module-usage-dynamic.js +175 -0
- package/lib/maintainability/module-usage.js +574 -0
- package/lib/maintainability/notify-editor.js +1 -0
- package/lib/maintainability/operator-references.js +84 -0
- package/lib/maintainability/polyglot-duplicates.js +121 -0
- package/lib/maintainability/polyglot.js +173 -0
- package/lib/maintainability/project.js +116 -0
- package/lib/maintainability/review-directive.js +91 -0
- package/lib/maintainability/rule-ids.js +67 -0
- package/lib/maintainability/runtime-directories.js +22 -0
- package/lib/maintainability/scan-changed.js +67 -0
- package/lib/maintainability/scan-worker.js +38 -0
- package/lib/maintainability/scan.js +238 -0
- package/lib/maintainability/site-fix.js +221 -0
- package/lib/maintainability/site-fixes/boolean-returns.js +79 -0
- package/lib/maintainability/site-fixes/branches.js +418 -0
- package/lib/maintainability/site-fixes/control-flow.js +67 -0
- package/lib/maintainability/site-fixes/cycles.js +101 -0
- package/lib/maintainability/site-fixes/deprecated-apis.js +67 -0
- package/lib/maintainability/site-fixes/duplicate-arrows.js +343 -0
- package/lib/maintainability/site-fixes/duplicate-bindings.js +149 -0
- package/lib/maintainability/site-fixes/duplicate-edits.js +396 -0
- package/lib/maintainability/site-fixes/duplicate-methods.js +407 -0
- package/lib/maintainability/site-fixes/duplicates.js +125 -0
- package/lib/maintainability/site-fixes/exports.js +25 -0
- package/lib/maintainability/site-fixes/extract-block-ast.js +130 -0
- package/lib/maintainability/site-fixes/extract-block-edits.js +156 -0
- package/lib/maintainability/site-fixes/extract-block-flow.js +265 -0
- package/lib/maintainability/site-fixes/extract-block-measure.js +131 -0
- package/lib/maintainability/site-fixes/extract-block-naming.js +164 -0
- package/lib/maintainability/site-fixes/extract-block-narrowing.js +141 -0
- package/lib/maintainability/site-fixes/extract-block.js +38 -0
- package/lib/maintainability/site-fixes/helpers.js +308 -0
- package/lib/maintainability/site-fixes/if-rewrites.js +468 -0
- package/lib/maintainability/site-fixes/isolated-program.js +85 -0
- package/lib/maintainability/site-fixes/large-module.js +175 -0
- package/lib/maintainability/site-fixes/parameters.js +460 -0
- package/lib/maintainability/site-fixes/stray-console.js +21 -0
- package/lib/maintainability/site-fixes/unused-bindings.js +158 -0
- package/lib/maintainability/size-limits.js +94 -0
- package/lib/maintainability/snapshot-context.js +63 -0
- package/lib/maintainability/source-exclusions.js +68 -0
- package/lib/maintainability/source-facts.js +39 -0
- package/lib/maintainability/stray-console.js +352 -0
- package/lib/maintainability/traversal-context.js +76 -0
- package/lib/maintainability/types/changed-lines.js +1 -0
- package/lib/maintainability/types/created-module.js +1 -0
- package/lib/maintainability/types/duplicate-sites.js +1 -0
- package/lib/maintainability/types/duplicates.js +1 -0
- package/lib/maintainability/types/entry-points.js +1 -0
- package/lib/maintainability/types/extract-block.js +1 -0
- package/lib/maintainability/types/extraction-drafts.js +1 -0
- package/lib/maintainability/types/finding-comparison.js +1 -0
- package/lib/maintainability/types/fix-files.js +1 -0
- package/lib/maintainability/types/module-graph.js +1 -0
- package/lib/maintainability/types/module-resolver.js +1 -0
- package/lib/maintainability/types/module-usage.js +1 -0
- package/lib/maintainability/types/policy.js +1 -0
- package/lib/maintainability/types/polyglot-scan.js +1 -0
- package/lib/maintainability/types/scan-report.js +1 -0
- package/lib/maintainability/types/scan-worker.js +1 -0
- package/lib/maintainability/types/site-fix-edits.js +1 -0
- package/lib/maintainability/types/site-fix-loader.js +1 -0
- package/lib/maintainability/types/site-fix-nodes.js +1 -0
- package/lib/maintainability/types/source-analysis.js +1 -0
- package/lib/maintainability/types/source-facts.js +1 -0
- package/lib/maintainability/types/typescript-jsdoc-internals.js +1 -0
- package/lib/maintainability/types/typescript-site-fix-internals.js +1 -0
- package/lib/maintainability/unused-bindings.js +182 -0
- package/lib/maintainability/unused-modules.js +258 -0
- package/lib/maintainability/verified-private-types.js +142 -0
- package/lib/maintainability/walk.js +17 -0
- package/lib/maintainability/workflow-entry-points.js +83 -0
- package/lib/performance/analyze.js +251 -0
- package/lib/performance/async-errors.js +190 -0
- package/lib/performance/await-before-early-exit.js +176 -0
- package/lib/performance/awaits.js +70 -0
- package/lib/performance/backend-mastery.js +444 -0
- package/lib/performance/cache-reads.js +170 -0
- package/lib/performance/call-syntax.js +27 -0
- package/lib/performance/cartesian-includes.js +364 -0
- package/lib/performance/changed-lines.js +141 -0
- package/lib/performance/cli-arguments.js +61 -0
- package/lib/performance/cli-output.js +175 -0
- package/lib/performance/cli-policy.js +79 -0
- package/lib/performance/cli-scan.js +419 -0
- package/lib/performance/cli-types.js +1 -0
- package/lib/performance/cli.js +120 -0
- package/lib/performance/collection-bindings.js +283 -0
- package/lib/performance/collection-bounds.js +247 -0
- package/lib/performance/collection-copy.js +169 -0
- package/lib/performance/collection-lookups.js +432 -0
- package/lib/performance/collection-reduce.js +340 -0
- package/lib/performance/collections.js +25 -0
- package/lib/performance/compiler.js +52 -0
- package/lib/performance/contracts/cli.js +230 -0
- package/lib/performance/contracts/dto.js +244 -0
- package/lib/performance/contracts/git-files.js +37 -0
- package/lib/performance/contracts/graphql.js +360 -0
- package/lib/performance/contracts/openapi.js +363 -0
- package/lib/performance/db/checks.js +398 -0
- package/lib/performance/db/cli-format.js +9 -0
- package/lib/performance/db/cli-mysql.js +82 -0
- package/lib/performance/db/cli.js +469 -0
- package/lib/performance/db/drivers.js +241 -0
- package/lib/performance/db/gateway.js +194 -0
- package/lib/performance/db/hypopg.js +52 -0
- package/lib/performance/db/measure.js +141 -0
- package/lib/performance/db/mongo.js +272 -0
- package/lib/performance/db/mysql-catalog.js +64 -0
- package/lib/performance/db/pg-catalog.js +114 -0
- package/lib/performance/db/plan-estimates.js +188 -0
- package/lib/performance/db/redact.js +126 -0
- package/lib/performance/db/snapshot.js +82 -0
- package/lib/performance/dependent-writes.js +228 -0
- package/lib/performance/discarded-error-result.js +46 -0
- package/lib/performance/drizzle-write-preflight.js +195 -0
- package/lib/performance/drizzle.js +288 -0
- package/lib/performance/editor-report.js +191 -0
- package/lib/performance/editor-setup.js +189 -0
- package/lib/performance/editor-signal.js +57 -0
- package/lib/performance/editor-watch-supervisor.js +104 -0
- package/lib/performance/editor-watch.js +193 -0
- package/lib/performance/emit-options.js +29 -0
- package/lib/performance/filter-existence.js +149 -0
- package/lib/performance/find-then-create.js +281 -0
- package/lib/performance/finding-ids.js +48 -0
- package/lib/performance/finding-text.js +117 -0
- package/lib/performance/fix-cli.js +200 -0
- package/lib/performance/floating-promises.js +248 -0
- package/lib/performance/frontend-dom-perf.js +310 -0
- package/lib/performance/frontend-helpers.js +93 -0
- package/lib/performance/frontend-perf.js +472 -0
- package/lib/performance/function-kinds.js +9 -0
- package/lib/performance/guard-queries.js +356 -0
- package/lib/performance/http-timeouts.js +492 -0
- package/lib/performance/impact.js +53 -0
- package/lib/performance/index-rules-foreign-keys.js +81 -0
- package/lib/performance/index-rules-order.js +152 -0
- package/lib/performance/index-rules-pattern.js +137 -0
- package/lib/performance/index-rules-table.js +288 -0
- package/lib/performance/index-rules.js +107 -0
- package/lib/performance/json-clone.js +28 -0
- package/lib/performance/json-parse-context.js +99 -0
- package/lib/performance/last-insert-id.js +120 -0
- package/lib/performance/list-counts.js +321 -0
- package/lib/performance/list-overfetch.js +216 -0
- package/lib/performance/literal-awaits.js +190 -0
- package/lib/performance/memory-growth.js +516 -0
- package/lib/performance/migrations/cli.js +203 -0
- package/lib/performance/migrations/discover.js +354 -0
- package/lib/performance/migrations/enforce.js +177 -0
- package/lib/performance/migrations/extract-code-builders.js +291 -0
- package/lib/performance/migrations/extract-code-discovery.js +179 -0
- package/lib/performance/migrations/extract-code-sql.js +196 -0
- package/lib/performance/migrations/extract-code-types.js +1 -0
- package/lib/performance/migrations/extract-code.js +123 -0
- package/lib/performance/migrations/extract-sql.js +452 -0
- package/lib/performance/migrations/operations.js +156 -0
- package/lib/performance/migrations/postgres-registry.js +135 -0
- package/lib/performance/migrations/rules-mysql.js +105 -0
- package/lib/performance/migrations/rules-postgres-add-column.js +145 -0
- package/lib/performance/migrations/rules-postgres-shared.js +22 -0
- package/lib/performance/migrations/rules-postgres.js +464 -0
- package/lib/performance/missing-packages.js +116 -0
- package/lib/performance/models/index.js +284 -0
- package/lib/performance/mongoose-patterns.js +245 -0
- package/lib/performance/native-checker.js +312 -0
- package/lib/performance/native-runtime.js +24 -0
- package/lib/performance/native-syntax.js +132 -0
- package/lib/performance/native-workspaces.js +31 -0
- package/lib/performance/native.js +342 -0
- package/lib/performance/node-fs-context.js +390 -0
- package/lib/performance/node-fs.js +452 -0
- package/lib/performance/notification-loops.js +176 -0
- package/lib/performance/notify-editor.js +1 -0
- package/lib/performance/offset-pagination.js +166 -0
- package/lib/performance/orm-owners.js +145 -0
- package/lib/performance/orm-queries.js +496 -0
- package/lib/performance/package-types.js +57 -0
- package/lib/performance/page-counts.js +262 -0
- package/lib/performance/parallel-reads-policy.js +41 -0
- package/lib/performance/parallel-reads.js +139 -0
- package/lib/performance/password-hashing.js +218 -0
- package/lib/performance/pg-fragments.js +300 -0
- package/lib/performance/pg-integrity.js +115 -0
- package/lib/performance/phase5-rules.js +539 -0
- package/lib/performance/plans.js +283 -0
- package/lib/performance/polyglot.js +193 -0
- package/lib/performance/pooling.js +200 -0
- package/lib/performance/postgres.js +182 -0
- package/lib/performance/prisma-aggregates.js +125 -0
- package/lib/performance/prisma-integrity.js +239 -0
- package/lib/performance/prisma.js +399 -0
- package/lib/performance/projects.js +431 -0
- package/lib/performance/promise-return-escapes-catch.js +96 -0
- package/lib/performance/pure-js-hashing.js +96 -0
- package/lib/performance/query-loop-batch.js +188 -0
- package/lib/performance/query-loop-bounds.js +219 -0
- package/lib/performance/query-loop-exits.js +171 -0
- package/lib/performance/query-loop-helpers.js +42 -0
- package/lib/performance/query-loop-memo.js +81 -0
- package/lib/performance/query-loop-pagination.js +130 -0
- package/lib/performance/query-loops.js +29 -0
- package/lib/performance/query-policy.js +94 -0
- package/lib/performance/query-results.js +179 -0
- package/lib/performance/queue-loops.js +87 -0
- package/lib/performance/recursive-watch.js +181 -0
- package/lib/performance/redis-client.js +19 -0
- package/lib/performance/redis-keys.js +78 -0
- package/lib/performance/redis.js +188 -0
- package/lib/performance/redundant-indexes.js +403 -0
- package/lib/performance/reference-checks.js +22 -0
- package/lib/performance/repeated.js +200 -0
- package/lib/performance/request-handlers.js +429 -0
- package/lib/performance/request-heavy-work.js +135 -0
- package/lib/performance/request-inputs.js +303 -0
- package/lib/performance/retry-backoff.js +132 -0
- package/lib/performance/return-in-finally.js +12 -0
- package/lib/performance/return-newline.js +54 -0
- package/lib/performance/review-context.js +434 -0
- package/lib/performance/rule-ids.js +357 -0
- package/lib/performance/scan-outcome.js +37 -0
- package/lib/performance/schema/context.js +145 -0
- package/lib/performance/schema/drizzle-schema.js +278 -0
- package/lib/performance/schema/model.js +169 -0
- package/lib/performance/schema/mongoose-schema.js +189 -0
- package/lib/performance/schema/prisma-schema.js +472 -0
- package/lib/performance/schema/project-indexes-events.js +494 -0
- package/lib/performance/schema/project-indexes.js +240 -0
- package/lib/performance/schema/query-site-support.js +61 -0
- package/lib/performance/schema/query-sites-drizzle.js +220 -0
- package/lib/performance/schema/query-sites-mongoose.js +140 -0
- package/lib/performance/schema/query-sites-prisma.js +201 -0
- package/lib/performance/schema/query-sites-sequelize.js +133 -0
- package/lib/performance/schema/query-sites-typeorm.js +180 -0
- package/lib/performance/schema/query-sites.js +19 -0
- package/lib/performance/schema/raw-sql-sites.js +284 -0
- package/lib/performance/schema/sequelize-schema.js +322 -0
- package/lib/performance/schema/ts-helpers.js +130 -0
- package/lib/performance/schema/typeorm-schema.js +262 -0
- package/lib/performance/schema-tooling.js +193 -0
- package/lib/performance/scope-evidence.js +137 -0
- package/lib/performance/sequential-loops.js +557 -0
- package/lib/performance/service-call-resolution.js +54 -0
- package/lib/performance/service-loop-collections.js +263 -0
- package/lib/performance/service-loop-operations.js +235 -0
- package/lib/performance/service-loops.js +416 -0
- package/lib/performance/session-store.js +86 -0
- package/lib/performance/site-fix.js +271 -0
- package/lib/performance/site-fixes/await-before-early-exit.js +121 -0
- package/lib/performance/site-fixes/backend-mastery-fixes.js +90 -0
- package/lib/performance/site-fixes/batch-loops.js +449 -0
- package/lib/performance/site-fixes/collection-copy.js +310 -0
- package/lib/performance/site-fixes/collection-existence.js +200 -0
- package/lib/performance/site-fixes/collection-find.js +195 -0
- package/lib/performance/site-fixes/collection-helpers.js +349 -0
- package/lib/performance/site-fixes/collection-lookup-declarations.js +47 -0
- package/lib/performance/site-fixes/collection-lookups.js +101 -0
- package/lib/performance/site-fixes/collection-membership.js +124 -0
- package/lib/performance/site-fixes/collections.js +18 -0
- package/lib/performance/site-fixes/database.js +455 -0
- package/lib/performance/site-fixes/delete-preflight.js +99 -0
- package/lib/performance/site-fixes/drizzle-index.js +239 -0
- package/lib/performance/site-fixes/error-handling.js +99 -0
- package/lib/performance/site-fixes/frontend-fixes.js +193 -0
- package/lib/performance/site-fixes/guard-queries.js +172 -0
- package/lib/performance/site-fixes/helpers.js +200 -0
- package/lib/performance/site-fixes/hoisting.js +155 -0
- package/lib/performance/site-fixes/http-timeouts.js +56 -0
- package/lib/performance/site-fixes/indexes.js +454 -0
- package/lib/performance/site-fixes/integrity-drizzle.js +188 -0
- package/lib/performance/site-fixes/integrity-wrap.js +45 -0
- package/lib/performance/site-fixes/integrity.js +555 -0
- package/lib/performance/site-fixes/json-parse.js +114 -0
- package/lib/performance/site-fixes/last-insert-id.js +230 -0
- package/lib/performance/site-fixes/list-queries.js +164 -0
- package/lib/performance/site-fixes/literal-awaits.js +431 -0
- package/lib/performance/site-fixes/method-calls.js +6 -0
- package/lib/performance/site-fixes/migration-column-rules.js +208 -0
- package/lib/performance/site-fixes/migration-context.js +317 -0
- package/lib/performance/site-fixes/migration-lock-rules.js +204 -0
- package/lib/performance/site-fixes/migration-placement.js +252 -0
- package/lib/performance/site-fixes/migrations.js +34 -0
- package/lib/performance/site-fixes/page-counts.js +88 -0
- package/lib/performance/site-fixes/prisma-aggregates.js +455 -0
- package/lib/performance/site-fixes/promise-catch.js +147 -0
- package/lib/performance/site-fixes/pure-js-hashing.js +68 -0
- package/lib/performance/site-fixes/query-loop-collections.js +202 -0
- package/lib/performance/site-fixes/query-loop-lookups.js +98 -0
- package/lib/performance/site-fixes/query-loop-materialization.js +279 -0
- package/lib/performance/site-fixes/query-loop-names.js +35 -0
- package/lib/performance/site-fixes/query-loop-nodes.js +162 -0
- package/lib/performance/site-fixes/query-loop-pg-redis.js +203 -0
- package/lib/performance/site-fixes/query-loop-prisma.js +304 -0
- package/lib/performance/site-fixes/query-loop-sites.js +317 -0
- package/lib/performance/site-fixes/query-loop-typeorm.js +294 -0
- package/lib/performance/site-fixes/query-loops.js +57 -0
- package/lib/performance/site-fixes/query-shapes.js +573 -0
- package/lib/performance/site-fixes/queue-loops.js +231 -0
- package/lib/performance/site-fixes/redis-keys.js +213 -0
- package/lib/performance/site-fixes/scope-names.js +30 -0
- package/lib/performance/site-fixes/service-loop-ast.js +85 -0
- package/lib/performance/site-fixes/service-loop-callee.js +57 -0
- package/lib/performance/site-fixes/service-loop-concurrent.js +88 -0
- package/lib/performance/site-fixes/service-loop-imports.js +68 -0
- package/lib/performance/site-fixes/service-loop-read-batch.js +255 -0
- package/lib/performance/site-fixes/service-loop-siblings.js +170 -0
- package/lib/performance/site-fixes/service-loop-signature.js +33 -0
- package/lib/performance/site-fixes/service-loop-sites.js +141 -0
- package/lib/performance/site-fixes/service-loop-write-batch.js +94 -0
- package/lib/performance/site-fixes/service-loops.js +153 -0
- package/lib/performance/site-fixes/small-rewrites.js +210 -0
- package/lib/performance/site-fixes/streams.js +150 -0
- package/lib/performance/site-fixes/sync-calls.js +485 -0
- package/lib/performance/site-fixes/sync-imports.js +170 -0
- package/lib/performance/site-fixes/transaction-escape.js +40 -0
- package/lib/performance/site-fixes/transaction-io.js +280 -0
- package/lib/performance/site-fixes/typeorm-updates.js +277 -0
- package/lib/performance/site-fixes/typeorm.js +239 -0
- package/lib/performance/site-fixes/types/module-binding.js +1 -0
- package/lib/performance/site-fixes/upload-limits.js +74 -0
- package/lib/performance/site-fixes/workbook-decodes.js +254 -0
- package/lib/performance/site-fixes/writes.js +342 -0
- package/lib/performance/sort-extreme.js +142 -0
- package/lib/performance/source-inputs.js +71 -0
- package/lib/performance/source-options.js +103 -0
- package/lib/performance/source-pillars.js +23 -0
- package/lib/performance/source-text.js +59 -0
- package/lib/performance/span-timing.js +54 -0
- package/lib/performance/sql/locations.js +91 -0
- package/lib/performance/sql/mysql-tokens.js +393 -0
- package/lib/performance/sql/pg-parser.js +330 -0
- package/lib/performance/stream-errors.js +650 -0
- package/lib/performance/traces.js +363 -0
- package/lib/performance/transaction-io.js +427 -0
- package/lib/performance/typeorm-projection.js +261 -0
- package/lib/performance/typeorm-transaction-loops.js +143 -0
- package/lib/performance/typeorm-unused-count.js +36 -0
- package/lib/performance/typeorm-updates.js +268 -0
- package/lib/performance/types/ast-grep-match.js +2 -0
- package/lib/performance/types/batch-plan.js +1 -0
- package/lib/performance/types/batched-fix-input.js +1 -0
- package/lib/performance/types/call-site.js +1 -0
- package/lib/performance/types/callee-helper.js +1 -0
- package/lib/performance/types/client-family.js +1 -0
- package/lib/performance/types/collections.js +1 -0
- package/lib/performance/types/contract-findings.js +3 -0
- package/lib/performance/types/db-cli.js +1 -0
- package/lib/performance/types/db-connection.js +1 -0
- package/lib/performance/types/db-model.js +3 -0
- package/lib/performance/types/db-plan-findings.js +1 -0
- package/lib/performance/types/db-plan.js +2 -0
- package/lib/performance/types/db-snapshot.js +1 -0
- package/lib/performance/types/declaration-link.js +2 -0
- package/lib/performance/types/decorator-call.js +1 -0
- package/lib/performance/types/drizzle-query.js +1 -0
- package/lib/performance/types/editor-report.js +1 -0
- package/lib/performance/types/find-lookup-facts.js +3 -0
- package/lib/performance/types/helper-function.js +1 -0
- package/lib/performance/types/hoist-anchor.js +1 -0
- package/lib/performance/types/http-call.js +1 -0
- package/lib/performance/types/lookup-construction.js +1 -0
- package/lib/performance/types/lookup-placement.js +1 -0
- package/lib/performance/types/loop-key-site.js +1 -0
- package/lib/performance/types/loop-lookup.js +1 -0
- package/lib/performance/types/method-call.js +1 -0
- package/lib/performance/types/migration-extraction.js +1 -0
- package/lib/performance/types/migration-files.js +1 -0
- package/lib/performance/types/migration-operations.js +1 -0
- package/lib/performance/types/migrations.js +1 -0
- package/lib/performance/types/model-fallback.js +2 -0
- package/lib/performance/types/mysql-statements.js +2 -0
- package/lib/performance/types/native-modules.js +1 -0
- package/lib/performance/types/native-typescript.js +1 -0
- package/lib/performance/types/otlp-attributes.js +1 -0
- package/lib/performance/types/otlp-trace.js +1 -0
- package/lib/performance/types/page-count-pair.js +1 -0
- package/lib/performance/types/parallel-reads.js +1 -0
- package/lib/performance/types/performance-policy.js +1 -0
- package/lib/performance/types/pg-statements.js +1 -0
- package/lib/performance/types/plain-property.js +1 -0
- package/lib/performance/types/postgres-registry.js +1 -0
- package/lib/performance/types/prisma-schema.js +1 -0
- package/lib/performance/types/program-scan.js +1 -0
- package/lib/performance/types/project-indexes.js +1 -0
- package/lib/performance/types/query-loops.js +1 -0
- package/lib/performance/types/query-site.js +1 -0
- package/lib/performance/types/related-location.js +2 -0
- package/lib/performance/types/repeat-owner.js +1 -0
- package/lib/performance/types/request-handler.js +1 -0
- package/lib/performance/types/request-input.js +1 -0
- package/lib/performance/types/schema-model.js +3 -0
- package/lib/performance/types/sibling-declaration.js +1 -0
- package/lib/performance/types/source-analyzer.js +1 -0
- package/lib/performance/types/source-check-values.js +1 -0
- package/lib/performance/types/source-command.js +1 -0
- package/lib/performance/types/source-position.js +2 -0
- package/lib/performance/types/source-scan-values.js +1 -0
- package/lib/performance/types/statement-range.js +2 -0
- package/lib/performance/types/typeorm-save-shape.js +1 -0
- package/lib/performance/types/typescript-binder.js +1 -0
- package/lib/performance/types/typescript-token-lookup.js +1 -0
- package/lib/performance/types/typescript-token-position.js +1 -0
- package/lib/performance/unbounded-list-queries.js +600 -0
- package/lib/performance/unscanned-javascript.js +29 -0
- package/lib/performance/upload-limits.js +68 -0
- package/lib/performance/vendor/README.md +7 -0
- package/lib/performance/vendor/typescript/LICENSE +55 -0
- package/lib/performance/vendor/typescript/NOTICE.txt +405 -0
- package/lib/performance/vendor/typescript/dist/api/compilerOptions.generated.js +8 -0
- package/lib/performance/vendor/typescript/dist/api/diagnosticFormatter.js +169 -0
- package/lib/performance/vendor/typescript/dist/api/fs.js +70 -0
- package/lib/performance/vendor/typescript/dist/api/fsCallbacks.js +111 -0
- package/lib/performance/vendor/typescript/dist/api/node/encoder.generated.js +74 -0
- package/lib/performance/vendor/typescript/dist/api/node/encoder.js +292 -0
- package/lib/performance/vendor/typescript/dist/api/node/msgpack.js +212 -0
- package/lib/performance/vendor/typescript/dist/api/node/node.generated.js +884 -0
- package/lib/performance/vendor/typescript/dist/api/node/node.infrastructure.js +102 -0
- package/lib/performance/vendor/typescript/dist/api/node/node.js +453 -0
- package/lib/performance/vendor/typescript/dist/api/node/protocol.generated.js +241 -0
- package/lib/performance/vendor/typescript/dist/api/node/protocol.js +33 -0
- package/lib/performance/vendor/typescript/dist/api/node/wtf8.js +130 -0
- package/lib/performance/vendor/typescript/dist/api/options.js +32 -0
- package/lib/performance/vendor/typescript/dist/api/path.js +884 -0
- package/lib/performance/vendor/typescript/dist/api/prepareCompilerOptions.generated.js +24 -0
- package/lib/performance/vendor/typescript/dist/api/proto.generated.js +21 -0
- package/lib/performance/vendor/typescript/dist/api/proto.js +50 -0
- package/lib/performance/vendor/typescript/dist/api/sourceFileCache.js +300 -0
- package/lib/performance/vendor/typescript/dist/api/sync/api.js +5408 -0
- package/lib/performance/vendor/typescript/dist/api/sync/client.js +174 -0
- package/lib/performance/vendor/typescript/dist/api/sync/generatorSupport.js +338 -0
- package/lib/performance/vendor/typescript/dist/api/syncChannel.js +526 -0
- package/lib/performance/vendor/typescript/dist/api/timing.js +149 -0
- package/lib/performance/vendor/typescript/dist/api/timingDump.js +38 -0
- package/lib/performance/vendor/typescript/dist/api/userPreferences.generated.js +3 -0
- package/lib/performance/vendor/typescript/dist/ast/ast.generated.js +4 -0
- package/lib/performance/vendor/typescript/dist/ast/ast.js +8 -0
- package/lib/performance/vendor/typescript/dist/ast/astnav.js +741 -0
- package/lib/performance/vendor/typescript/dist/ast/clone.js +104 -0
- package/lib/performance/vendor/typescript/dist/ast/factory.generated.js +5751 -0
- package/lib/performance/vendor/typescript/dist/ast/index.js +25 -0
- package/lib/performance/vendor/typescript/dist/ast/is.generated.js +1400 -0
- package/lib/performance/vendor/typescript/dist/ast/is.js +456 -0
- package/lib/performance/vendor/typescript/dist/ast/jsdoc.js +208 -0
- package/lib/performance/vendor/typescript/dist/ast/modifiers.js +41 -0
- package/lib/performance/vendor/typescript/dist/ast/scanner.js +2231 -0
- package/lib/performance/vendor/typescript/dist/ast/spanMap.js +417 -0
- package/lib/performance/vendor/typescript/dist/ast/utils.js +318 -0
- package/lib/performance/vendor/typescript/dist/ast/visitor.generated.js +979 -0
- package/lib/performance/vendor/typescript/dist/ast/visitor.js +87 -0
- package/lib/performance/vendor/typescript/dist/enums/caseSensitivity.js +7 -0
- package/lib/performance/vendor/typescript/dist/enums/characterCodes.js +130 -0
- package/lib/performance/vendor/typescript/dist/enums/checkFlags.js +36 -0
- package/lib/performance/vendor/typescript/dist/enums/commentDirectiveType.js +6 -0
- package/lib/performance/vendor/typescript/dist/enums/completionItemKind.js +30 -0
- package/lib/performance/vendor/typescript/dist/enums/diagnosticCategory.js +9 -0
- package/lib/performance/vendor/typescript/dist/enums/diagnosticDirectivePolicy.js +7 -0
- package/lib/performance/vendor/typescript/dist/enums/elementFlags.js +14 -0
- package/lib/performance/vendor/typescript/dist/enums/emitOnly.js +8 -0
- package/lib/performance/vendor/typescript/dist/enums/indexKind.js +7 -0
- package/lib/performance/vendor/typescript/dist/enums/internalSymbolName.js +25 -0
- package/lib/performance/vendor/typescript/dist/enums/jsDeclarationKind.js +12 -0
- package/lib/performance/vendor/typescript/dist/enums/jsxEmit.js +11 -0
- package/lib/performance/vendor/typescript/dist/enums/languageVariant.js +6 -0
- package/lib/performance/vendor/typescript/dist/enums/modifierFlags.js +44 -0
- package/lib/performance/vendor/typescript/dist/enums/moduleDetectionKind.js +9 -0
- package/lib/performance/vendor/typescript/dist/enums/moduleKind.js +19 -0
- package/lib/performance/vendor/typescript/dist/enums/moduleResolutionKind.js +11 -0
- package/lib/performance/vendor/typescript/dist/enums/newLineKind.js +8 -0
- package/lib/performance/vendor/typescript/dist/enums/nodeBuilderFlags.js +38 -0
- package/lib/performance/vendor/typescript/dist/enums/nodeFlags.js +46 -0
- package/lib/performance/vendor/typescript/dist/enums/objectFlags.js +53 -0
- package/lib/performance/vendor/typescript/dist/enums/outerExpressionKinds.js +18 -0
- package/lib/performance/vendor/typescript/dist/enums/regularExpressionFlags.js +14 -0
- package/lib/performance/vendor/typescript/dist/enums/scriptKind.js +11 -0
- package/lib/performance/vendor/typescript/dist/enums/scriptTarget.js +20 -0
- package/lib/performance/vendor/typescript/dist/enums/signatureFlags.js +17 -0
- package/lib/performance/vendor/typescript/dist/enums/signatureKind.js +7 -0
- package/lib/performance/vendor/typescript/dist/enums/spanMapFeature.js +27 -0
- package/lib/performance/vendor/typescript/dist/enums/spanMapFidelity.js +9 -0
- package/lib/performance/vendor/typescript/dist/enums/spanMapKind.js +8 -0
- package/lib/performance/vendor/typescript/dist/enums/symbolFlags.js +72 -0
- package/lib/performance/vendor/typescript/dist/enums/symbolOwnerKind.js +7 -0
- package/lib/performance/vendor/typescript/dist/enums/syntaxKind.js +392 -0
- package/lib/performance/vendor/typescript/dist/enums/tokenFlags.js +32 -0
- package/lib/performance/vendor/typescript/dist/enums/typeFlags.js +78 -0
- package/lib/performance/vendor/typescript/dist/enums/typeFormatFlags.js +31 -0
- package/lib/performance/vendor/typescript/dist/enums/typePredicateKind.js +9 -0
- package/lib/performance/vendor/typescript/dist/internal/utils.js +25 -0
- package/lib/performance/vendor/typescript/lib/getExePath.js +70 -0
- package/lib/performance/vendor/typescript/package.json +93 -0
- package/lib/performance/vendor/typescript/vendor/vscode-jsonrpc/License.txt +11 -0
- package/lib/performance/watch.js +99 -0
- package/lib/performance/workbook-decodes.js +147 -0
- package/lib/reliability/analyze.js +29 -0
- package/lib/reliability/boundary-access.js +521 -0
- package/lib/reliability/cli.js +20 -0
- package/lib/reliability/resource-leaks.js +526 -0
- package/lib/reliability/rule-ids.js +225 -0
- package/lib/reliability/site-fixes/boundary-access.js +80 -0
- package/lib/reliability/site-fixes/resource-leaks.js +125 -0
- package/lib/reliability/site-fixes/suspicious-logic.js +115 -0
- package/lib/reliability/source-helpers.js +32 -0
- package/lib/reliability/sql-insert-terminator.js +106 -0
- package/lib/reliability/standalone-sources.js +54 -0
- package/lib/reliability/suspicious-logic.js +364 -0
- package/lib/reliability/swallowed-errors.js +321 -0
- package/lib/reliability/usage.js +16 -0
- package/lib/reliability/walk.js +16 -0
- package/lib/security/analyze.js +129 -0
- package/lib/security/auth-crypto/comparison.js +97 -0
- package/lib/security/auth-crypto/hashing.js +302 -0
- package/lib/security/auth-crypto/index.js +32 -0
- package/lib/security/auth-crypto/jwt.js +468 -0
- package/lib/security/auth-crypto/plaintext-password.js +171 -0
- package/lib/security/auth-crypto/random.js +124 -0
- package/lib/security/auth-crypto/rate-limits.js +326 -0
- package/lib/security/auth-crypto/rule-ids.js +17 -0
- package/lib/security/auth-crypto/secrets.js +331 -0
- package/lib/security/auth-crypto/shared.js +105 -0
- package/lib/security/auth-crypto/transport-and-ciphers.js +217 -0
- package/lib/security/bindings.js +286 -0
- package/lib/security/cli.js +293 -0
- package/lib/security/declarations.js +25 -0
- package/lib/security/deps/advisory.js +142 -0
- package/lib/security/deps/cli.js +75 -0
- package/lib/security/deps/lockfiles.js +310 -0
- package/lib/security/deps/osv.js +217 -0
- package/lib/security/deps/rule-ids.js +6 -0
- package/lib/security/deps/scan.js +69 -0
- package/lib/security/examples/auth-crypto.cjs +57 -0
- package/lib/security/examples/deps.cjs +9 -0
- package/lib/security/examples/exposure.cjs +98 -0
- package/lib/security/examples/files.cjs +29 -0
- package/lib/security/examples/injection.cjs +53 -0
- package/lib/security/examples/moved.cjs +17 -0
- package/lib/security/examples/request-forgery.cjs +25 -0
- package/lib/security/exposure/backend-security-mastery.js +80 -0
- package/lib/security/exposure/cookies.js +173 -0
- package/lib/security/exposure/cors-origin-regex.js +177 -0
- package/lib/security/exposure/cors.js +217 -0
- package/lib/security/exposure/error-responses.js +437 -0
- package/lib/security/exposure/frontend-security.js +547 -0
- package/lib/security/exposure/graphql.js +131 -0
- package/lib/security/exposure/index.js +52 -0
- package/lib/security/exposure/literals.js +133 -0
- package/lib/security/exposure/logging.js +168 -0
- package/lib/security/exposure/mass-assignment.js +165 -0
- package/lib/security/exposure/password-response.js +315 -0
- package/lib/security/exposure/prototype-pollution.js +291 -0
- package/lib/security/exposure/reflected-xss.js +57 -0
- package/lib/security/exposure/report.js +10 -0
- package/lib/security/exposure/rule-ids.js +28 -0
- package/lib/security/exposure/storage-acl.js +87 -0
- package/lib/security/exposure/template-autoescape.js +39 -0
- package/lib/security/exposure/url-secrets.js +164 -0
- package/lib/security/exposure/validation-pipe.js +36 -0
- package/lib/security/exposure/xml.js +28 -0
- package/lib/security/file-context.js +82 -0
- package/lib/security/files/compose.js +79 -0
- package/lib/security/files/dockerfile.js +206 -0
- package/lib/security/files/index.js +100 -0
- package/lib/security/files/project-files.js +103 -0
- package/lib/security/files/review-directive.js +30 -0
- package/lib/security/files/rule-ids.js +10 -0
- package/lib/security/files/secret-values.js +98 -0
- package/lib/security/files/secrets.js +121 -0
- package/lib/security/injection/code.js +108 -0
- package/lib/security/injection/command.js +127 -0
- package/lib/security/injection/index.js +13 -0
- package/lib/security/injection/nosql.js +266 -0
- package/lib/security/injection/redos.js +609 -0
- package/lib/security/injection/regex.js +48 -0
- package/lib/security/injection/rule-ids.js +16 -0
- package/lib/security/injection/shared.js +119 -0
- package/lib/security/injection/sql.js +432 -0
- package/lib/security/pg-dynamic-query.js +30 -0
- package/lib/security/pg-identifier-guards.js +155 -0
- package/lib/security/phase5-rules.js +515 -0
- package/lib/security/polyglot.js +8 -0
- package/lib/security/request-forgery/index.js +11 -0
- package/lib/security/request-forgery/open-redirect.js +336 -0
- package/lib/security/request-forgery/path-traversal.js +103 -0
- package/lib/security/request-forgery/rule-ids.js +9 -0
- package/lib/security/request-forgery/shared.js +355 -0
- package/lib/security/request-forgery/ssrf.js +133 -0
- package/lib/security/request-forgery/upload-filename.js +75 -0
- package/lib/security/request-forgery/zip-slip.js +42 -0
- package/lib/security/rule-descriptions.js +84 -0
- package/lib/security/rule-ids.js +142 -0
- package/lib/security/scope/drizzle-policy.js +197 -0
- package/lib/security/scope/query-policy.js +156 -0
- package/lib/security/site-fixes/auth-crypto.js +223 -0
- package/lib/security/site-fixes/backend-security-fixes.js +86 -0
- package/lib/security/site-fixes/error-responses.js +84 -0
- package/lib/security/site-fixes/exposure.js +120 -0
- package/lib/security/site-fixes/files.js +45 -0
- package/lib/security/site-fixes/frontend-security-fixes.js +73 -0
- package/lib/security/site-fixes/injection.js +119 -0
- package/lib/security/site-fixes/jwt.js +89 -0
- package/lib/security/site-fixes/list-edits.js +16 -0
- package/lib/security/site-fixes/request-forgery.js +117 -0
- package/lib/security/site-fixes/secret-comparison.js +107 -0
- package/lib/security/site-fixes/template-autoescape.js +25 -0
- package/lib/security/taint/archive-sources.js +127 -0
- package/lib/security/taint/filename-guard.js +110 -0
- package/lib/security/taint/guards.js +274 -0
- package/lib/security/taint/index.js +559 -0
- package/lib/security/taint/propagate.js +117 -0
- package/lib/security/taint/sanitizers.js +67 -0
- package/lib/security/taint/sources.js +357 -0
- package/lib/security/taint/summaries.js +207 -0
- package/lib/security/taint/url-parts.js +264 -0
- package/lib/security/taint/validators.js +420 -0
- package/lib/security/types/condition-guards.js +1 -0
- package/lib/security/types/file-finding.js +1 -0
- package/lib/security/types/inspectable-type.js +1 -0
- package/lib/security/types/lockfile.js +1 -0
- package/lib/security/types/osv-vulnerability.js +1 -0
- package/lib/security/types/project-files.js +1 -0
- package/lib/security/types/propagation.js +1 -0
- package/lib/security/types/rule-example.js +1 -0
- package/lib/security/types/schema-call.js +1 -0
- package/lib/security/types/security-check.js +1 -0
- package/lib/shared/agent-init.js +235 -0
- package/lib/shared/agent-session.js +28 -0
- package/lib/shared/agent-verify.js +239 -0
- package/lib/shared/atomic-write.js +52 -0
- package/lib/shared/baseline-flags.js +33 -0
- package/lib/shared/baseline.js +237 -0
- package/lib/shared/build-output.js +22 -0
- package/lib/shared/check.js +247 -0
- package/lib/shared/config.js +286 -0
- package/lib/shared/coverage-notes.js +27 -0
- package/lib/shared/error-code.js +9 -0
- package/lib/shared/execution-context.js +278 -0
- package/lib/shared/explain.js +34 -0
- package/lib/shared/fix-command.js +23 -0
- package/lib/shared/fix-convergence.js +389 -0
- package/lib/shared/fix-handoff.js +57 -0
- package/lib/shared/fix-history.js +303 -0
- package/lib/shared/fix-hunks.js +108 -0
- package/lib/shared/fix-imports.js +233 -0
- package/lib/shared/fix-presentation-comments.js +253 -0
- package/lib/shared/fix-presentation-prettier.js +233 -0
- package/lib/shared/fix-presentation-rows.js +157 -0
- package/lib/shared/fix-presentation-style.js +230 -0
- package/lib/shared/fix-presentation.js +177 -0
- package/lib/shared/fix-rationales.js +151 -0
- package/lib/shared/fix-recipes.js +101 -0
- package/lib/shared/fix-safety.js +64 -0
- package/lib/shared/fix-terminal.js +65 -0
- package/lib/shared/fix-typecheck.js +188 -0
- package/lib/shared/fix.js +257 -0
- package/lib/shared/formats/contract-rules.js +9 -0
- package/lib/shared/formats/finding-location.js +31 -0
- package/lib/shared/formats/github.js +36 -0
- package/lib/shared/formats/index.js +29 -0
- package/lib/shared/formats/sarif.js +91 -0
- package/lib/shared/function-summaries.js +571 -0
- package/lib/shared/function-syntax.js +86 -0
- package/lib/shared/git-hook.js +153 -0
- package/lib/shared/git-paths.js +38 -0
- package/lib/shared/glob.js +53 -0
- package/lib/shared/heap-limit.js +60 -0
- package/lib/shared/hot-path-graph.js +268 -0
- package/lib/shared/hot-path.js +20 -0
- package/lib/shared/impact-levels.js +49 -0
- package/lib/shared/is-record.js +5 -0
- package/lib/shared/managed-blocks.js +54 -0
- package/lib/shared/notify-editor.js +50 -0
- package/lib/shared/pending-review.js +117 -0
- package/lib/shared/pillar-rules.js +6 -0
- package/lib/shared/pillars.js +384 -0
- package/lib/shared/polyglot-compatibility.js +105 -0
- package/lib/shared/project-root.js +35 -0
- package/lib/shared/real-target.js +23 -0
- package/lib/shared/reason-groups.js +20 -0
- package/lib/shared/review-delivery.js +33 -0
- package/lib/shared/review-mcp.js +262 -0
- package/lib/shared/review-request.js +59 -0
- package/lib/shared/rule-registry.js +57 -0
- package/lib/shared/scan-cache.js +234 -0
- package/lib/shared/shell-argument.js +9 -0
- package/lib/shared/source-report.js +156 -0
- package/lib/shared/types/baseline.js +1 -0
- package/lib/shared/types/checker-run.js +1 -0
- package/lib/shared/types/cli-finding.js +1 -0
- package/lib/shared/types/fix-hunks.js +1 -0
- package/lib/shared/types/fix-presentation.js +1 -0
- package/lib/shared/types/fix-run.js +1 -0
- package/lib/shared/types/function-summaries.js +1 -0
- package/lib/shared/types/managed-blocks.js +1 -0
- package/lib/shared/types/pillar-name.js +1 -0
- package/lib/shared/types/report-formats.js +1 -0
- package/lib/shared/types/review-event.js +1 -0
- package/lib/shared/types/review-history.js +1 -0
- package/lib/shared/types/settings.js +1 -0
- package/lib/shared/types/source-report.js +1 -0
- package/lib/shared/types/typescript-assignment-target.js +1 -0
- package/lib/shared/types/typescript-internals.js +1 -0
- package/lib/shared/types/typescript-module-resolution.js +1 -0
- package/lib/shared/types/typescript-outer-expression.js +1 -0
- package/lib/shared/types.js +1 -0
- package/lib/shared/workspaces.js +299 -0
- package/package.json +127 -4
- package/plugin/.claude-plugin/plugin.json +9 -0
- package/plugin/commands/loadwise.md +24 -0
- package/plugin/hooks/check-edited-file.js +142 -0
- package/plugin/hooks/hooks.json +17 -0
- package/polyglot/maintainability/rules.js +159 -0
- package/polyglot/maintainability/sgconfig.yml +12 -0
- package/polyglot/performance/rules/csharp.yml +104 -0
- package/polyglot/performance/rules/go.yml +123 -0
- package/polyglot/performance/rules/input.yml +37 -0
- package/polyglot/performance/rules/java.yml +115 -0
- package/polyglot/performance/rules/python.yml +159 -0
- package/polyglot/performance/rules/rust.yml +88 -0
- package/polyglot/performance/sgconfig.yml +8 -0
- package/polyglot/reliability/rules/csharp.yml +65 -0
- package/polyglot/reliability/rules/go.yml +76 -0
- package/polyglot/reliability/rules/java.yml +41 -0
- package/polyglot/reliability/rules/python.yml +32 -0
- package/polyglot/reliability/rules/rust.yml +34 -0
- package/polyglot/reliability/sgconfig.yml +8 -0
- package/polyglot/security/rules/csharp.yml +28 -0
- package/polyglot/security/rules/go.yml +42 -0
- package/polyglot/security/rules/java.yml +17 -0
- package/polyglot/security/rules/python.yml +48 -0
- package/polyglot/security/rules/rust.yml +23 -0
- package/polyglot/security/sgconfig.yml +8 -0
- package/schema/loadwise.config.schema.json +725 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
// Finds the for-of loops the per-item query rewrites can batch: the loop site, the item key its
|
|
2
|
+
// read filters by, and what the rest of the loop does to the rows it reads.
|
|
3
|
+
import { bindingNames, ts, textOf, enclosingIteration, isPlainReference } from './helpers.js';
|
|
4
|
+
import { someNode, outerParentheses, startsLine, textWith, localNames, receiverRoot, readsOnlyNames, plainProperties, propertyValue, } from './query-loop-nodes.js';
|
|
5
|
+
import { identifierPattern } from './query-loop-names.js';
|
|
6
|
+
import { mapItems, collectionKind, fixedList } from './query-loop-collections.js';
|
|
7
|
+
const exitKinds = new Set([
|
|
8
|
+
ts.SyntaxKind.ContinueStatement,
|
|
9
|
+
ts.SyntaxKind.BreakStatement,
|
|
10
|
+
ts.SyntaxKind.ReturnStatement,
|
|
11
|
+
ts.SyntaxKind.ThrowStatement,
|
|
12
|
+
]);
|
|
13
|
+
// The awaited value may only flow straight into a declaration, assignment, argument or property
|
|
14
|
+
// read.
|
|
15
|
+
function plainPath(awaited, statement) {
|
|
16
|
+
for (let child = awaited; child !== statement; child = child.parent) {
|
|
17
|
+
const parent = child.parent;
|
|
18
|
+
const allowed = ts.isParenthesizedExpression(parent) ||
|
|
19
|
+
ts.isVariableDeclaration(parent) ||
|
|
20
|
+
ts.isVariableDeclarationList(parent) ||
|
|
21
|
+
ts.isVariableStatement(parent) ||
|
|
22
|
+
ts.isExpressionStatement(parent) ||
|
|
23
|
+
(ts.isPropertyAccessExpression(parent) && parent.expression === child) ||
|
|
24
|
+
(ts.isBinaryExpression(parent) &&
|
|
25
|
+
parent.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
|
|
26
|
+
parent.right === child) ||
|
|
27
|
+
(ts.isCallExpression(parent) && parent.arguments.some((argument) => argument === child));
|
|
28
|
+
if (!allowed)
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
function forOfLoop(loop) {
|
|
34
|
+
if (!ts.isForOfStatement(loop) || loop.awaitModifier || !isPlainReference(loop.expression))
|
|
35
|
+
return;
|
|
36
|
+
if (!(ts.isBlock(loop.parent) || ts.isSourceFile(loop.parent)) || !startsLine(loop))
|
|
37
|
+
return;
|
|
38
|
+
const list = loop.initializer;
|
|
39
|
+
if (!ts.isVariableDeclarationList(list) || list.declarations.length !== 1)
|
|
40
|
+
return;
|
|
41
|
+
const name = list.declarations[0].name;
|
|
42
|
+
if (!ts.isIdentifier(name))
|
|
43
|
+
return;
|
|
44
|
+
const locals = localNames(loop.statement);
|
|
45
|
+
if (locals.has(name.text) ||
|
|
46
|
+
someNode(loop.expression, (node) => ts.isIdentifier(node) && locals.has(node.text)))
|
|
47
|
+
return;
|
|
48
|
+
return { loop, loopVariable: name.text, locals };
|
|
49
|
+
}
|
|
50
|
+
// A for-of whose only round trip is `call`, issued unconditionally from a top-level statement of
|
|
51
|
+
// the body.
|
|
52
|
+
export function loopSite(call) {
|
|
53
|
+
const awaited = call.parent;
|
|
54
|
+
const iteration = enclosingIteration(call);
|
|
55
|
+
if (!ts.isAwaitExpression(awaited) || iteration?.kind !== 'loop')
|
|
56
|
+
return;
|
|
57
|
+
const site = forOfLoop(iteration.node);
|
|
58
|
+
if (!site)
|
|
59
|
+
return;
|
|
60
|
+
const body = site.loop.statement;
|
|
61
|
+
if (!ts.isBlock(body))
|
|
62
|
+
return;
|
|
63
|
+
const statement = body.statements.find((candidate) => candidate.pos <= call.pos && call.end <= candidate.end);
|
|
64
|
+
if (!statement || !plainPath(awaited, statement))
|
|
65
|
+
return;
|
|
66
|
+
const earlier = body.statements.slice(0, body.statements.indexOf(statement));
|
|
67
|
+
if (earlier.some((previous) => someNode(previous, (node) => exitKinds.has(node.kind))))
|
|
68
|
+
return;
|
|
69
|
+
// The batched read runs before every iteration, so no other awaited work may change what it would
|
|
70
|
+
// read.
|
|
71
|
+
const otherWork = someNode(body, (node) => (ts.isAwaitExpression(node) && node !== awaited) ||
|
|
72
|
+
ts.isYieldExpression(node) ||
|
|
73
|
+
(ts.isForOfStatement(node) && !!node.awaitModifier));
|
|
74
|
+
const root = receiverRoot(call.expression.expression);
|
|
75
|
+
const sameClient = someNode(body, (node) => ts.isCallExpression(node) &&
|
|
76
|
+
node !== call &&
|
|
77
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
78
|
+
receiverRoot(node.expression.expression) === root);
|
|
79
|
+
if (otherWork || !root || sameClient)
|
|
80
|
+
return;
|
|
81
|
+
return { ...site, statement, awaited };
|
|
82
|
+
}
|
|
83
|
+
const freshIteratorMethods = new Set(['entries', 'values', 'keys']);
|
|
84
|
+
// The loop's collection in a form that can be iterated again before the loop without draining it.
|
|
85
|
+
function itemSource(expression) {
|
|
86
|
+
const value = ts.skipParentheses(expression);
|
|
87
|
+
if (isPlainReference(value)) {
|
|
88
|
+
const kind = collectionKind(value);
|
|
89
|
+
return kind && { text: textOf(value), kind, fixed: fixedList(value) };
|
|
90
|
+
}
|
|
91
|
+
if (ts.isCallExpression(value) &&
|
|
92
|
+
ts.isPropertyAccessExpression(value.expression) &&
|
|
93
|
+
!value.arguments.length &&
|
|
94
|
+
freshIteratorMethods.has(value.expression.name.text) &&
|
|
95
|
+
isPlainReference(value.expression.expression)) {
|
|
96
|
+
// Each call returns a fresh iterator, so the loop's own iterator is untouched whatever the
|
|
97
|
+
// owner is.
|
|
98
|
+
const owner = value.expression.expression;
|
|
99
|
+
const ownerKind = collectionKind(owner);
|
|
100
|
+
const method = value.expression.name.text;
|
|
101
|
+
return { text: textOf(value), kind: 'iterable', method, owner: textOf(owner), ownerKind, fixed: fixedList(owner) };
|
|
102
|
+
}
|
|
103
|
+
const fallback = ts.isBinaryExpression(value) &&
|
|
104
|
+
(value.operatorToken.kind === ts.SyntaxKind.QuestionQuestionToken ||
|
|
105
|
+
value.operatorToken.kind === ts.SyntaxKind.BarBarToken) &&
|
|
106
|
+
isPlainReference(value.left) &&
|
|
107
|
+
ts.isArrayLiteralExpression(value.right) &&
|
|
108
|
+
!value.right.elements.length;
|
|
109
|
+
if (fallback)
|
|
110
|
+
return { text: textOf(value), kind: 'iterable', fixed: false };
|
|
111
|
+
}
|
|
112
|
+
// A for-of whose items can be listed again before it: its binding, collection and the names its
|
|
113
|
+
// body writes.
|
|
114
|
+
export function forOfBinding(loop) {
|
|
115
|
+
if (!ts.isForOfStatement(loop) || loop.awaitModifier)
|
|
116
|
+
return;
|
|
117
|
+
if (!(ts.isBlock(loop.parent) || ts.isSourceFile(loop.parent)) || !startsLine(loop))
|
|
118
|
+
return;
|
|
119
|
+
const list = loop.initializer;
|
|
120
|
+
if (!ts.isVariableDeclarationList(list) || list.declarations.length !== 1)
|
|
121
|
+
return;
|
|
122
|
+
const pattern = list.declarations[0].name;
|
|
123
|
+
const names = bindingNames(pattern);
|
|
124
|
+
const source = itemSource(loop.expression);
|
|
125
|
+
const locals = localNames(loop.statement);
|
|
126
|
+
if (!source || [...names].some((name) => locals.has(name)))
|
|
127
|
+
return;
|
|
128
|
+
if (someNode(loop.expression, (node) => ts.isIdentifier(node) && locals.has(node.text)))
|
|
129
|
+
return;
|
|
130
|
+
return { loop, pattern, names, source, locals };
|
|
131
|
+
}
|
|
132
|
+
// Whether reaching `awaited` from the top of its statement depends on a branch.
|
|
133
|
+
function conditionalPath(awaited, statement) {
|
|
134
|
+
for (let child = awaited; child !== statement; child = child.parent) {
|
|
135
|
+
const parent = child.parent;
|
|
136
|
+
if (ts.isIfStatement(parent) && parent.expression !== child)
|
|
137
|
+
return true;
|
|
138
|
+
if (ts.isConditionalExpression(parent) && parent.condition !== child)
|
|
139
|
+
return true;
|
|
140
|
+
if (ts.isCaseClause(parent) || ts.isDefaultClause(parent))
|
|
141
|
+
return true;
|
|
142
|
+
const shortCircuit = [
|
|
143
|
+
ts.SyntaxKind.AmpersandAmpersandToken,
|
|
144
|
+
ts.SyntaxKind.BarBarToken,
|
|
145
|
+
ts.SyntaxKind.QuestionQuestionToken,
|
|
146
|
+
];
|
|
147
|
+
if (ts.isBinaryExpression(parent) && parent.right === child && shortCircuit.includes(parent.operatorToken.kind))
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
// A read awaited once per item of a for-of. Other statements may surround it; the builder reports
|
|
153
|
+
// what to check.
|
|
154
|
+
export function loopLookup(call) {
|
|
155
|
+
const awaited = outerParentheses(call).parent;
|
|
156
|
+
const iteration = enclosingIteration(call);
|
|
157
|
+
if (!ts.isAwaitExpression(awaited) || iteration?.kind !== 'loop')
|
|
158
|
+
return;
|
|
159
|
+
const binding = forOfBinding(iteration.node);
|
|
160
|
+
if (!binding)
|
|
161
|
+
return;
|
|
162
|
+
const body = binding.loop.statement;
|
|
163
|
+
if (!ts.isBlock(body))
|
|
164
|
+
return;
|
|
165
|
+
const statement = body.statements.find((candidate) => candidate.pos <= call.pos && call.end <= candidate.end);
|
|
166
|
+
if (!statement)
|
|
167
|
+
return;
|
|
168
|
+
// A per-item try would now have to catch the batched read too.
|
|
169
|
+
for (let current = awaited.parent; current !== body; current = current.parent)
|
|
170
|
+
if (ts.isTryStatement(current) || ts.isCatchClause(current))
|
|
171
|
+
return;
|
|
172
|
+
const index = body.statements.indexOf(statement);
|
|
173
|
+
const guarded = body.statements.slice(0, index).some((previous) => someNode(previous, (node) => exitKinds.has(node.kind))) ||
|
|
174
|
+
conditionalPath(awaited, statement);
|
|
175
|
+
const otherAwaits = [];
|
|
176
|
+
const blocked = someNode(body, (node) => {
|
|
177
|
+
if (ts.isYieldExpression(node) || (ts.isForOfStatement(node) && node.awaitModifier))
|
|
178
|
+
return true;
|
|
179
|
+
if (ts.isAwaitExpression(node) && node !== awaited)
|
|
180
|
+
otherAwaits.push(node);
|
|
181
|
+
return false;
|
|
182
|
+
});
|
|
183
|
+
if (blocked)
|
|
184
|
+
return;
|
|
185
|
+
const start = awaited.getStart();
|
|
186
|
+
return {
|
|
187
|
+
...binding,
|
|
188
|
+
statement,
|
|
189
|
+
awaited,
|
|
190
|
+
guarded,
|
|
191
|
+
earlierAwaits: otherAwaits.filter((node) => node.end <= start),
|
|
192
|
+
laterAwaits: otherAwaits.filter((node) => node.end > start),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
// A `const` declared earlier in the loop body from the item alone, so the key can be computed per
|
|
196
|
+
// item up front.
|
|
197
|
+
export function inlinedLocal(identifier, site) {
|
|
198
|
+
const body = site.loop?.statement;
|
|
199
|
+
if (!site.statement || !body || !ts.isBlock(body))
|
|
200
|
+
return;
|
|
201
|
+
const index = body.statements.indexOf(site.statement);
|
|
202
|
+
for (const statement of body.statements.slice(0, index)) {
|
|
203
|
+
if (!ts.isVariableStatement(statement) || !(statement.declarationList.flags & ts.NodeFlags.Const))
|
|
204
|
+
continue;
|
|
205
|
+
const declaration = statement.declarationList.declarations.find((candidate) => ts.isIdentifier(candidate.name) && candidate.name.text === identifier.text);
|
|
206
|
+
if (!declaration?.initializer)
|
|
207
|
+
continue;
|
|
208
|
+
const locals = new Set([...site.locals].filter((name) => name !== identifier.text));
|
|
209
|
+
if (readsOnlyNames(declaration.initializer, site.names, locals)?.usesLoopVariable)
|
|
210
|
+
return declaration.initializer;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
const findOperator = /^[A-Z]\w*$/;
|
|
214
|
+
// The one filter property that depends on the item; the others must be the same on every iteration.
|
|
215
|
+
export function itemKeyFilter(filter, site) {
|
|
216
|
+
const properties = plainProperties(filter);
|
|
217
|
+
if (!properties?.size)
|
|
218
|
+
return;
|
|
219
|
+
let key;
|
|
220
|
+
for (const [field, property] of properties) {
|
|
221
|
+
const value = propertyValue(property);
|
|
222
|
+
if (textOf(property).includes('\n'))
|
|
223
|
+
return;
|
|
224
|
+
const reads = readsOnlyNames(value, site.names, site.locals);
|
|
225
|
+
const local = !reads && ts.isIdentifier(value) && inlinedLocal(value, site);
|
|
226
|
+
if (reads && !reads.usesLoopVariable)
|
|
227
|
+
continue;
|
|
228
|
+
if ((!reads && !local) || key || !identifierPattern.test(field))
|
|
229
|
+
return;
|
|
230
|
+
const operator = ts.isCallExpression(value) && ts.isIdentifier(value.expression) && findOperator.test(value.expression.text);
|
|
231
|
+
if (ts.isObjectLiteralExpression(value) || ts.isArrayLiteralExpression(value) || operator)
|
|
232
|
+
return;
|
|
233
|
+
key = { field, property, value, perItem: local || value };
|
|
234
|
+
}
|
|
235
|
+
return key && { ...key, properties };
|
|
236
|
+
}
|
|
237
|
+
// The key as computed for every item; under a guard it must not throw for the items the guard
|
|
238
|
+
// skipped.
|
|
239
|
+
export function itemKeys(site, key) {
|
|
240
|
+
let perItem = textOf(key.perItem);
|
|
241
|
+
if (site.guarded) {
|
|
242
|
+
const unsafe = someNode(key.perItem, (node) => ts.isCallExpression(node) ||
|
|
243
|
+
ts.isElementAccessExpression(node) ||
|
|
244
|
+
ts.isNewExpression(node) ||
|
|
245
|
+
ts.isTaggedTemplateExpression(node));
|
|
246
|
+
if (unsafe)
|
|
247
|
+
return;
|
|
248
|
+
const edits = [];
|
|
249
|
+
someNode(key.perItem, (node) => {
|
|
250
|
+
if (ts.isPropertyAccessExpression(node) &&
|
|
251
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
252
|
+
!node.questionDotToken)
|
|
253
|
+
edits.push({ start: node.expression.end, end: node.name.getStart(), text: '?.' });
|
|
254
|
+
return false;
|
|
255
|
+
});
|
|
256
|
+
perItem = textWith(key.perItem, edits);
|
|
257
|
+
}
|
|
258
|
+
const keys = mapItems(site, perItem);
|
|
259
|
+
return site.guarded ? `${keys}.filter((key) => key != null)` : keys;
|
|
260
|
+
}
|
|
261
|
+
const readMethodPattern = /^(?:find|count|exists|aggregate|groupBy|get|has)/;
|
|
262
|
+
const batchWritePattern = /Many$/;
|
|
263
|
+
// What the reader must check once the read moves before the loop, or undefined when awaited work
|
|
264
|
+
// before it could change what it reads. Whether awaited work later in the body may write rows of
|
|
265
|
+
// this read: the same repository or client, or a call the builder cannot see into.
|
|
266
|
+
function mayWriteSameRows(awaited, receiverText, prismaRoot) {
|
|
267
|
+
const call = ts.skipParentheses(awaited.expression);
|
|
268
|
+
if (!ts.isCallExpression(call) || !ts.isPropertyAccessExpression(call.expression))
|
|
269
|
+
return true;
|
|
270
|
+
const receiver = call.expression.expression;
|
|
271
|
+
if (readMethodPattern.test(call.expression.name.text))
|
|
272
|
+
return false;
|
|
273
|
+
if (receiver.kind === ts.SyntaxKind.ThisKeyword || textOf(receiver) === receiverText)
|
|
274
|
+
return true;
|
|
275
|
+
// Prisma writes on the same client can write this model through nested relations.
|
|
276
|
+
return !!prismaRoot && receiverRoot(receiver) === prismaRoot;
|
|
277
|
+
}
|
|
278
|
+
// Keys that cannot repeat: items of a list fixed in the source, or each item's own `item.id`.
|
|
279
|
+
export function distinctKeys(site, keyNode) {
|
|
280
|
+
const value = ts.isExpression(keyNode) ? ts.skipParentheses(keyNode) : keyNode;
|
|
281
|
+
const ownId = ts.isPropertyAccessExpression(value) &&
|
|
282
|
+
value.name.text === 'id' &&
|
|
283
|
+
ts.isIdentifier(value.expression) &&
|
|
284
|
+
site.names.has(value.expression.text);
|
|
285
|
+
return site.source.fixed || ownId;
|
|
286
|
+
}
|
|
287
|
+
// What the reader must check once the read moves before the loop, or undefined when work in the
|
|
288
|
+
// loop could change what it reads: awaited writes before it, or later writes to the same rows when
|
|
289
|
+
// two items may share a key.
|
|
290
|
+
export function loopWorkNote(site, receiverText, prismaRoot, keyNode) {
|
|
291
|
+
const earlierWrites = [];
|
|
292
|
+
for (const awaited of site.earlierAwaits) {
|
|
293
|
+
const call = ts.skipParentheses(awaited.expression);
|
|
294
|
+
if (!ts.isCallExpression(call) || !ts.isPropertyAccessExpression(call.expression))
|
|
295
|
+
return;
|
|
296
|
+
const receiver = call.expression.expression;
|
|
297
|
+
const method = call.expression.name.text;
|
|
298
|
+
if (receiver.kind === ts.SyntaxKind.ThisKeyword || textOf(receiver) === receiverText)
|
|
299
|
+
return;
|
|
300
|
+
if (readMethodPattern.test(method))
|
|
301
|
+
continue;
|
|
302
|
+
if (prismaRoot && receiverRoot(receiver) === prismaRoot && !batchWritePattern.test(method))
|
|
303
|
+
return;
|
|
304
|
+
earlierWrites.push(textOf(call.expression));
|
|
305
|
+
}
|
|
306
|
+
const laterWrites = site.laterAwaits.some((awaited) => mayWriteSameRows(awaited, receiverText, prismaRoot));
|
|
307
|
+
if (laterWrites && !distinctKeys(site, keyNode))
|
|
308
|
+
return;
|
|
309
|
+
if (!site.laterAwaits.length && !earlierWrites.length)
|
|
310
|
+
return [];
|
|
311
|
+
const checked = earlierWrites.length
|
|
312
|
+
? ` and that ${[...new Set(earlierWrites)].join(', ')} cannot change what it reads`
|
|
313
|
+
: '';
|
|
314
|
+
return [
|
|
315
|
+
`The read now runs once before the loop, so rows the loop itself writes are not seen by later items: check that no two items share a key${checked}.`,
|
|
316
|
+
];
|
|
317
|
+
}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
// TypeORM per-item rewrites: find, findOne, exists and count inside a loop, and the same reads
|
|
2
|
+
// mapped through Promise.all, become one query with `In(...)`.
|
|
3
|
+
import { ts, textOf, replaceNode, calleeCall, insertLinesBefore, freshName, isPlainReference } from './helpers.js';
|
|
4
|
+
import { isMethodCall } from './method-calls.js';
|
|
5
|
+
import { someNode, outerParentheses, startsLine, inSlot, mentions, plainProperties } from './query-loop-nodes.js';
|
|
6
|
+
import { plural, capitalized, usableName, asConst, rowsName } from './query-loop-names.js';
|
|
7
|
+
import { loopLookup, itemKeyFilter, itemKeys, loopWorkNote } from './query-loop-sites.js';
|
|
8
|
+
import { collectionKind } from './query-loop-collections.js';
|
|
9
|
+
import { keyedLookup, groupedLookup, groupedKeyNote, nullKeyNote, ownIdKey, mapKeyNote, setKeyNote, duplicateKeyNote, joinNotes, invariantOptions, whereWith, } from './query-loop-lookups.js';
|
|
10
|
+
function repositoryNames(receiver) {
|
|
11
|
+
const last = ts.isPropertyAccessExpression(receiver) ? receiver.name.text : textOf(receiver);
|
|
12
|
+
const base = last.replace(/(?:Repository|Repo|repository|repo)$/, '');
|
|
13
|
+
if (!base || base === 'this')
|
|
14
|
+
return { rowsBase: 'rows', rowName: 'row' };
|
|
15
|
+
const lowered = base[0].toLowerCase() + base.slice(1);
|
|
16
|
+
// `case`, `default` and other keywords cannot name the callback parameter.
|
|
17
|
+
if (lowered.endsWith('s'))
|
|
18
|
+
return { rowsBase: lowered, rowName: 'row' };
|
|
19
|
+
if (ts.stringToToken(lowered) !== undefined)
|
|
20
|
+
return { rowsBase: plural(lowered), rowName: 'row' };
|
|
21
|
+
return { rowsBase: plural(lowered), rowName: lowered };
|
|
22
|
+
}
|
|
23
|
+
// Names for rows of `repo`, `this.userRepository` or `source.getRepository(User)`, which is safe to
|
|
24
|
+
// evaluate once.
|
|
25
|
+
function repositoryReceiver(receiver) {
|
|
26
|
+
if (isPlainReference(receiver))
|
|
27
|
+
return repositoryNames(receiver);
|
|
28
|
+
const plainGetRepository = ts.isCallExpression(receiver) &&
|
|
29
|
+
ts.isPropertyAccessExpression(receiver.expression) &&
|
|
30
|
+
receiver.expression.name.text === 'getRepository' &&
|
|
31
|
+
isPlainReference(receiver.expression.expression) &&
|
|
32
|
+
receiver.arguments.length === 1 &&
|
|
33
|
+
ts.isIdentifier(receiver.arguments[0]);
|
|
34
|
+
if (plainGetRepository)
|
|
35
|
+
return repositoryNames(receiver.arguments[0]);
|
|
36
|
+
}
|
|
37
|
+
// The local name of TypeORM's `In`, adding it to an existing named import, or as a new import, when
|
|
38
|
+
// needed.
|
|
39
|
+
function typeormIn(sourceFile) {
|
|
40
|
+
let lastImport;
|
|
41
|
+
for (const statement of sourceFile.statements) {
|
|
42
|
+
if (!ts.isImportDeclaration(statement))
|
|
43
|
+
continue;
|
|
44
|
+
lastImport = statement;
|
|
45
|
+
const clause = statement.importClause;
|
|
46
|
+
const bindings = clause?.namedBindings;
|
|
47
|
+
if (!clause ||
|
|
48
|
+
clause.isTypeOnly ||
|
|
49
|
+
!ts.isStringLiteral(statement.moduleSpecifier) ||
|
|
50
|
+
statement.moduleSpecifier.text !== 'typeorm' ||
|
|
51
|
+
!bindings ||
|
|
52
|
+
!ts.isNamedImports(bindings))
|
|
53
|
+
continue;
|
|
54
|
+
const existing = bindings.elements.find((element) => (element.propertyName ?? element.name).text === 'In');
|
|
55
|
+
if (existing)
|
|
56
|
+
return existing.isTypeOnly ? undefined : { name: existing.name.text, edits: [] };
|
|
57
|
+
if (freshName(sourceFile, 'In') !== 'In' || !bindings.elements.length)
|
|
58
|
+
return;
|
|
59
|
+
const last = bindings.elements[bindings.elements.length - 1];
|
|
60
|
+
return { name: 'In', edits: [{ start: last.end, end: last.end, text: ', In' }] };
|
|
61
|
+
}
|
|
62
|
+
if (!lastImport || freshName(sourceFile, 'In') !== 'In')
|
|
63
|
+
return;
|
|
64
|
+
const quote = textOf(lastImport.moduleSpecifier)[0];
|
|
65
|
+
const line = `\nimport { In } from ${quote}typeorm${quote};`;
|
|
66
|
+
return { name: 'In', edits: [{ start: lastImport.end, end: lastImport.end, text: line }] };
|
|
67
|
+
}
|
|
68
|
+
const typeormModes = {
|
|
69
|
+
find: 'list',
|
|
70
|
+
findBy: 'list',
|
|
71
|
+
findOne: 'one',
|
|
72
|
+
findOneBy: 'one',
|
|
73
|
+
exists: 'exists',
|
|
74
|
+
existsBy: 'exists',
|
|
75
|
+
count: 'count',
|
|
76
|
+
countBy: 'count',
|
|
77
|
+
};
|
|
78
|
+
const typeormRowOptions = new Set(['relations', 'select', 'withDeleted', 'loadEagerRelations']);
|
|
79
|
+
// A shared `order` keeps each key's rows in the same order once they are grouped; `take` and `skip`
|
|
80
|
+
// would not.
|
|
81
|
+
const typeormListOptions = new Set([...typeormRowOptions, 'order']);
|
|
82
|
+
const typeormOptionsByMode = {
|
|
83
|
+
one: typeormRowOptions,
|
|
84
|
+
list: typeormListOptions,
|
|
85
|
+
};
|
|
86
|
+
// `select` naming the key column, as an object or an array of property names.
|
|
87
|
+
function typeormSelectsKey(select, field) {
|
|
88
|
+
const value = ts.isPropertyAssignment(select) ? select.initializer : undefined;
|
|
89
|
+
if (value && ts.isArrayLiteralExpression(value))
|
|
90
|
+
return value.elements.some((element) => ts.isStringLiteral(element) && element.text === field);
|
|
91
|
+
const current = value && plainProperties(value)?.get(field);
|
|
92
|
+
return !!current && ts.isPropertyAssignment(current) && current.initializer.kind === ts.SyntaxKind.TrueKeyword;
|
|
93
|
+
}
|
|
94
|
+
// The options and the filter of a `find*` call: the `where` object, or the argument of a `*By`
|
|
95
|
+
// method.
|
|
96
|
+
function lookupFilter(call, byFilter) {
|
|
97
|
+
if (byFilter)
|
|
98
|
+
return { options: new Map(), filter: call.arguments[0] };
|
|
99
|
+
const options = plainProperties(call.arguments[0]);
|
|
100
|
+
const where = options?.get('where');
|
|
101
|
+
if (!options || !where || !ts.isPropertyAssignment(where))
|
|
102
|
+
return;
|
|
103
|
+
return { options, filter: where.initializer };
|
|
104
|
+
}
|
|
105
|
+
// loadwise-reviewed high-branch-complexity -- a linear chain of independent safety bail-outs followed by one exclusive list/one/exists rewrite choice; splitting scatters the proof from the rewrite
|
|
106
|
+
function typeormLookup(call, sourceFile) {
|
|
107
|
+
const method = call.expression.name.text;
|
|
108
|
+
const mode = typeormModes[method];
|
|
109
|
+
const receiver = call.expression.expression;
|
|
110
|
+
if (!mode || call.arguments.length !== 1)
|
|
111
|
+
return;
|
|
112
|
+
const names = repositoryReceiver(receiver);
|
|
113
|
+
if (!names)
|
|
114
|
+
return;
|
|
115
|
+
const site = loopLookup(call);
|
|
116
|
+
if (!site || someNode(receiver, (node) => ts.isIdentifier(node) && site.locals.has(node.text)))
|
|
117
|
+
return;
|
|
118
|
+
const byFilter = method.endsWith('By');
|
|
119
|
+
const filterParts = lookupFilter(call, byFilter);
|
|
120
|
+
if (!filterParts)
|
|
121
|
+
return;
|
|
122
|
+
const { options, filter } = filterParts;
|
|
123
|
+
const key = itemKeyFilter(filter, site);
|
|
124
|
+
if (!key)
|
|
125
|
+
return;
|
|
126
|
+
const others = invariantOptions(options, site, typeormOptionsByMode[mode] ?? new Set());
|
|
127
|
+
const keys = others && itemKeys(site, key);
|
|
128
|
+
const operator = keys ? typeormIn(sourceFile) : undefined;
|
|
129
|
+
const workNotes = operator && loopWorkNote(site, textOf(receiver), undefined, key.perItem);
|
|
130
|
+
const selectProperty = options.get('select');
|
|
131
|
+
if (!others || !operator || !workNotes || (selectProperty && !typeormSelectsKey(selectProperty, key.field)))
|
|
132
|
+
return;
|
|
133
|
+
const condition = whereWith(key, `${operator.name}(${keys})`);
|
|
134
|
+
const repository = textOf(receiver);
|
|
135
|
+
const keyText = textOf(key.value);
|
|
136
|
+
const base = names.rowName === 'row' ? names.rowsBase.replace(/s$/, '') : names.rowName;
|
|
137
|
+
const notes = [mapKeyNote, ...workNotes];
|
|
138
|
+
const fetchLine = byFilter
|
|
139
|
+
? `${repository}.findBy(${condition})`
|
|
140
|
+
: `${repository}.find({ ${[`where: ${condition}`, ...others.values()].join(', ')} })`;
|
|
141
|
+
let fix;
|
|
142
|
+
if (mode === 'list') {
|
|
143
|
+
notes[0] = groupedKeyNote;
|
|
144
|
+
if (!ownIdKey(key.value))
|
|
145
|
+
notes.splice(1, 0, nullKeyNote);
|
|
146
|
+
fix = groupedLookup({ site, sourceFile, ...names, field: key.field, keyValue: key.value, fetchLine, note: '' });
|
|
147
|
+
}
|
|
148
|
+
else if (mode === 'one') {
|
|
149
|
+
if (key.field !== 'id')
|
|
150
|
+
notes.splice(1, 0, duplicateKeyNote);
|
|
151
|
+
fix = keyedLookup({ site, sourceFile, ...names, field: key.field, keyValue: key.value, fetchLine, note: '' });
|
|
152
|
+
}
|
|
153
|
+
else if (mode === 'exists') {
|
|
154
|
+
notes[0] = setKeyNote;
|
|
155
|
+
const rows = usableName(sourceFile, names.rowsBase);
|
|
156
|
+
const keySet = rows && usableName(sourceFile, `${base}${capitalized(plural(key.field))}`);
|
|
157
|
+
if (!keySet)
|
|
158
|
+
return;
|
|
159
|
+
fix = {
|
|
160
|
+
edits: [
|
|
161
|
+
insertLinesBefore(site.loop, [
|
|
162
|
+
`const ${rows} = await ${repository}.find({ where: ${condition}, select: { ${key.field}: true } });`,
|
|
163
|
+
`const ${keySet} = new Set(${rows}.map((row) => row.${key.field}));`,
|
|
164
|
+
]),
|
|
165
|
+
replaceNode(site.awaited, inSlot(site.awaited, `${keySet}.has(${keyText})`)),
|
|
166
|
+
],
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
const counts = usableName(sourceFile, `${base}Counts`);
|
|
171
|
+
const byKey = counts && usableName(sourceFile, `${base}CountBy${capitalized(key.field)}`);
|
|
172
|
+
if (!byKey)
|
|
173
|
+
return;
|
|
174
|
+
fix = {
|
|
175
|
+
edits: [
|
|
176
|
+
insertLinesBefore(site.loop, [
|
|
177
|
+
`const ${counts} = await ${repository}`,
|
|
178
|
+
` .createQueryBuilder('row')`,
|
|
179
|
+
` .select('row.${key.field}', 'groupKey')`,
|
|
180
|
+
` .addSelect('COUNT(*)', 'total')`,
|
|
181
|
+
` .where(${condition})`,
|
|
182
|
+
` .groupBy('row.${key.field}')`,
|
|
183
|
+
` .getRawMany();`,
|
|
184
|
+
`const ${byKey} = new Map(${counts}.map((row) => [row.groupKey, Number(row.total)]${asConst(sourceFile)}));`,
|
|
185
|
+
]),
|
|
186
|
+
replaceNode(site.awaited, inSlot(site.awaited, `${byKey}.get(${keyText}) ?? 0`)),
|
|
187
|
+
],
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
return fix && { edits: [...fix.edits, ...operator.edits], note: joinNotes(notes) };
|
|
191
|
+
}
|
|
192
|
+
// The `items.map((item) => <read>)` handed straight to an awaited `Promise.all`, with the read as
|
|
193
|
+
// the whole callback body (optionally `async` and awaited), and the statement the await sits in.
|
|
194
|
+
function promiseAllRead(call) {
|
|
195
|
+
let body = outerParentheses(call);
|
|
196
|
+
if (ts.isAwaitExpression(body.parent))
|
|
197
|
+
body = outerParentheses(body.parent);
|
|
198
|
+
const callback = body.parent;
|
|
199
|
+
if (!ts.isArrowFunction(callback) || callback.body !== body || callback.parameters.length !== 1)
|
|
200
|
+
return;
|
|
201
|
+
const parameter = callback.parameters[0];
|
|
202
|
+
if (!ts.isIdentifier(parameter.name) || parameter.initializer || parameter.dotDotDotToken)
|
|
203
|
+
return;
|
|
204
|
+
const mapCall = callback.parent;
|
|
205
|
+
if (!ts.isCallExpression(mapCall) ||
|
|
206
|
+
mapCall.arguments.length !== 1 ||
|
|
207
|
+
mapCall.arguments[0] !== callback ||
|
|
208
|
+
!ts.isPropertyAccessExpression(mapCall.expression) ||
|
|
209
|
+
mapCall.expression.name.text !== 'map' ||
|
|
210
|
+
mapCall.expression.questionDotToken)
|
|
211
|
+
return;
|
|
212
|
+
const collection = mapCall.expression.expression;
|
|
213
|
+
if (!isPlainReference(collection) || collectionKind(collection) !== 'array')
|
|
214
|
+
return;
|
|
215
|
+
const all = mapCall.parent;
|
|
216
|
+
if (!ts.isCallExpression(all) || all.arguments.length !== 1 || textOf(all.expression) !== 'Promise.all')
|
|
217
|
+
return;
|
|
218
|
+
const awaited = all.parent;
|
|
219
|
+
if (!ts.isAwaitExpression(awaited))
|
|
220
|
+
return;
|
|
221
|
+
const holder = awaited.parent;
|
|
222
|
+
const statement = ts.isVariableDeclaration(holder) ? holder.parent.parent : holder;
|
|
223
|
+
const plainStatement = (ts.isVariableDeclaration(holder) && holder.initializer === awaited && ts.isVariableStatement(statement)) ||
|
|
224
|
+
(ts.isReturnStatement(holder) && holder.expression === awaited) ||
|
|
225
|
+
(ts.isExpressionStatement(holder) && holder.expression === awaited);
|
|
226
|
+
if (!plainStatement || !(ts.isBlock(statement.parent) || ts.isSourceFile(statement.parent)))
|
|
227
|
+
return;
|
|
228
|
+
if (!startsLine(statement))
|
|
229
|
+
return;
|
|
230
|
+
return { parameter: parameter.name.text, collection, awaited, statement };
|
|
231
|
+
}
|
|
232
|
+
// `await Promise.all(ids.map((id) => repo.findOne({ where: { id } })))` becomes one `find` with
|
|
233
|
+
// `In(ids)` and a Map, read back in the same order, with null for a missing row as before.
|
|
234
|
+
function promiseAllLookup(call, sourceFile) {
|
|
235
|
+
const method = call.expression.name.text;
|
|
236
|
+
const receiver = call.expression.expression;
|
|
237
|
+
if (typeormModes[method] !== 'one' || call.arguments.length !== 1)
|
|
238
|
+
return;
|
|
239
|
+
const names = repositoryReceiver(receiver);
|
|
240
|
+
const read = names && promiseAllRead(call);
|
|
241
|
+
if (!names || !read || mentions(textOf(receiver), read.parameter))
|
|
242
|
+
return;
|
|
243
|
+
// The shape itemKeyFilter expects of a loop: the per-item name, and no locals or earlier
|
|
244
|
+
// statements in the body.
|
|
245
|
+
const site = { names: new Set([read.parameter]), locals: new Set() };
|
|
246
|
+
const byFilter = method.endsWith('By');
|
|
247
|
+
const filterParts = lookupFilter(call, byFilter);
|
|
248
|
+
if (!filterParts)
|
|
249
|
+
return;
|
|
250
|
+
const { options, filter } = filterParts;
|
|
251
|
+
const key = itemKeyFilter(filter, site);
|
|
252
|
+
// The key is read twice, once to list the keys and once to look the row up, so it must have no
|
|
253
|
+
// side effects.
|
|
254
|
+
if (!key || key.perItem !== key.value || !isPlainReference(key.value))
|
|
255
|
+
return;
|
|
256
|
+
const others = invariantOptions(options, site, typeormRowOptions);
|
|
257
|
+
const operator = others && typeormIn(sourceFile);
|
|
258
|
+
const selectProperty = options.get('select');
|
|
259
|
+
if (!others || !operator || (selectProperty && !typeormSelectsKey(selectProperty, key.field)))
|
|
260
|
+
return;
|
|
261
|
+
const items = textOf(read.collection);
|
|
262
|
+
const keyText = textOf(key.value);
|
|
263
|
+
const keys = keyText === read.parameter ? items : `${items}.map((${read.parameter}) => ${keyText})`;
|
|
264
|
+
const condition = whereWith(key, `${operator.name}(${keys})`);
|
|
265
|
+
const repository = textOf(receiver);
|
|
266
|
+
const fetchLine = byFilter
|
|
267
|
+
? `${repository}.findBy(${condition})`
|
|
268
|
+
: `${repository}.find({ ${[`where: ${condition}`, ...others.values()].join(', ')} })`;
|
|
269
|
+
const rows = rowsName(sourceFile, names.rowsBase);
|
|
270
|
+
const byKey = rows && usableName(sourceFile, `${rows}By${capitalized(key.field)}`);
|
|
271
|
+
if (!byKey)
|
|
272
|
+
return;
|
|
273
|
+
const entry = `[${names.rowName}.${key.field}, ${names.rowName}]${asConst(sourceFile)}`;
|
|
274
|
+
const lookup = `${items}.map((${read.parameter}) => ${byKey}.get(${keyText}) ?? null)`;
|
|
275
|
+
return {
|
|
276
|
+
edits: [
|
|
277
|
+
insertLinesBefore(read.statement, [
|
|
278
|
+
`const ${rows} = await ${fetchLine};`,
|
|
279
|
+
`const ${byKey} = new Map(${rows}.map((${names.rowName}) => ${entry}));`,
|
|
280
|
+
]),
|
|
281
|
+
replaceNode(read.awaited, lookup),
|
|
282
|
+
...operator.edits,
|
|
283
|
+
],
|
|
284
|
+
note: joinNotes([mapKeyNote, key.field === 'id' ? '' : duplicateKeyNote]),
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
export function ormQueryInLoop({ node, finding, sourceFile }) {
|
|
288
|
+
if (!node || !sourceFile || !finding.message?.startsWith('TypeORM.'))
|
|
289
|
+
return;
|
|
290
|
+
const call = calleeCall(node);
|
|
291
|
+
if (!call || !isMethodCall(call))
|
|
292
|
+
return;
|
|
293
|
+
return typeormLookup(call, sourceFile) ?? promiseAllLookup(call, sourceFile);
|
|
294
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Rewrites per-item queries inside a for-of loop into one batched query before the loop, and single
|
|
2
|
+
// queries that load every row only to count, pick or filter them. Any shape not proven safe is left
|
|
3
|
+
// to the rule example. The builders live in the query-loop-* modules; this one registers them by rule
|
|
4
|
+
// id and re-exports the helpers batch-loops.cjs shares.
|
|
5
|
+
import { someNode, textWith, isReference, mentions, readsOnlyNames, plainProperties, indentationOf, } from './query-loop-nodes.js';
|
|
6
|
+
import { plural, capitalized, usableName } from './query-loop-names.js';
|
|
7
|
+
import { forOfBinding, loopLookup, inlinedLocal, itemKeyFilter, itemKeys, loopWorkNote } from './query-loop-sites.js';
|
|
8
|
+
import { mapItems } from './query-loop-collections.js';
|
|
9
|
+
import { keyedLookup, indentationStep, groupedLookup, groupedKeyNote, nullKeyNote, ownIdKey, mapKeyNote, duplicateKeyNote, joinNotes, invariantOptions, whereWith, } from './query-loop-lookups.js';
|
|
10
|
+
import { prismaQueryInLoop } from './query-loop-prisma.js';
|
|
11
|
+
import { ormQueryInLoop } from './query-loop-typeorm.js';
|
|
12
|
+
import { pgQueryInLoop, redisCommandInLoop } from './query-loop-pg-redis.js';
|
|
13
|
+
import { prismaCountMaterialization, prismaFirstMaterialization, prismaFilterMaterialization, prismaTopKMaterialization, pgFirstMaterialization, pgCountMaterialization, } from './query-loop-materialization.js';
|
|
14
|
+
export default {
|
|
15
|
+
'prisma-query-in-loop': prismaQueryInLoop,
|
|
16
|
+
'pg-query-in-loop': pgQueryInLoop,
|
|
17
|
+
'redis-command-in-loop': redisCommandInLoop,
|
|
18
|
+
'prisma-count-materialization': prismaCountMaterialization,
|
|
19
|
+
'prisma-first-materialization': prismaFirstMaterialization,
|
|
20
|
+
'prisma-filter-materialization': prismaFilterMaterialization,
|
|
21
|
+
'prisma-top-k-materialization': prismaTopKMaterialization,
|
|
22
|
+
'pg-first-materialization': pgFirstMaterialization,
|
|
23
|
+
'pg-count-materialization': pgCountMaterialization,
|
|
24
|
+
};
|
|
25
|
+
// The default export is the rule builder registry; helpers shared with batch-loops.cjs are a
|
|
26
|
+
// separate named export.
|
|
27
|
+
export const shared = {
|
|
28
|
+
someNode,
|
|
29
|
+
loopLookup,
|
|
30
|
+
forOfBinding,
|
|
31
|
+
itemKeyFilter,
|
|
32
|
+
itemKeys,
|
|
33
|
+
inlinedLocal,
|
|
34
|
+
loopWorkNote,
|
|
35
|
+
keyedLookup,
|
|
36
|
+
groupedLookup,
|
|
37
|
+
whereWith,
|
|
38
|
+
invariantOptions,
|
|
39
|
+
plainProperties,
|
|
40
|
+
readsOnlyNames,
|
|
41
|
+
mapItems,
|
|
42
|
+
usableName,
|
|
43
|
+
capitalized,
|
|
44
|
+
plural,
|
|
45
|
+
ownIdKey,
|
|
46
|
+
mentions,
|
|
47
|
+
joinNotes,
|
|
48
|
+
textWith,
|
|
49
|
+
indentationOf,
|
|
50
|
+
indentationStep,
|
|
51
|
+
isReference,
|
|
52
|
+
mapKeyNote,
|
|
53
|
+
groupedKeyNote,
|
|
54
|
+
nullKeyNote,
|
|
55
|
+
duplicateKeyNote,
|
|
56
|
+
typeormQueryInLoop: ormQueryInLoop,
|
|
57
|
+
};
|