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,172 @@
|
|
|
1
|
+
import { ts, ancestor, calleeCall, freshName, indentationAt, isPlainReference, requireReview, textOf, } from './helpers.js';
|
|
2
|
+
const CACHE_TTL_SECONDS = 30;
|
|
3
|
+
// Written into the generated field as is, digit separator included.
|
|
4
|
+
const MAX_CACHED_LOOKUPS = '10_000';
|
|
5
|
+
const typedExtensions = /\.[cm]?tsx?$/i;
|
|
6
|
+
// A guard that enforces revocation, roles or account state must see changes at once; a cached row
|
|
7
|
+
// would keep a revoked token or a removed role working until the TTL ends.
|
|
8
|
+
const accessStateWords = /revok|role|permission|tokenVersion|banned|blocked|suspend|disabled|isActive|deactivat/i;
|
|
9
|
+
const literalKinds = new Set([ts.SyntaxKind.TrueKeyword, ts.SyntaxKind.FalseKeyword, ts.SyntaxKind.NullKeyword]);
|
|
10
|
+
function isLiteral(node) {
|
|
11
|
+
return ts.isStringLiteralLike(node) || ts.isNumericLiteral(node) || literalKinds.has(node.kind);
|
|
12
|
+
}
|
|
13
|
+
// A value that names the row: a variable or property chain, or a literal.
|
|
14
|
+
function isKeyPart(node) {
|
|
15
|
+
return isPlainReference(node) || isLiteral(node);
|
|
16
|
+
}
|
|
17
|
+
// The variable values, which tell lookups apart; literals are the same on every request.
|
|
18
|
+
function variableParts(values) {
|
|
19
|
+
if (!values.every(isKeyPart))
|
|
20
|
+
return;
|
|
21
|
+
const parts = values.filter((value) => !isLiteral(value));
|
|
22
|
+
return parts.length ? parts : undefined;
|
|
23
|
+
}
|
|
24
|
+
// Option text without variables, such as `select: { id: true }`, means the same thing on every
|
|
25
|
+
// request.
|
|
26
|
+
function isConstant(node) {
|
|
27
|
+
let constant = true;
|
|
28
|
+
(function visit(child) {
|
|
29
|
+
if (!constant)
|
|
30
|
+
return;
|
|
31
|
+
if (ts.isIdentifier(child)) {
|
|
32
|
+
const parent = child.parent;
|
|
33
|
+
const isName = (ts.isPropertyAssignment(parent) && parent.name === child) ||
|
|
34
|
+
(ts.isPropertyAccessExpression(parent) && parent.name === child);
|
|
35
|
+
if (!isName && child.text !== 'undefined')
|
|
36
|
+
constant = false;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (child.kind === ts.SyntaxKind.ThisKeyword || ts.isCallExpression(child))
|
|
40
|
+
constant = false;
|
|
41
|
+
else
|
|
42
|
+
ts.forEachChild(child, visit);
|
|
43
|
+
})(node);
|
|
44
|
+
return constant;
|
|
45
|
+
}
|
|
46
|
+
// The values that identify the looked-up row, or undefined when the query depends on anything else.
|
|
47
|
+
function keyParts(where) {
|
|
48
|
+
if (!ts.isObjectLiteralExpression(where) || !where.properties.length)
|
|
49
|
+
return;
|
|
50
|
+
const values = [];
|
|
51
|
+
for (const property of where.properties) {
|
|
52
|
+
if (ts.isShorthandPropertyAssignment(property))
|
|
53
|
+
values.push(property.name);
|
|
54
|
+
else if (ts.isPropertyAssignment(property))
|
|
55
|
+
values.push(ts.skipOuterExpressions(property.initializer));
|
|
56
|
+
else
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
return variableParts(values);
|
|
60
|
+
}
|
|
61
|
+
function lookupKey(call, access) {
|
|
62
|
+
const method = access.name.text;
|
|
63
|
+
const [first, ...rest] = call.arguments;
|
|
64
|
+
if (!first)
|
|
65
|
+
return;
|
|
66
|
+
if (method === 'query') {
|
|
67
|
+
const values = rest[0];
|
|
68
|
+
if (!ts.isStringLiteralLike(first) || rest.length !== 1 || !ts.isArrayLiteralExpression(values))
|
|
69
|
+
return;
|
|
70
|
+
return variableParts([...values.elements]);
|
|
71
|
+
}
|
|
72
|
+
const options = ts.skipOuterExpressions(first);
|
|
73
|
+
if (rest.length || !ts.isObjectLiteralExpression(options))
|
|
74
|
+
return;
|
|
75
|
+
if (method.endsWith('By'))
|
|
76
|
+
return keyParts(options);
|
|
77
|
+
const whereProperty = options.properties.find((property) => ts.isPropertyAssignment(property) && textOf(property.name) === 'where');
|
|
78
|
+
if (!whereProperty)
|
|
79
|
+
return;
|
|
80
|
+
const others = options.properties.filter((property) => property !== whereProperty);
|
|
81
|
+
if (!others.every((property) => ts.isPropertyAssignment(property) && isConstant(property.initializer)))
|
|
82
|
+
return;
|
|
83
|
+
return keyParts(ts.skipOuterExpressions(whereProperty.initializer));
|
|
84
|
+
}
|
|
85
|
+
function receiverLabel(access) {
|
|
86
|
+
const receiver = access.expression;
|
|
87
|
+
const name = ts.isPropertyAccessExpression(receiver) ? receiver.name.text : textOf(receiver);
|
|
88
|
+
return /^\w+$/.test(name) ? name : undefined;
|
|
89
|
+
}
|
|
90
|
+
function capitalized(name) {
|
|
91
|
+
return name[0].toUpperCase() + name.slice(1);
|
|
92
|
+
}
|
|
93
|
+
function fieldLines(names, typed) {
|
|
94
|
+
const { cache, ttl, limit } = names;
|
|
95
|
+
const modifiers = typed ? 'private readonly ' : '';
|
|
96
|
+
const map = typed ? 'new Map<string, { expiresAt: number; value: unknown }>()' : 'new Map()';
|
|
97
|
+
return [
|
|
98
|
+
'// Guards run on every request, so this lookup is reused for a few seconds.',
|
|
99
|
+
`${modifiers}${cache} = ${map};`,
|
|
100
|
+
`${modifiers}${ttl} = ${CACHE_TTL_SECONDS}_000;`,
|
|
101
|
+
`${modifiers}${limit} = ${MAX_CACHED_LOOKUPS};`,
|
|
102
|
+
'',
|
|
103
|
+
];
|
|
104
|
+
}
|
|
105
|
+
function helperLines(names, typed) {
|
|
106
|
+
const { cache, ttl, limit, loader } = names;
|
|
107
|
+
const signature = typed
|
|
108
|
+
? `private async ${loader}<T>(key: string, load: () => Promise<T>): Promise<T> {`
|
|
109
|
+
: `async ${loader}(key, load) {`;
|
|
110
|
+
return [
|
|
111
|
+
'',
|
|
112
|
+
signature,
|
|
113
|
+
` const cached = this.${cache}.get(key);`,
|
|
114
|
+
` if (cached && cached.expiresAt > Date.now()) return cached.value${typed ? ' as T' : ''};`,
|
|
115
|
+
' const value = await load();',
|
|
116
|
+
' if (value === null || value === undefined) return value;',
|
|
117
|
+
` if (this.${cache}.size >= this.${limit}) this.${cache}.clear();`,
|
|
118
|
+
` this.${cache}.set(key, { expiresAt: Date.now() + this.${ttl}, value });`,
|
|
119
|
+
' return value;',
|
|
120
|
+
'}',
|
|
121
|
+
];
|
|
122
|
+
}
|
|
123
|
+
function guardQueryFix({ node, sourceFile, text }) {
|
|
124
|
+
if (!node || !sourceFile || text === undefined)
|
|
125
|
+
return;
|
|
126
|
+
const call = calleeCall(node);
|
|
127
|
+
if (!call || !ts.isPropertyAccessExpression(call.expression))
|
|
128
|
+
return;
|
|
129
|
+
const parts = lookupKey(call, call.expression);
|
|
130
|
+
const label = receiverLabel(call.expression);
|
|
131
|
+
const classNode = ancestor(call, ts.isClassDeclaration);
|
|
132
|
+
if (!parts || !label || !classNode || accessStateWords.test(classNode.getText(sourceFile)))
|
|
133
|
+
return;
|
|
134
|
+
const cache = freshName(sourceFile, `${label}LookupCache`);
|
|
135
|
+
const ttl = freshName(sourceFile, `${label}LookupTtlMs`);
|
|
136
|
+
const limit = freshName(sourceFile, `${label}LookupMaxEntries`);
|
|
137
|
+
const loader = freshName(sourceFile, `getOrLoad${capitalized(label)}`);
|
|
138
|
+
if (!cache || !ttl || !limit || !loader)
|
|
139
|
+
return;
|
|
140
|
+
const names = { cache, ttl, limit, loader };
|
|
141
|
+
const typed = typedExtensions.test(sourceFile.fileName);
|
|
142
|
+
const key = '`' + parts.map((part) => '${' + textOf(part) + '}').join(':') + '`';
|
|
143
|
+
const classIndent = indentationAt(text, classNode.getStart(sourceFile));
|
|
144
|
+
const memberIndent = classNode.members.length
|
|
145
|
+
? indentationAt(text, classNode.members[0].getStart(sourceFile))
|
|
146
|
+
: classIndent + ' ';
|
|
147
|
+
const openBrace = classNode.members.pos - 1;
|
|
148
|
+
const afterOpenLine = text.indexOf('\n', openBrace) + 1;
|
|
149
|
+
const closeLine = text.lastIndexOf('\n', classNode.end - 1) + 1;
|
|
150
|
+
// New members go on lines of their own, so both braces must end and start their lines.
|
|
151
|
+
if (text[openBrace] !== '{' || text.slice(openBrace + 1, afterOpenLine).trim())
|
|
152
|
+
return;
|
|
153
|
+
if (closeLine <= afterOpenLine || text.slice(closeLine, classNode.end).trim() !== '}')
|
|
154
|
+
return;
|
|
155
|
+
const indentLines = (lines) => lines.map((line) => (line ? memberIndent + line : '') + '\n').join('');
|
|
156
|
+
return {
|
|
157
|
+
edits: [
|
|
158
|
+
{
|
|
159
|
+
start: afterOpenLine,
|
|
160
|
+
end: afterOpenLine,
|
|
161
|
+
text: indentLines(fieldLines(names, typed)),
|
|
162
|
+
},
|
|
163
|
+
{ start: call.getStart(sourceFile), end: call.getStart(sourceFile), text: `this.${names.loader}(${key}, () => ` },
|
|
164
|
+
{ start: call.end, end: call.end, text: ')' },
|
|
165
|
+
{ start: closeLine, end: closeLine, text: indentLines(helperLines(names, typed)) },
|
|
166
|
+
],
|
|
167
|
+
note: `Caches this lookup for ${CACHE_TTL_SECONDS} s per guard instance and per process, keyed by ${key}; missing rows are not cached. A change to the row (status, role, token version, slug) shows up only after the TTL, so clear \`this.${names.cache}\` where it changes, or lower \`${names.ttl}\`, if that delay is not acceptable. Requests share the cached object, so do not mutate it.`,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
export default {
|
|
171
|
+
'guard-query-per-request': requireReview('Adds a cache with a chosen TTL, so changed rows show up late.', guardQueryFix),
|
|
172
|
+
};
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
// Shared syntax helpers for site-fix builders. Builders return edits as { start, end, text } file
|
|
2
|
+
// offsets.
|
|
3
|
+
import { ts } from '../compiler.js';
|
|
4
|
+
import { createReferenceChecks } from '../reference-checks.js';
|
|
5
|
+
let cachedRefChecksTs;
|
|
6
|
+
let cachedRefChecks;
|
|
7
|
+
function refChecks() {
|
|
8
|
+
if (cachedRefChecksTs !== ts || !cachedRefChecks) {
|
|
9
|
+
cachedRefChecksTs = ts;
|
|
10
|
+
cachedRefChecks = createReferenceChecks(ts);
|
|
11
|
+
}
|
|
12
|
+
return cachedRefChecks;
|
|
13
|
+
}
|
|
14
|
+
function isPlainReference(node) {
|
|
15
|
+
return refChecks().isPlainReference(node);
|
|
16
|
+
}
|
|
17
|
+
function mentionsIdentifier(node, name) {
|
|
18
|
+
return refChecks().mentionsIdentifier(node, name);
|
|
19
|
+
}
|
|
20
|
+
function textOf(node) {
|
|
21
|
+
return node.getText(node.getSourceFile());
|
|
22
|
+
}
|
|
23
|
+
function replaceNode(node, text) {
|
|
24
|
+
return { start: node.getStart(node.getSourceFile()), end: node.end, text };
|
|
25
|
+
}
|
|
26
|
+
function ancestor(node, predicate) {
|
|
27
|
+
for (let current = node; current; current = current.parent)
|
|
28
|
+
if (predicate(current))
|
|
29
|
+
return current;
|
|
30
|
+
}
|
|
31
|
+
// The innermost call whose callee (`find`, `repo.find`) contains the reported position.
|
|
32
|
+
function calleeCall(node) {
|
|
33
|
+
for (let call = ancestor(node, ts.isCallExpression); call; call = ancestor(call.parent, ts.isCallExpression)) {
|
|
34
|
+
if (ancestor(node, (current) => current === call.expression))
|
|
35
|
+
return call;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function enclosingStatement(node) {
|
|
39
|
+
return ancestor(node, (current) => ts.isStatement(current) && (ts.isBlock(current.parent) || ts.isSourceFile(current.parent)));
|
|
40
|
+
}
|
|
41
|
+
function lineStart(text, offset) {
|
|
42
|
+
return offset <= 0 ? 0 : text.lastIndexOf('\n', offset - 1) + 1;
|
|
43
|
+
}
|
|
44
|
+
function indentationAt(text, offset) {
|
|
45
|
+
const start = lineStart(text, offset);
|
|
46
|
+
let end = start;
|
|
47
|
+
while (end < text.length && (text[end] === ' ' || text[end] === '\t'))
|
|
48
|
+
end++;
|
|
49
|
+
return text.slice(start, end);
|
|
50
|
+
}
|
|
51
|
+
// Inserts whole lines before the line that holds `node`, matching that line's indentation.
|
|
52
|
+
function insertLinesBefore(node, lines) {
|
|
53
|
+
const sourceFile = node.getSourceFile();
|
|
54
|
+
const text = sourceFile.text;
|
|
55
|
+
const start = lineStart(text, node.getStart(sourceFile));
|
|
56
|
+
const indentation = indentationAt(text, start);
|
|
57
|
+
return { start, end: start, text: lines.map((line) => indentation + line + '\n').join('') };
|
|
58
|
+
}
|
|
59
|
+
function isLoopKind(kind) {
|
|
60
|
+
return (kind === ts.SyntaxKind.ForOfStatement ||
|
|
61
|
+
kind === ts.SyntaxKind.ForInStatement ||
|
|
62
|
+
kind === ts.SyntaxKind.ForStatement ||
|
|
63
|
+
kind === ts.SyntaxKind.WhileStatement ||
|
|
64
|
+
kind === ts.SyntaxKind.DoStatement);
|
|
65
|
+
}
|
|
66
|
+
const iteratingMethods = new Set([
|
|
67
|
+
'map',
|
|
68
|
+
'forEach',
|
|
69
|
+
'filter',
|
|
70
|
+
'some',
|
|
71
|
+
'every',
|
|
72
|
+
'find',
|
|
73
|
+
'findIndex',
|
|
74
|
+
'flatMap',
|
|
75
|
+
'reduce',
|
|
76
|
+
]);
|
|
77
|
+
// The nearest loop statement or array-iteration callback around `node`, inside the same function.
|
|
78
|
+
function enclosingIteration(node) {
|
|
79
|
+
for (let current = node.parent; current; current = current.parent) {
|
|
80
|
+
if (isLoopKind(current.kind))
|
|
81
|
+
return { kind: 'loop', node: current };
|
|
82
|
+
if (ts.isFunctionLike(current)) {
|
|
83
|
+
const call = current.parent;
|
|
84
|
+
if (call &&
|
|
85
|
+
ts.isCallExpression(call) &&
|
|
86
|
+
call.arguments[0] === current &&
|
|
87
|
+
ts.isPropertyAccessExpression(call.expression) &&
|
|
88
|
+
iteratingMethods.has(call.expression.name.text)) {
|
|
89
|
+
return { kind: 'callback', node: call, callback: current, method: call.expression.name.text };
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const identifiersByFile = new WeakMap();
|
|
96
|
+
function identifiersIn(sourceFile) {
|
|
97
|
+
let names = identifiersByFile.get(sourceFile);
|
|
98
|
+
if (names)
|
|
99
|
+
return names;
|
|
100
|
+
names = new Set();
|
|
101
|
+
const collect = (node) => {
|
|
102
|
+
if (ts.isIdentifier(node))
|
|
103
|
+
names.add(node.text);
|
|
104
|
+
ts.forEachChild(node, collect);
|
|
105
|
+
};
|
|
106
|
+
collect(sourceFile);
|
|
107
|
+
identifiersByFile.set(sourceFile, names);
|
|
108
|
+
return names;
|
|
109
|
+
}
|
|
110
|
+
// True when `name` is declared anywhere in the file, so a new binding with that name could shadow
|
|
111
|
+
// or clash.
|
|
112
|
+
function nameTaken(sourceFile, name) {
|
|
113
|
+
return identifiersIn(sourceFile).has(name);
|
|
114
|
+
}
|
|
115
|
+
function freshName(sourceFile, base) {
|
|
116
|
+
if (!nameTaken(sourceFile, base))
|
|
117
|
+
return base;
|
|
118
|
+
for (let suffix = 2; suffix < 100; suffix++)
|
|
119
|
+
if (!nameTaken(sourceFile, base + suffix))
|
|
120
|
+
return base + suffix;
|
|
121
|
+
}
|
|
122
|
+
function spansLines(text, from, to) {
|
|
123
|
+
return text.slice(from, to).includes('\n');
|
|
124
|
+
}
|
|
125
|
+
// Adds `property` to an object literal, on its own line when the literal is already multi-line.
|
|
126
|
+
function addProperty(literal, property, text) {
|
|
127
|
+
const [last] = literal.properties.slice(-1);
|
|
128
|
+
if (!last)
|
|
129
|
+
return { start: literal.getStart(), end: literal.end, text: `{ ${property} }` };
|
|
130
|
+
const trailingComma = literal.properties.hasTrailingComma;
|
|
131
|
+
const multiline = spansLines(text, literal.getStart(), last.getStart());
|
|
132
|
+
const commaEnd = trailingComma ? text.indexOf(',', last.end) + 1 : last.end;
|
|
133
|
+
if (multiline) {
|
|
134
|
+
const indentation = indentationAt(text, last.getStart());
|
|
135
|
+
const lineText = `\n${indentation}${property}`;
|
|
136
|
+
return { start: commaEnd, end: commaEnd, text: trailingComma ? `${lineText},` : `,${lineText}` };
|
|
137
|
+
}
|
|
138
|
+
return { start: commaEnd, end: commaEnd, text: trailingComma ? ` ${property},` : `, ${property}` };
|
|
139
|
+
}
|
|
140
|
+
// Appends `{ property }` as a new last argument.
|
|
141
|
+
function addOptionsArgument(call, property, text) {
|
|
142
|
+
const options = `{ ${property} }`;
|
|
143
|
+
const [last] = call.arguments.slice(-1);
|
|
144
|
+
if (!last) {
|
|
145
|
+
const open = text.indexOf('(', call.expression.end);
|
|
146
|
+
const insertAt = open === -1 ? call.end - 1 : open + 1;
|
|
147
|
+
return { start: insertAt, end: insertAt, text: options };
|
|
148
|
+
}
|
|
149
|
+
const trailingComma = call.arguments.hasTrailingComma;
|
|
150
|
+
const commaEnd = trailingComma ? text.indexOf(',', last.end) + 1 : last.end;
|
|
151
|
+
if (spansLines(text, call.expression.end, last.getStart())) {
|
|
152
|
+
const lineText = `\n${indentationAt(text, last.getStart())}${options}`;
|
|
153
|
+
return { start: commaEnd, end: commaEnd, text: trailingComma ? `${lineText},` : `,${lineText}` };
|
|
154
|
+
}
|
|
155
|
+
return { start: commaEnd, end: commaEnd, text: trailingComma ? ` ${options},` : `, ${options}` };
|
|
156
|
+
}
|
|
157
|
+
function hasMultilineTemplate(sourceFile, start, end) {
|
|
158
|
+
let found = false;
|
|
159
|
+
(function visit(child) {
|
|
160
|
+
if (found || child.end <= start || child.getStart(sourceFile) >= end)
|
|
161
|
+
return;
|
|
162
|
+
const isTemplate = ts.isTemplateExpression(child) || ts.isNoSubstitutionTemplateLiteral(child);
|
|
163
|
+
if (isTemplate && textOf(child).includes('\n'))
|
|
164
|
+
found = true;
|
|
165
|
+
else
|
|
166
|
+
ts.forEachChild(child, visit);
|
|
167
|
+
})(sourceFile);
|
|
168
|
+
return found;
|
|
169
|
+
}
|
|
170
|
+
// Every name a for-of binds per item: `item`, `[index, item]` or `{ id, name }`.
|
|
171
|
+
function bindingNames(name, names = new Set()) {
|
|
172
|
+
if (ts.isIdentifier(name))
|
|
173
|
+
names.add(name.text);
|
|
174
|
+
else
|
|
175
|
+
for (const element of name.elements)
|
|
176
|
+
if (!ts.isOmittedExpression(element))
|
|
177
|
+
bindingNames(element.name, names);
|
|
178
|
+
return names;
|
|
179
|
+
}
|
|
180
|
+
// Wraps a builder so the fixes it returns wait for individual review: `loadwise fix --yes` and
|
|
181
|
+
// `--fix --yes` skip them. `reason` leads the note. `appliesTo(fix)` limits the review to the
|
|
182
|
+
// variants that change behaviour.
|
|
183
|
+
function requireReview(reason, builder, appliesTo = () => true) {
|
|
184
|
+
return (...args) => {
|
|
185
|
+
const fix = builder(...args);
|
|
186
|
+
if (!fix || !appliesTo(fix))
|
|
187
|
+
return fix;
|
|
188
|
+
return { ...fix, requiresReview: true, note: fix.note ? `${reason} ${fix.note}` : reason };
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
// True when `text` between the offsets holds a comment, which a whole-loop rewrite would silently
|
|
192
|
+
// drop.
|
|
193
|
+
function hasCommentBetween(text, from, to) {
|
|
194
|
+
const scanner = ts.createScanner(ts.ScriptTarget.Latest, false, ts.LanguageVariant.Standard, text.slice(from, to));
|
|
195
|
+
for (let token = scanner.scan(); token !== ts.SyntaxKind.EndOfFileToken; token = scanner.scan())
|
|
196
|
+
if (token === ts.SyntaxKind.SingleLineCommentTrivia || token === ts.SyntaxKind.MultiLineCommentTrivia)
|
|
197
|
+
return true;
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
export { requireReview, hasCommentBetween, bindingNames, hasMultilineTemplate, addProperty, addOptionsArgument, ts, textOf, replaceNode, ancestor, calleeCall, enclosingStatement, enclosingIteration, indentationAt, insertLinesBefore, lineStart, freshName, nameTaken, isPlainReference, mentionsIdentifier, };
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// Shared by site fixes that move an awaited call out of an expression into a statement placed
|
|
2
|
+
// before it.
|
|
3
|
+
import { ts, textOf, lineStart } from './helpers.js';
|
|
4
|
+
const neverFree = () => false;
|
|
5
|
+
const clockCalls = new Set(['Date.now', 'performance.now']);
|
|
6
|
+
const unaryWrites = new Set([ts.SyntaxKind.PlusPlusToken, ts.SyntaxKind.MinusMinusToken]);
|
|
7
|
+
// True when evaluating `node` has no effect another expression could observe, so its position among
|
|
8
|
+
// awaits is free.
|
|
9
|
+
const pureKeywordKinds = [
|
|
10
|
+
ts.SyntaxKind.TrueKeyword,
|
|
11
|
+
ts.SyntaxKind.FalseKeyword,
|
|
12
|
+
ts.SyntaxKind.NullKeyword,
|
|
13
|
+
ts.SyntaxKind.SuperKeyword,
|
|
14
|
+
];
|
|
15
|
+
// loadwise-reviewed high-branch-complexity -- a flat dispatch over independent expression kinds, one early return per kind; each case is exclusive and a lookup table would hide the recursion
|
|
16
|
+
function isPure(node, isFree = neverFree) {
|
|
17
|
+
if (!node || isFree(node))
|
|
18
|
+
return true;
|
|
19
|
+
if (ts.isIdentifier(node) || ts.isLiteralExpression(node) || node.kind === ts.SyntaxKind.ThisKeyword)
|
|
20
|
+
return true;
|
|
21
|
+
if (ts.isFunctionLike(node) || ts.isRegularExpressionLiteral(node))
|
|
22
|
+
return true;
|
|
23
|
+
if (pureKeywordKinds.includes(node.kind))
|
|
24
|
+
return true;
|
|
25
|
+
if (ts.isParenthesizedExpression(node) || ts.isNonNullExpression(node) || ts.isAsExpression(node))
|
|
26
|
+
return isPure(node.expression, isFree);
|
|
27
|
+
if (ts.isSatisfiesExpression(node) || ts.isTypeAssertionExpression(node))
|
|
28
|
+
return isPure(node.expression, isFree);
|
|
29
|
+
if (ts.isPropertyAccessExpression(node))
|
|
30
|
+
return isPure(node.expression, isFree);
|
|
31
|
+
if (ts.isElementAccessExpression(node))
|
|
32
|
+
return isPure(node.expression, isFree) && isPure(node.argumentExpression, isFree);
|
|
33
|
+
if (ts.isTemplateExpression(node))
|
|
34
|
+
return node.templateSpans.every((span) => isPure(span.expression, isFree));
|
|
35
|
+
if (ts.isPrefixUnaryExpression(node))
|
|
36
|
+
return !unaryWrites.has(node.operator) && isPure(node.operand, isFree);
|
|
37
|
+
if (ts.isTypeOfExpression(node))
|
|
38
|
+
return isPure(node.expression, isFree);
|
|
39
|
+
if (ts.isBinaryExpression(node)) {
|
|
40
|
+
const operator = node.operatorToken.kind;
|
|
41
|
+
if (operator >= ts.SyntaxKind.FirstAssignment && operator <= ts.SyntaxKind.LastAssignment)
|
|
42
|
+
return false;
|
|
43
|
+
return isPure(node.left, isFree) && isPure(node.right, isFree);
|
|
44
|
+
}
|
|
45
|
+
if (ts.isConditionalExpression(node))
|
|
46
|
+
return [node.condition, node.whenTrue, node.whenFalse].every((child) => isPure(child, isFree));
|
|
47
|
+
if (ts.isArrayLiteralExpression(node))
|
|
48
|
+
return node.elements.every((child) => isPure(child, isFree));
|
|
49
|
+
if (ts.isSpreadElement(node) || ts.isSpreadAssignment(node))
|
|
50
|
+
return isPure(node.expression, isFree);
|
|
51
|
+
if (ts.isObjectLiteralExpression(node))
|
|
52
|
+
return node.properties.every((child) => isPure(child, isFree));
|
|
53
|
+
if (ts.isPropertyAssignment(node))
|
|
54
|
+
return !ts.isComputedPropertyName(node.name) && isPure(node.initializer, isFree);
|
|
55
|
+
if (ts.isShorthandPropertyAssignment(node) || ts.isMethodDeclaration(node))
|
|
56
|
+
return true;
|
|
57
|
+
if (ts.isCallExpression(node))
|
|
58
|
+
return clockCalls.has(textOf(node.expression)) && node.arguments.every((child) => isPure(child, isFree));
|
|
59
|
+
if (ts.isNewExpression(node)) {
|
|
60
|
+
return textOf(node.expression) === 'Date' && (node.arguments ?? []).every((child) => isPure(child, isFree));
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
const sequentialBinaryOperators = new Set([
|
|
65
|
+
ts.SyntaxKind.AmpersandAmpersandToken,
|
|
66
|
+
ts.SyntaxKind.BarBarToken,
|
|
67
|
+
ts.SyntaxKind.QuestionQuestionToken,
|
|
68
|
+
]);
|
|
69
|
+
const transparentKinds = [
|
|
70
|
+
ts.isParenthesizedExpression,
|
|
71
|
+
ts.isAsExpression,
|
|
72
|
+
ts.isNonNullExpression,
|
|
73
|
+
ts.isSatisfiesExpression,
|
|
74
|
+
ts.isTypeAssertionExpression,
|
|
75
|
+
ts.isAwaitExpression,
|
|
76
|
+
ts.isSpreadElement,
|
|
77
|
+
ts.isSpreadAssignment,
|
|
78
|
+
ts.isPropertyAssignment,
|
|
79
|
+
ts.isVariableDeclaration,
|
|
80
|
+
ts.isVariableStatement,
|
|
81
|
+
ts.isReturnStatement,
|
|
82
|
+
ts.isExpressionStatement,
|
|
83
|
+
ts.isThrowStatement,
|
|
84
|
+
];
|
|
85
|
+
function isStatementList(node) {
|
|
86
|
+
return ts.isBlock(node) || ts.isSourceFile(node) || ts.isModuleBlock(node) || ts.isCaseClause(node);
|
|
87
|
+
}
|
|
88
|
+
// Whether `parent` evaluates everything before `child` without effects, and always evaluates
|
|
89
|
+
// `child`.
|
|
90
|
+
function reachesChildPurely(parent, child, isFree) {
|
|
91
|
+
if (transparentKinds.some((test) => test(parent)))
|
|
92
|
+
return true;
|
|
93
|
+
const before = (list) => list.slice(0, list.indexOf(child)).every((earlier) => isPure(earlier, isFree));
|
|
94
|
+
if (ts.isVariableDeclarationList(parent)) {
|
|
95
|
+
const declarationNodes = parent.declarations;
|
|
96
|
+
return parent.declarations
|
|
97
|
+
.slice(0, declarationNodes.indexOf(child))
|
|
98
|
+
.every((declaration) => isPure(declaration.initializer, isFree));
|
|
99
|
+
}
|
|
100
|
+
if (ts.isObjectLiteralExpression(parent))
|
|
101
|
+
return before([...parent.properties]);
|
|
102
|
+
if (ts.isArrayLiteralExpression(parent))
|
|
103
|
+
return before([...parent.elements]);
|
|
104
|
+
if (ts.isCallExpression(parent) || ts.isNewExpression(parent)) {
|
|
105
|
+
if (parent.expression === child)
|
|
106
|
+
return true;
|
|
107
|
+
if (ts.isCallExpression(parent) && parent.questionDotToken)
|
|
108
|
+
return false;
|
|
109
|
+
return isPure(parent.expression, isFree) && before([...(parent.arguments ?? [])]);
|
|
110
|
+
}
|
|
111
|
+
if (ts.isPropertyAccessExpression(parent))
|
|
112
|
+
return parent.expression === child;
|
|
113
|
+
if (ts.isElementAccessExpression(parent))
|
|
114
|
+
return parent.expression === child || isPure(parent.expression, isFree);
|
|
115
|
+
if (ts.isBinaryExpression(parent)) {
|
|
116
|
+
if (parent.left === child)
|
|
117
|
+
return true;
|
|
118
|
+
return !sequentialBinaryOperators.has(parent.operatorToken.kind) && isPure(parent.left, isFree);
|
|
119
|
+
}
|
|
120
|
+
if (ts.isConditionalExpression(parent))
|
|
121
|
+
return parent.condition === child;
|
|
122
|
+
if (ts.isTemplateSpan(parent))
|
|
123
|
+
return true;
|
|
124
|
+
if (ts.isTemplateExpression(parent)) {
|
|
125
|
+
const spanNodes = parent.templateSpans;
|
|
126
|
+
return parent.templateSpans.slice(0, spanNodes.indexOf(child)).every((span) => isPure(span.expression, isFree));
|
|
127
|
+
}
|
|
128
|
+
if (ts.isForOfStatement(parent) || ts.isForInStatement(parent))
|
|
129
|
+
return parent.expression === child;
|
|
130
|
+
if (ts.isIfStatement(parent) || ts.isSwitchStatement(parent))
|
|
131
|
+
return parent.expression === child;
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
// Where a hoisted line can go: before the statement that always runs `start`, or into a concise
|
|
135
|
+
// arrow body. Nodes accepted by `isFree` may be evaluated earlier than they are now (they are
|
|
136
|
+
// hoisted too).
|
|
137
|
+
function hoistAnchor(start, isFree = neverFree) {
|
|
138
|
+
let child = start;
|
|
139
|
+
for (let parent = start.parent; parent; child = parent, parent = parent.parent) {
|
|
140
|
+
if (ts.isStatement(child) && isStatementList(parent))
|
|
141
|
+
return { statement: child };
|
|
142
|
+
if (ts.isArrowFunction(parent) && parent.body === child)
|
|
143
|
+
return { arrow: parent };
|
|
144
|
+
if (ts.isFunctionLike(parent) || isStatementList(parent))
|
|
145
|
+
return;
|
|
146
|
+
if (!reachesChildPurely(parent, child, isFree))
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function startsOwnLine(statement) {
|
|
151
|
+
const text = statement.getSourceFile().text;
|
|
152
|
+
const start = statement.getStart();
|
|
153
|
+
return /^[ \t]*$/.test(text.slice(lineStart(text, start), start));
|
|
154
|
+
}
|
|
155
|
+
export { isPure, hoistAnchor, startsOwnLine };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ts, calleeCall, addProperty, addOptionsArgument } from './helpers.js';
|
|
2
|
+
import { describeCall, skipParentheses } from '../http-timeouts.js';
|
|
3
|
+
const limitSource = {
|
|
4
|
+
signal: 'signal: AbortSignal.timeout(10_000)',
|
|
5
|
+
timeout: 'timeout: 10_000',
|
|
6
|
+
};
|
|
7
|
+
const placeholderNote = 'The 10 s limit is a placeholder; tune it to the slowest response this API should ever take.';
|
|
8
|
+
const slowWorkNote = 'This request sends a body or targets a long-running endpoint (upload, inference, export), so a 10 s limit can abort work that normally succeeds. ' +
|
|
9
|
+
'Set the limit from the slowest response this endpoint should ever take.';
|
|
10
|
+
const longRunningUrl = /upload|predict|infer|export|import|download|backup|transcod|render|stream/i;
|
|
11
|
+
const bodyArgumentIndex = 1;
|
|
12
|
+
function hasProperty(literal, names) {
|
|
13
|
+
return literal.properties.some((property) => property.name &&
|
|
14
|
+
(ts.isIdentifier(property.name) || ts.isStringLiteral(property.name)) &&
|
|
15
|
+
names.includes(property.name.text));
|
|
16
|
+
}
|
|
17
|
+
// Uploads, inference, exports and other writes can legitimately take longer than the placeholder
|
|
18
|
+
// limit.
|
|
19
|
+
function mayRunLong(call, target, literal) {
|
|
20
|
+
if (literal && hasProperty(literal, ['body', 'data']))
|
|
21
|
+
return true;
|
|
22
|
+
if (target.library === 'axios' &&
|
|
23
|
+
target.optionsIndex > bodyArgumentIndex &&
|
|
24
|
+
call.arguments.length > bodyArgumentIndex) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
const [url] = call.arguments;
|
|
28
|
+
return !!url && longRunningUrl.test(url.getText());
|
|
29
|
+
}
|
|
30
|
+
function withReview(edit, call, target, literal) {
|
|
31
|
+
if (!mayRunLong(call, target, literal))
|
|
32
|
+
return { edits: [edit], note: placeholderNote };
|
|
33
|
+
return { edits: [edit], note: slowWorkNote, requiresReview: true };
|
|
34
|
+
}
|
|
35
|
+
function timeoutFix({ node, text }) {
|
|
36
|
+
if (!node || text === undefined)
|
|
37
|
+
return;
|
|
38
|
+
const call = calleeCall(node);
|
|
39
|
+
if (!call)
|
|
40
|
+
return;
|
|
41
|
+
const target = describeCall(call);
|
|
42
|
+
if (!target)
|
|
43
|
+
return;
|
|
44
|
+
const property = limitSource[target.limitProperty];
|
|
45
|
+
const options = call.arguments[target.optionsIndex];
|
|
46
|
+
if (options) {
|
|
47
|
+
const literal = skipParentheses(options);
|
|
48
|
+
if (!ts.isObjectLiteralExpression(literal))
|
|
49
|
+
return;
|
|
50
|
+
return withReview(addProperty(literal, property, text), call, target, literal);
|
|
51
|
+
}
|
|
52
|
+
if (call.arguments.length !== target.optionsIndex)
|
|
53
|
+
return;
|
|
54
|
+
return withReview(addOptionsArgument(call, property, text), call, target);
|
|
55
|
+
}
|
|
56
|
+
export default { 'http-call-without-timeout': timeoutFix };
|