@preventive/triage 1.0.0-alpha.8 → 1.0.0-alpha.80
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-APACHE +202 -0
- package/README.md +16 -0
- package/api/reap.ts +16 -78
- package/cli.js +6 -0
- package/client/dependency-paths.d.ts +3 -0
- package/client/dependency-paths.js +36 -0
- package/client/finding-link.js +305 -0
- package/client/linked-findings.d.ts +1 -0
- package/client/linked-findings.js +115 -0
- package/common/bundle-commit.d.ts +1 -0
- package/common/bundle-commit.js +4 -0
- package/common/bundle-compare-diff.d.ts +6 -0
- package/common/bundle-compare-diff.js +377 -0
- package/common/bundle-compare-inputs.d.ts +3 -0
- package/common/bundle-compare-inputs.js +141 -0
- package/common/bundle-compare-versions.js +172 -0
- package/common/bundle-comparison.d.ts +8 -0
- package/common/bundle-comparison.js +69 -0
- package/common/bundle-imports.js +20 -0
- package/common/bundle-metadata.d.ts +15 -0
- package/common/bundle-metadata.js +226 -0
- package/common/bundle-pkg-of.d.ts +1 -0
- package/common/bundle-pkg-of.js +90 -0
- package/common/bundle-reasons.d.ts +6 -0
- package/common/bundle-reasons.js +58 -0
- package/common/bundle-source-links.d.ts +6 -0
- package/common/bundle-source-links.js +216 -0
- package/common/bundle-sourcemap.d.ts +10 -0
- package/common/bundle-sourcemap.js +100 -0
- package/common/bundle-sources.d.ts +10 -0
- package/common/bundle-sources.js +374 -0
- package/common/bundle-stats.js +41 -0
- package/common/bundle-tabs.js +1 -0
- package/common/code-language.js +66 -0
- package/common/default-scan-models.ts +36 -0
- package/common/dependency-reviews.d.ts +18 -0
- package/common/dependency-reviews.js +64 -0
- package/common/finding-duplicates.js +63 -0
- package/common/finding-filters.js +313 -0
- package/common/finding-id.js +47 -0
- package/common/finding-repo.d.ts +5 -0
- package/common/finding-repo.js +67 -0
- package/common/github-issue-labels.d.ts +1 -0
- package/common/github-issue-labels.js +11 -0
- package/common/github-pr.ts +56 -0
- package/common/gzip.js +59 -0
- package/common/line-diff.d.ts +14 -0
- package/common/line-diff.js +181 -0
- package/common/linked-workspace-groups.js +63 -0
- package/common/managed/agent-tasks.ts +292 -0
- package/common/managed/comments.ts +43 -0
- package/common/managed/dependency-routes.js +25 -0
- package/common/managed/directory-packages.ts +28 -0
- package/common/managed/finding-detail.d.ts +5 -0
- package/common/managed/finding-detail.js +75 -0
- package/common/managed/finding-values.d.ts +2 -0
- package/common/managed/finding-values.js +138 -0
- package/common/managed/github-agents.ts +114 -0
- package/common/managed/github-logins.ts +49 -0
- package/common/managed/lite-name.d.ts +2 -0
- package/common/managed/lite-name.js +20 -0
- package/common/managed/npm-packages.d.ts +9 -0
- package/common/managed/npm-packages.js +63 -0
- package/common/managed/permissions.ts +31 -0
- package/common/managed/report-content.ts +72 -0
- package/common/managed/report-filter.ts +120 -0
- package/common/managed/repository-alias.ts +65 -0
- package/common/managed/review-view-routes.js +23 -0
- package/common/managed/risk-routes.js +30 -0
- package/common/managed/roles.ts +41 -0
- package/common/managed/routes.d.ts +2 -0
- package/common/managed/routes.js +385 -0
- package/common/managed/scan-models.ts +6 -0
- package/common/managed/stasis-config.ts +7 -0
- package/common/managed/team-app.d.ts +19 -0
- package/common/managed/team-app.js +129 -0
- package/common/managed/team-filters.js +26 -0
- package/common/managed/triage.ts +83 -0
- package/common/managed/upload-seal.ts +126 -0
- package/common/pretty-json.js +98 -0
- package/common/pretty-kinds.js +20 -0
- package/common/pretty-print.d.ts +6 -0
- package/common/pretty-print.js +36 -0
- package/common/pretty-sourcemap.js +70 -0
- package/common/repo-commit.d.ts +4 -0
- package/common/repo-commit.js +30 -0
- package/common/revalidation-conflicts.js +48 -0
- package/common/revalidation-input-groups.js +56 -0
- package/common/save-error-reason.ts +20 -7
- package/common/scan-server.ts +13 -0
- package/common/security-links.d.ts +5 -0
- package/common/security-links.js +33 -0
- package/common/server-info.ts +46 -0
- package/common/sourcemap-listing.js +78 -0
- package/common/sourcemap-mappings.js +136 -0
- package/common/sourcemap-unlist.js +85 -0
- package/common/stasis-files.d.ts +5 -0
- package/common/stasis-files.js +20 -0
- package/common/stasis-tgz.d.ts +6 -0
- package/common/stasis-tgz.js +27 -0
- package/common/utf8.d.ts +3 -0
- package/common/utf8.js +45 -0
- package/common/whitespace-insensitive.js +19 -0
- package/common/workspace-app.js +91 -0
- package/common/workspace-groups.js +176 -0
- package/out/activity.js +2 -0
- package/out/brotli-fallback.js +3 -3
- package/out/chunk-2XUEZHIP.js +28 -0
- package/out/chunk-55YIWY3H.js +5 -0
- package/out/chunk-5AVGKFMR.js +1 -0
- package/out/chunk-5CJKUV53.js +1 -0
- package/out/chunk-5EAVJAD2.js +3 -0
- package/out/chunk-5M2X3QPK.js +6 -0
- package/out/chunk-5QWPKTCE.js +40 -0
- package/out/chunk-6CCSTJWB.js +1 -0
- package/out/chunk-6VOB5WXX.js +2 -0
- package/out/chunk-6Y6PZ2BU.js +9 -0
- package/out/chunk-74JZTGTO.js +11 -0
- package/out/chunk-7BKKYVWR.js +7 -0
- package/out/chunk-7C7DWL7I.js +1 -0
- package/out/chunk-7HP2VYIC.js +2 -0
- package/out/chunk-7YFJUT2P.js +1 -0
- package/out/chunk-7YO4QV5P.js +1 -0
- package/out/chunk-A4BBBHQU.js +1 -0
- package/out/chunk-B64CTMVU.js +4 -0
- package/out/chunk-BEKYZCPX.js +14 -0
- package/out/chunk-C4Z6ZBXV.js +10 -0
- package/out/chunk-CU3FPB3P.js +1 -0
- package/out/chunk-DEVAORP2.js +1 -0
- package/out/chunk-DUASGS2O.js +8 -0
- package/out/chunk-DUS5ARE2.js +53 -0
- package/out/chunk-EEJA7JBI.js +13 -0
- package/out/chunk-FSU2PLJL.js +1 -0
- package/out/chunk-GBMAXAYK.js +3 -0
- package/out/chunk-GO7FT4OD.js +1 -0
- package/out/chunk-GX5UXWT4.js +1 -0
- package/out/chunk-ITUKKCCK.js +10 -0
- package/out/chunk-IYPY47MC.js +1 -0
- package/out/chunk-JXBRWLMA.js +4 -0
- package/out/chunk-K4XJHM2T.js +1 -0
- package/out/chunk-LBD3M3J6.js +1 -0
- package/out/chunk-LVSLM7HB.js +1 -0
- package/out/chunk-LVW7WWV4.js +1 -0
- package/out/chunk-MV66NL3G.js +3 -0
- package/out/chunk-N57OWFKY.js +15 -0
- package/out/chunk-NRPC74AM.js +1 -0
- package/out/chunk-OOJM4CTU.js +1 -0
- package/out/chunk-OWSEQOL5.js +1 -0
- package/out/chunk-PKLVXUEI.js +11 -0
- package/out/chunk-PLGH63UC.js +2 -0
- package/out/chunk-PNHBZGDD.js +1 -0
- package/out/chunk-PTFYDJUP.js +1 -0
- package/out/chunk-PWFUOLZK.js +17 -0
- package/out/chunk-PXK7EU4V.js +1 -0
- package/out/chunk-QD3IBSF4.js +7 -0
- package/out/chunk-QI66YA4F.js +1 -0
- package/out/chunk-QRKFPLA4.js +80 -0
- package/out/chunk-R3NZFXVR.js +1 -0
- package/out/chunk-R5O6FAW4.js +2 -0
- package/out/chunk-RPNO56H2.js +1 -0
- package/out/chunk-SSPDMA6D.js +1 -0
- package/out/chunk-SZWPYLPC.js +1 -0
- package/out/chunk-TUII34K2.js +1 -0
- package/out/chunk-UJP4PQJA.js +1 -0
- package/out/chunk-UJSJMXEG.js +1 -0
- package/out/chunk-UR4WYMIP.js +1 -0
- package/out/chunk-VHEXSGGP.js +1 -0
- package/out/chunk-VYYUMYVW.js +9 -0
- package/out/chunk-VZPPX6MV.js +1 -0
- package/out/chunk-WCDYSIKG.js +1 -0
- package/out/chunk-XM4RLC4A.js +2 -0
- package/out/chunk-YKCRCNYZ.js +266 -0
- package/out/chunk-ZQHLECTI.js +1 -0
- package/out/client-managed-import.js +4 -0
- package/out/client-managed.js +37 -0
- package/out/client-sync.js +11 -17
- package/out/compare.js +26 -0
- package/out/dialogs.js +40 -0
- package/out/github-issue-authorized.html +3 -0
- package/out/github-issue-authorized.js +1 -0
- package/out/graph.js +19 -4
- package/out/index.html +104 -24
- package/out/prism.js +14 -10
- package/out/scan.js +2 -0
- package/out/stasis.svg +20 -0
- package/out/terminal.js +367 -39
- package/out/view.css +1 -1
- package/out/view.js +19 -147
- package/package.json +409 -64
- package/risk/actions/findings.js +161 -0
- package/risk/actions/resolve.js +287 -0
- package/risk/actions/scripts/commands.js +182 -0
- package/risk/actions/scripts/grade.js +113 -0
- package/risk/actions/scripts/packages.js +123 -0
- package/risk/actions/scripts/shell.js +169 -0
- package/risk/actions/uses.js +94 -0
- package/risk/actions/workflow.js +183 -0
- package/risk/files/characters.js +341 -0
- package/risk/files/hosts.js +206 -0
- package/risk/files/readability.js +185 -0
- package/risk/files/runs-code.js +563 -0
- package/risk/files/script.js +402 -0
- package/risk/files/source-map-link.js +43 -0
- package/risk/files/stamps.js +47 -0
- package/risk/index.d.ts +294 -0
- package/risk/index.js +12 -0
- package/risk/npm/assess.js +285 -0
- package/risk/npm/combined.js +68 -0
- package/risk/npm/compare.js +236 -0
- package/risk/npm/dependencies.js +172 -0
- package/risk/npm/diff.js +79 -0
- package/risk/npm/downloads.js +84 -0
- package/risk/npm/files.js +445 -0
- package/risk/npm/held.js +67 -0
- package/risk/npm/install-scripts.js +34 -0
- package/risk/npm/malware.js +38 -0
- package/risk/npm/manifest.js +65 -0
- package/risk/npm/new-dependency.js +60 -0
- package/risk/npm/old-version.js +108 -0
- package/risk/npm/registry.js +393 -0
- package/risk/npm/release.js +85 -0
- package/risk/npm/score.js +59 -0
- package/risk/npm/specs.js +124 -0
- package/risk/npm/tarball.js +169 -0
- package/server-common/database-config.ts +16 -0
- package/server-common/initialize.ts +18 -0
- package/server-common/npm-advisories.ts +101 -0
- package/{server → server-common}/origin.ts +5 -5
- package/server-common/reap.ts +48 -0
- package/server-common/scan-config.ts +19 -0
- package/server-common/standalone.ts +29 -0
- package/server-common/storage-crypto.ts +182 -0
- package/server-common/storage-log.ts +38 -0
- package/server-common/vercel-blob.ts +103 -0
- package/server-e2e/app.ts +487 -0
- package/{server → server-e2e}/bus-receiver.ts +2 -1
- package/{server → server-e2e}/cli.js +9 -4
- package/{server → server-e2e}/config.ts +50 -42
- package/{server → server-e2e}/db-neon.ts +2 -2
- package/{server → server-e2e}/db-revision-sql.ts +1 -1
- package/{server → server-e2e}/db-stmt.ts +2 -2
- package/{server → server-e2e}/db.ts +7 -7
- package/{server → server-e2e}/http.ts +44 -13
- package/{server → server-e2e}/hub.ts +40 -9
- package/server-e2e/index.ts +17 -0
- package/server-e2e/lifecycle.ts +95 -0
- package/{server → server-e2e}/neon-driver.ts +2 -2
- package/{server → server-e2e}/npm-proxy.ts +12 -145
- package/{server → server-e2e}/objstore/blob-vercel.ts +10 -114
- package/{server → server-e2e}/objstore/blob.ts +1 -1
- package/{server → server-e2e}/objstore/fetch-mint-guard.ts +2 -2
- package/{server → server-e2e}/objstore/handlers.ts +9 -8
- package/{server → server-e2e}/objstore/init.ts +19 -27
- package/{server → server-e2e}/objstore/reaper.ts +1 -1
- package/{server → server-e2e}/objstore/rest-deny.ts +1 -1
- package/{server → server-e2e}/objstore/rest-mint.ts +3 -3
- package/{server → server-e2e}/objstore/rest.ts +3 -3
- package/{server → server-e2e}/objstore/store-neon.ts +6 -10
- package/{server → server-e2e}/objstore/store.ts +7 -7
- package/{server → server-e2e}/objstore/tokens.ts +2 -2
- package/{server → server-e2e}/pubsub.ts +12 -9
- package/{server → server-e2e}/sign.ts +4 -4
- package/{server → server-e2e}/sse-server.ts +60 -33
- package/{server → server-e2e}/static.ts +18 -17
- package/{server → server-e2e}/sync-handlers.ts +64 -30
- package/{server → server-e2e}/ws-server.ts +20 -9
- package/server-managed/activity.ts +247 -0
- package/server-managed/agent-merges.ts +109 -0
- package/server-managed/app-agents.ts +23 -0
- package/server-managed/avatar-store.ts +13 -0
- package/server-managed/blob-store.ts +26 -0
- package/server-managed/brotli.ts +10 -0
- package/server-managed/bundle-advisories.ts +79 -0
- package/server-managed/bundle-advisory-inventory.ts +85 -0
- package/server-managed/bundle-build-diagnostics.d.ts +10 -0
- package/server-managed/bundle-build-diagnostics.js +23 -0
- package/server-managed/bundle-build-leases.ts +41 -0
- package/server-managed/bundle-build-worker.js +380 -0
- package/server-managed/bundle-build.ts +326 -0
- package/server-managed/bundle-cache.ts +261 -0
- package/server-managed/bundle-catalog.ts +29 -0
- package/server-managed/bundle-commits.ts +133 -0
- package/server-managed/bundle-dependency-reviews.ts +91 -0
- package/server-managed/bundle-store.ts +24 -0
- package/server-managed/bundle-summary-cache.ts +139 -0
- package/server-managed/bundle-validation.ts +33 -0
- package/server-managed/bundle.ts +151 -0
- package/server-managed/cache-storage.ts +20 -0
- package/server-managed/cli.js +21 -0
- package/server-managed/combined.ts +43 -0
- package/server-managed/comments.ts +138 -0
- package/server-managed/commit-coauthors.ts +105 -0
- package/server-managed/commit-lockfiles.ts +78 -0
- package/server-managed/comparison.ts +51 -0
- package/server-managed/config.ts +163 -0
- package/server-managed/content-access.ts +15 -0
- package/server-managed/crypto.ts +25 -0
- package/server-managed/db-methods.ts +1914 -0
- package/server-managed/db-neon.ts +398 -0
- package/server-managed/db-schema.ts +263 -0
- package/server-managed/db-table-names.ts +22 -0
- package/server-managed/db.ts +149 -0
- package/server-managed/dependabot-access.ts +61 -0
- package/server-managed/dependabot-alerts.ts +180 -0
- package/server-managed/dependency-review-comments.ts +143 -0
- package/server-managed/dependency-reviews.ts +369 -0
- package/server-managed/github-accounts.ts +59 -0
- package/server-managed/github-actions.ts +71 -0
- package/server-managed/github-app.ts +347 -0
- package/server-managed/github-errors.ts +92 -0
- package/server-managed/github-graphql.ts +42 -0
- package/server-managed/github-issue-links.ts +264 -0
- package/server-managed/github-issue-oauth.ts +30 -0
- package/server-managed/github-issues.ts +157 -0
- package/server-managed/github-link-oauth.ts +56 -0
- package/server-managed/github-links.ts +204 -0
- package/server-managed/github-metadata.ts +213 -0
- package/server-managed/github-oauth.ts +264 -0
- package/server-managed/github-pulls.ts +257 -0
- package/server-managed/github-requests.ts +181 -0
- package/server-managed/github-users.ts +30 -0
- package/server-managed/github-values.ts +26 -0
- package/server-managed/history-windows.ts +172 -0
- package/server-managed/http-response.ts +76 -0
- package/server-managed/http.ts +6324 -0
- package/server-managed/import-triage.ts +51 -0
- package/server-managed/index.ts +204 -0
- package/server-managed/kept-briefly.ts +37 -0
- package/server-managed/kept.ts +28 -0
- package/server-managed/link-reports.ts +149 -0
- package/server-managed/listed-activity.ts +39 -0
- package/server-managed/locked-packages.ts +234 -0
- package/server-managed/lockfile-scope.ts +58 -0
- package/server-managed/lru.ts +30 -0
- package/server-managed/managed-issues.ts +92 -0
- package/server-managed/management-catalog.ts +45 -0
- package/server-managed/management.ts +116 -0
- package/server-managed/npm-delta-worker.js +142 -0
- package/server-managed/npm-delta.ts +277 -0
- package/server-managed/npm-insights.ts +455 -0
- package/server-managed/npm-kept.ts +265 -0
- package/server-managed/npm-loads.ts +259 -0
- package/server-managed/npm-manifest.ts +117 -0
- package/server-managed/npm-packages.ts +469 -0
- package/server-managed/npm-patch-paths.ts +86 -0
- package/server-managed/npm-patch.ts +455 -0
- package/server-managed/npm-provenance.ts +127 -0
- package/server-managed/npm-risk.ts +287 -0
- package/server-managed/object-storage-disk.ts +147 -0
- package/server-managed/object-storage-vercel.ts +71 -0
- package/server-managed/object-storage.ts +82 -0
- package/server-managed/package-entry-points.ts +127 -0
- package/server-managed/pretty-copies.ts +22 -0
- package/server-managed/pretty-format.d.ts +3 -0
- package/server-managed/pretty-format.js +13 -0
- package/server-managed/pretty-print.ts +442 -0
- package/server-managed/public-workspace.ts +243 -0
- package/server-managed/pull-comment-reviews.ts +161 -0
- package/server-managed/pull-dependencies.ts +370 -0
- package/server-managed/pull-dependency-reviews.ts +407 -0
- package/server-managed/pull-reviews.ts +202 -0
- package/server-managed/queue.ts +54 -0
- package/server-managed/release-commits.ts +85 -0
- package/server-managed/rename-diff-worker.js +30 -0
- package/server-managed/rename-diff.ts +237 -0
- package/server-managed/repo-path.ts +21 -0
- package/server-managed/report-migration.ts +32 -0
- package/server-managed/report-opening.ts +77 -0
- package/server-managed/report-query.ts +10 -0
- package/server-managed/report-response.ts +16 -0
- package/server-managed/report-sources.ts +185 -0
- package/server-managed/report-store.ts +77 -0
- package/server-managed/repository-actions.ts +220 -0
- package/server-managed/repository-agents.ts +422 -0
- package/server-managed/repository-aliases.ts +119 -0
- package/server-managed/repository-browser.ts +361 -0
- package/server-managed/repository-changes.ts +280 -0
- package/server-managed/repository-code.ts +222 -0
- package/server-managed/repository-dependency-reviews.ts +182 -0
- package/server-managed/repository-discovery.ts +83 -0
- package/server-managed/repository-history.ts +428 -0
- package/server-managed/repository-issues.ts +293 -0
- package/server-managed/repository-policy.ts +27 -0
- package/server-managed/repository-pulls.ts +207 -0
- package/server-managed/repository-pulse.ts +477 -0
- package/server-managed/repository-risk-assess.ts +108 -0
- package/server-managed/repository-risk-audit.ts +78 -0
- package/server-managed/repository-risk-caches.ts +37 -0
- package/server-managed/repository-risk-read.ts +260 -0
- package/server-managed/repository-risk-stasis.ts +61 -0
- package/server-managed/repository-risk-turn.ts +97 -0
- package/server-managed/repository-risk.ts +516 -0
- package/server-managed/repository-squashes.ts +160 -0
- package/server-managed/repository-stamp.ts +41 -0
- package/server-managed/request-timing.ts +63 -0
- package/server-managed/reviewed-dependencies.ts +170 -0
- package/server-managed/revisions.ts +35 -0
- package/server-managed/scan-downloads.ts +121 -0
- package/server-managed/session.ts +132 -0
- package/server-managed/slugs.ts +38 -0
- package/server-managed/solidity-entry-points.ts +71 -0
- package/server-managed/sql-postgres.ts +34 -0
- package/server-managed/sql.ts +107 -0
- package/server-managed/stasis-config.ts +147 -0
- package/server-managed/stasis-dependencies.ts +221 -0
- package/server-managed/static.ts +28 -0
- package/server-managed/storage-command.ts +16 -0
- package/server-managed/storage-db.ts +183 -0
- package/server-managed/storage-encryption.ts +288 -0
- package/server-managed/storage-maintenance.ts +259 -0
- package/server-managed/storage-payload.ts +121 -0
- package/server-managed/storage-stores.ts +91 -0
- package/server-managed/storage.ts +82 -0
- package/server-managed/team-app-summaries.ts +56 -0
- package/server-managed/team-app.ts +156 -0
- package/server-managed/team-catalog.ts +7 -0
- package/server-managed/team-feed.ts +180 -0
- package/server-managed/team-npm-scopes.ts +103 -0
- package/server-managed/team-reports.ts +368 -0
- package/server-managed/triage-response.ts +16 -0
- package/server-managed/type-only-proof.js +161 -0
- package/server-managed/type-only-worker.js +31 -0
- package/server-managed/type-only.ts +135 -0
- package/server-managed/uploads.ts +106 -0
- package/server-managed/upstream-cache.ts +256 -0
- package/server-managed/view-as.ts +58 -0
- package/server-managed/worker-turns.ts +76 -0
- package/server-managed/workspace-shares.ts +170 -0
- package/server.ts +70 -0
- package/strip-types-loader.js +13 -10
- package/server/index.ts +0 -480
- package/server/lifecycle.ts +0 -208
- /package/{LICENSE → LICENSE-MIT} +0 -0
- /package/{server → server-e2e}/auth.ts +0 -0
- /package/{server → server-e2e}/config.example.json +0 -0
- /package/{server → server-e2e}/objstore/blob-fs.ts +0 -0
- /package/{server → server-e2e}/objstore/fs.ts +0 -0
- /package/{server → server-e2e}/objstore/sign.ts +0 -0
- /package/{server → server-e2e}/peer.ts +0 -0
- /package/{server → server-e2e}/sse-session.ts +0 -0
- /package/{server → server-e2e}/util.ts +0 -0
- /package/{server → server-e2e}/validation.ts +0 -0
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
import { DEPENDENCY_REVIEW_COLUMNS, DEPENDENCY_REVIEW_INDEXES, DEPENDENCY_REVIEW_SCHEMA } from './dependency-reviews.ts'
|
|
2
|
+
import { LINK_REPORT_SCHEMA } from './link-reports.ts'
|
|
3
|
+
import { REPOSITORY_ALIAS_SCHEMA } from './repository-aliases.ts'
|
|
4
|
+
import { TEAM_NPM_SCOPE_SCHEMA } from './team-npm-scopes.ts'
|
|
5
|
+
import { GITHUB_LINK_SCHEMA, GITHUB_LINK_USER_COLUMNS } from './github-links.ts'
|
|
6
|
+
import { REPOSITORY_DEPENDENCY_REVIEW_COLUMNS } from './repository-dependency-reviews.ts'
|
|
7
|
+
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
8
|
+
import { WebSocket } from 'ws'
|
|
9
|
+
import { type ManagedDb, type ManagedDbOptions, createManagedMethods } from './db-methods.ts'
|
|
10
|
+
import { revisionSchema } from './revisions.ts'
|
|
11
|
+
import { MANAGED_SCHEMA, REPORT_OPENING_COLUMNS, REPO_UPLOAD_INDEXES, VIEW_SESSION_INDEX } from './db-schema.ts'
|
|
12
|
+
import { STORAGE_SCHEMA } from './storage-db.ts'
|
|
13
|
+
import { GITHUB_COMMIT_SCHEMA, GITHUB_METADATA_SCHEMA, GITHUB_STATE_REASON_COLUMN } from './github-metadata.ts'
|
|
14
|
+
import { MANAGED_ISSUE_SCHEMA } from './managed-issues.ts'
|
|
15
|
+
import { BUNDLE_BUILD_LEASE_SCHEMA } from './bundle-build-leases.ts'
|
|
16
|
+
import { UPSTREAM_CACHE_SCHEMA } from './upstream-cache.ts'
|
|
17
|
+
import { TEAM_APP_SUMMARY_SCHEMA } from './team-app-summaries.ts'
|
|
18
|
+
import { COMMENT_SCHEMA } from './comments.ts'
|
|
19
|
+
import { ACTIVITY_SCHEMA, uploadAction } from './activity.ts'
|
|
20
|
+
import { type ManagedSqlDriver, scopeManagedMethods } from './sql.ts'
|
|
21
|
+
import { countStatement, timed } from './request-timing.ts'
|
|
22
|
+
import { postgresSchema, postgresSql } from './sql-postgres.ts'
|
|
23
|
+
import { managedTableRenames } from './db-table-names.ts'
|
|
24
|
+
import { WORKSPACE_SHARE_SCHEMA } from './workspace-shares.ts'
|
|
25
|
+
import { allocateMissingSlugs } from './slugs.ts'
|
|
26
|
+
|
|
27
|
+
export interface PgConnection {
|
|
28
|
+
query(sql: string, params?: unknown[]): Promise<{
|
|
29
|
+
rows: Record<string, unknown>[]; rowCount?: number | null
|
|
30
|
+
fields?: { name: string; dataTypeID: number }[]
|
|
31
|
+
}>
|
|
32
|
+
// After a failure the connection's state is unknown: discard it, never reuse it.
|
|
33
|
+
release(discard?: boolean): Promise<void>
|
|
34
|
+
}
|
|
35
|
+
export type PgConnect = () => Promise<PgConnection>
|
|
36
|
+
// Content/access mutations cooperate on this transaction-scoped lock. Reads,
|
|
37
|
+
// presence updates, and maintenance leases do not take it. Also fences migrations.
|
|
38
|
+
const LOCK = 'SELECT pg_advisory_xact_lock(1937006964, 1835101793)'
|
|
39
|
+
|
|
40
|
+
// Whether every version up to the latest is recorded, in one round trip at
|
|
41
|
+
// a cold start: a database with no versions table yet (undefined_table) has
|
|
42
|
+
// none. Outside a transaction, so the failed read aborts nothing.
|
|
43
|
+
const SCHEMA_VERSIONS = 38
|
|
44
|
+
async function currentSchema(db: PgConnection): Promise<boolean> {
|
|
45
|
+
try {
|
|
46
|
+
const { rows } = await db.query(`SELECT count(*) AS n FROM managed_schema_version WHERE version BETWEEN 1 AND ${SCHEMA_VERSIONS}`)
|
|
47
|
+
return Number(rows[0]?.['n']) === SCHEMA_VERSIONS
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if ((error as { code?: unknown })?.code === '42P01') return false
|
|
50
|
+
throw error
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Whether migration `version` is recorded, in the bootstrap's transaction.
|
|
55
|
+
async function recorded(db: PgConnection, version: number): Promise<boolean> {
|
|
56
|
+
return (await db.query(`SELECT version FROM managed_schema_version WHERE version = ${version}`)).rows.length > 0
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// An ALTER TABLE's clauses adding each of `columns` it lacks.
|
|
60
|
+
const addColumns = (columns: readonly (readonly [string, string])[]) =>
|
|
61
|
+
columns.map(([column, type]) => `ADD COLUMN IF NOT EXISTS ${column} ${type}`).join(', ')
|
|
62
|
+
|
|
63
|
+
// Migration `version`, unless it is recorded: its `statements` in order,
|
|
64
|
+
// then its record.
|
|
65
|
+
async function migration(db: PgConnection, version: number, ...statements: string[]): Promise<void> {
|
|
66
|
+
if (await recorded(db, version)) return
|
|
67
|
+
for (const statement of statements) await db.query(statement)
|
|
68
|
+
await db.query(`INSERT INTO managed_schema_version VALUES (${version})`)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function migrateGithubMetadata(db: PgConnection): Promise<void> {
|
|
72
|
+
await db.query(postgresSchema(GITHUB_METADATA_SCHEMA + MANAGED_ISSUE_SCHEMA))
|
|
73
|
+
await db.query(`ALTER TABLE managed_github_metadata ADD COLUMN IF NOT EXISTS state_reason ${GITHUB_STATE_REASON_COLUMN}`)
|
|
74
|
+
await db.query('ALTER TABLE managed_github_metadata ADD COLUMN IF NOT EXISTS attempted_at BIGINT')
|
|
75
|
+
await db.query('INSERT INTO managed_schema_version VALUES (14) ON CONFLICT DO NOTHING')
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function migrateLinkReports(db: PgConnection): Promise<void> {
|
|
79
|
+
await db.query(postgresSchema(revisionSchema(true)))
|
|
80
|
+
await db.query('INSERT INTO managed_schema_version VALUES (16) ON CONFLICT DO NOTHING')
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function migrateRepositoryAliases(db: PgConnection): Promise<void> {
|
|
84
|
+
await db.query(postgresSchema(REPOSITORY_ALIAS_SCHEMA))
|
|
85
|
+
await db.query('INSERT INTO managed_schema_version VALUES (17) ON CONFLICT DO NOTHING')
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Existing rows stay NULL (unknown): some may have been built on the server.
|
|
89
|
+
async function migrateBundleProvenance(db: PgConnection): Promise<void> {
|
|
90
|
+
if (await recorded(db, 20)) return
|
|
91
|
+
await db.query('ALTER TABLE managed_bundle ADD COLUMN IF NOT EXISTS provenance TEXT')
|
|
92
|
+
await createUploadTrigger(db, 'bundle', false)
|
|
93
|
+
await db.query('INSERT INTO managed_schema_version VALUES (20)')
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// The migrations from 12 on, in order.
|
|
97
|
+
async function migrateFrom12(db: PgConnection): Promise<void> {
|
|
98
|
+
await migration(db, 12, 'ALTER TABLE managed_selected_repo ADD COLUMN IF NOT EXISTS cached_default_branch TEXT')
|
|
99
|
+
await migration(db, 13, postgresSchema(BUNDLE_BUILD_LEASE_SCHEMA))
|
|
100
|
+
await migration(db, 15, 'ALTER TABLE managed_bundle ADD COLUMN IF NOT EXISTS visible INTEGER NOT NULL DEFAULT 1')
|
|
101
|
+
await migrateLinkReports(db)
|
|
102
|
+
await migrateRepositoryAliases(db)
|
|
103
|
+
await migration(db, 18, 'ALTER TABLE managed_team ADD COLUMN IF NOT EXISTS hidden INTEGER NOT NULL DEFAULT 0')
|
|
104
|
+
await migration(db, 19, 'ALTER TABLE managed_finding_issue ADD COLUMN IF NOT EXISTS auto_fix_url TEXT, ADD COLUMN IF NOT EXISTS auto_fix_checked_at BIGINT',
|
|
105
|
+
postgresSchema(revisionSchema(true)))
|
|
106
|
+
await migrateBundleProvenance(db)
|
|
107
|
+
await migration(db, 21, postgresSchema(UPSTREAM_CACHE_SCHEMA))
|
|
108
|
+
// Existing builds stay NULL: their conditions were never recorded.
|
|
109
|
+
await migration(db, 22, 'ALTER TABLE managed_bundle ADD COLUMN IF NOT EXISTS build_conditions TEXT')
|
|
110
|
+
// Existing sessions create their upload key on first use.
|
|
111
|
+
await migration(db, 23, 'ALTER TABLE managed_session ADD COLUMN IF NOT EXISTS upload_key TEXT')
|
|
112
|
+
await migration(db, 24, 'ALTER TABLE managed_session ADD COLUMN IF NOT EXISTS viewer_session TEXT REFERENCES managed_session(id) ON DELETE CASCADE',
|
|
113
|
+
VIEW_SESSION_INDEX)
|
|
114
|
+
await migration(db, 25, postgresSchema(GITHUB_COMMIT_SCHEMA))
|
|
115
|
+
await migration(db, 26, postgresSchema(TEAM_NPM_SCOPE_SCHEMA))
|
|
116
|
+
await migration(db, 27, 'ALTER TABLE managed_team ADD COLUMN IF NOT EXISTS dependency_review INTEGER NOT NULL DEFAULT 0',
|
|
117
|
+
postgresSchema(DEPENDENCY_REVIEW_SCHEMA))
|
|
118
|
+
// Existing names are the sign-in accounts' own: none was chosen yet.
|
|
119
|
+
await migration(db, 28, postgresSchema(GITHUB_LINK_SCHEMA), `ALTER TABLE managed_user ${addColumns(GITHUB_LINK_USER_COLUMNS)}`,
|
|
120
|
+
'UPDATE managed_user SET github_name = name')
|
|
121
|
+
await migration(db, 29, `ALTER TABLE managed_selected_repo ${addColumns(REPOSITORY_DEPENDENCY_REVIEW_COLUMNS)}`)
|
|
122
|
+
// The lockfiles a repository's dependency review holds to, its columns
|
|
123
|
+
// added since 29 added there too; and a team's published reviews, listed by
|
|
124
|
+
// it, indexed so.
|
|
125
|
+
await migration(db, 30, `ALTER TABLE managed_selected_repo ${addColumns(REPOSITORY_DEPENDENCY_REVIEW_COLUMNS)}`,
|
|
126
|
+
'CREATE INDEX IF NOT EXISTS managed_dependency_review_team_idx ON managed_dependency_review_team(team_id, review_id)')
|
|
127
|
+
await migration(db, 31, REPO_UPLOAD_INDEXES)
|
|
128
|
+
// The shasums of the tarballs a dependency review reads, none known of
|
|
129
|
+
// those written before.
|
|
130
|
+
await migration(db, 32, `ALTER TABLE managed_dependency_review ${addColumns(DEPENDENCY_REVIEW_COLUMNS)}`)
|
|
131
|
+
// The patch a dependency review is of, and where it was read, none of
|
|
132
|
+
// those written before; each author's one draft of a comparison held to its
|
|
133
|
+
// patch too.
|
|
134
|
+
await migration(db, 33, `ALTER TABLE managed_dependency_review ${addColumns(DEPENDENCY_REVIEW_COLUMNS)}`, DEPENDENCY_REVIEW_INDEXES)
|
|
135
|
+
await migration(db, 34, postgresSchema(TEAM_APP_SUMMARY_SCHEMA))
|
|
136
|
+
// The issue a saved one was closed as a duplicate of, none known of those
|
|
137
|
+
// checked before.
|
|
138
|
+
await migration(db, 35, 'ALTER TABLE managed_finding_issue ADD COLUMN IF NOT EXISTS duplicate_of_url TEXT')
|
|
139
|
+
// The patch a dependency review's base is of, none of those written
|
|
140
|
+
// before; each author's one draft of a comparison held to it too.
|
|
141
|
+
await migration(db, 36, `ALTER TABLE managed_dependency_review ${addColumns(DEPENDENCY_REVIEW_COLUMNS)}`, DEPENDENCY_REVIEW_INDEXES)
|
|
142
|
+
// Whether a report may open on Confirmed, existing ones read for it as the
|
|
143
|
+
// reports page lists them (report-opening.ts), and none switched yet.
|
|
144
|
+
await migration(db, 37, `ALTER TABLE managed_report ${addColumns(REPORT_OPENING_COLUMNS)}`)
|
|
145
|
+
// When a dependency review was last published to a team, none of those
|
|
146
|
+
// published before: a time in milliseconds, so BIGINT, as postgresSchema
|
|
147
|
+
// makes SQLite's INTEGER.
|
|
148
|
+
await migration(db, 38, postgresSchema(`ALTER TABLE managed_dependency_review ${addColumns(DEPENDENCY_REVIEW_COLUMNS)}`))
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async function initialize(db: PgConnection): Promise<void> {
|
|
152
|
+
if (await currentSchema(db)) return
|
|
153
|
+
await db.query('BEGIN')
|
|
154
|
+
try {
|
|
155
|
+
await db.query(LOCK)
|
|
156
|
+
await db.query('CREATE TABLE IF NOT EXISTS managed_schema_version (version INTEGER PRIMARY KEY)')
|
|
157
|
+
const initialized = await recorded(db, 1)
|
|
158
|
+
const prefixed = await recorded(db, 3)
|
|
159
|
+
if (initialized && !prefixed) {
|
|
160
|
+
const { rows } = await db.query("SELECT relname AS name FROM pg_class WHERE relkind IN ('r', 'p') AND pg_table_is_visible(oid)")
|
|
161
|
+
for (const [from, to] of managedTableRenames(new Set(rows.map(row => String(row['name']))))) {
|
|
162
|
+
await db.query(`ALTER TABLE ${from} RENAME TO ${to}`)
|
|
163
|
+
}
|
|
164
|
+
// PL/pgSQL function bodies retain literal table names after ALTER TABLE.
|
|
165
|
+
for (const type of ['report', 'bundle']) await createUploadTrigger(db, type, false)
|
|
166
|
+
}
|
|
167
|
+
if (!initialized) {
|
|
168
|
+
await db.query(postgresSchema(MANAGED_SCHEMA + COMMENT_SCHEMA + ACTIVITY_SCHEMA))
|
|
169
|
+
await db.query(`ALTER TABLE managed_finding_triage_event ADD COLUMN report_id TEXT, ADD COLUMN report TEXT, ADD COLUMN repo TEXT;
|
|
170
|
+
CREATE UNIQUE INDEX managed_team_slug_idx ON managed_team(slug);
|
|
171
|
+
CREATE UNIQUE INDEX managed_report_slug_idx ON managed_report(slug);
|
|
172
|
+
CREATE INDEX managed_activity_actor_at_idx ON managed_activity(actor_id, at);`)
|
|
173
|
+
for (const type of ['report', 'bundle']) await createUploadTrigger(db, type)
|
|
174
|
+
await db.query('INSERT INTO managed_schema_version VALUES (1)')
|
|
175
|
+
}
|
|
176
|
+
await migration(db, 2, 'CREATE INDEX IF NOT EXISTS managed_report_bundle_hash_idx ON managed_report(bundle_id, sha256)')
|
|
177
|
+
if (!prefixed) await db.query('INSERT INTO managed_schema_version VALUES (3)')
|
|
178
|
+
await migration(db, 4, postgresSchema(WORKSPACE_SHARE_SCHEMA))
|
|
179
|
+
await migrateGithubMetadata(db)
|
|
180
|
+
await migration(db, 5, `ALTER TABLE managed_workspace_share ADD COLUMN IF NOT EXISTS dependencies INTEGER NOT NULL DEFAULT 0,
|
|
181
|
+
ADD COLUMN IF NOT EXISTS security INTEGER NOT NULL DEFAULT 0`)
|
|
182
|
+
if (!await recorded(db, 6)) {
|
|
183
|
+
await db.query('ALTER TABLE managed_bundle ADD COLUMN IF NOT EXISTS slug TEXT')
|
|
184
|
+
const { rows } = await db.query('SELECT id, slug FROM managed_bundle ORDER BY id')
|
|
185
|
+
for (const row of allocateMissingSlugs(rows as { id: string; slug: string | null }[])) {
|
|
186
|
+
await db.query('UPDATE managed_bundle SET slug = $1 WHERE id = $2', [row.slug, row.id])
|
|
187
|
+
}
|
|
188
|
+
await db.query(`ALTER TABLE managed_bundle ALTER COLUMN slug SET NOT NULL;
|
|
189
|
+
CREATE UNIQUE INDEX IF NOT EXISTS managed_bundle_slug_idx ON managed_bundle(slug);
|
|
190
|
+
INSERT INTO managed_schema_version VALUES (6)`)
|
|
191
|
+
}
|
|
192
|
+
await migration(db, 7, "ALTER TABLE managed_bundle ADD COLUMN IF NOT EXISTS repo_directory TEXT NOT NULL DEFAULT ''")
|
|
193
|
+
await migration(db, 8, 'CREATE INDEX IF NOT EXISTS managed_report_hash_idx ON managed_report(sha256, uploaded_at, id)')
|
|
194
|
+
await migration(db, 9, postgresSchema(STORAGE_SCHEMA),
|
|
195
|
+
...['managed_report', 'managed_bundle'].map(table => `ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS data_key TEXT, ADD COLUMN IF NOT EXISTS storage_encrypted INTEGER NOT NULL DEFAULT 0`),
|
|
196
|
+
'ALTER TABLE managed_user ADD COLUMN IF NOT EXISTS gh_tokens_encrypted INTEGER NOT NULL DEFAULT 0')
|
|
197
|
+
await db.query(postgresSchema(LINK_REPORT_SCHEMA))
|
|
198
|
+
if (!await recorded(db, 10)) {
|
|
199
|
+
await db.query(postgresSchema(revisionSchema(true)) + '; INSERT INTO managed_schema_version VALUES (10)')
|
|
200
|
+
}
|
|
201
|
+
if (!await recorded(db, 11)) {
|
|
202
|
+
await db.query(postgresSchema(revisionSchema(true)) + '; INSERT INTO managed_schema_version VALUES (11)')
|
|
203
|
+
}
|
|
204
|
+
await migrateFrom12(db)
|
|
205
|
+
await db.query('COMMIT')
|
|
206
|
+
} catch (err) {
|
|
207
|
+
await db.query('ROLLBACK')
|
|
208
|
+
throw err
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async function createUploadTrigger(db: PgConnection, type: string, createTrigger = true): Promise<void> {
|
|
213
|
+
await db.query(`CREATE OR REPLACE FUNCTION managed_${type}_activity_insert() RETURNS trigger LANGUAGE plpgsql AS $$
|
|
214
|
+
BEGIN
|
|
215
|
+
INSERT INTO managed_activity (id, kind, actor, action, repo, report_id, report, at, bundle_id, actor_id)
|
|
216
|
+
VALUES ('${type}-upload:' || NEW.id, 'upload',
|
|
217
|
+
COALESCE(NEW.uploaded_by_login, (SELECT login FROM managed_user WHERE id = NEW.uploaded_by)),
|
|
218
|
+
${uploadAction(type, 'NEW')}, (SELECT full_name FROM managed_selected_repo WHERE repo_id = NEW.repo_id),
|
|
219
|
+
${type === 'report' ? 'NEW.id' : 'NULL'}, NEW.filename, NEW.uploaded_at,
|
|
220
|
+
${type === 'bundle' ? 'NEW.id' : 'NULL'}, NEW.uploaded_by);
|
|
221
|
+
RETURN NEW;
|
|
222
|
+
END $$;`)
|
|
223
|
+
if (createTrigger) {
|
|
224
|
+
await db.query(`CREATE TRIGGER managed_${type}_activity AFTER INSERT ON managed_${type}
|
|
225
|
+
FOR EACH ROW EXECUTE FUNCTION managed_${type}_activity_insert();`)
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
type RequestConnection = { connection?: PgConnection; queue: Promise<unknown>; ended: boolean }
|
|
230
|
+
// A connection whose state is unknown, discarded; a failure to release it
|
|
231
|
+
// too changes nothing.
|
|
232
|
+
const discardConnection = (connection?: PgConnection) => connection?.release(true).catch(() => {})
|
|
233
|
+
|
|
234
|
+
function requestConnections(connect: PgConnect) {
|
|
235
|
+
const requests = new AsyncLocalStorage<RequestConnection>()
|
|
236
|
+
async function withConnection<T>(work: (db: PgConnection) => Promise<T>): Promise<T> {
|
|
237
|
+
const request = requests.getStore()
|
|
238
|
+
if (!request || request.ended) {
|
|
239
|
+
const connection = await connect()
|
|
240
|
+
let result: T
|
|
241
|
+
try { result = await work(connection) }
|
|
242
|
+
catch (error) { await discardConnection(connection); throw error }
|
|
243
|
+
await connection.release()
|
|
244
|
+
return result
|
|
245
|
+
}
|
|
246
|
+
// Serialize transactions on the leased connection, never interleave BEGINs
|
|
247
|
+
// from concurrent Blob/catalog tasks. Remote Blob reads remain concurrent.
|
|
248
|
+
const result = request.queue.then(async () => {
|
|
249
|
+
const connection = request.connection ??= await connect()
|
|
250
|
+
try { return await work(connection) }
|
|
251
|
+
catch (error) {
|
|
252
|
+
delete request.connection
|
|
253
|
+
await discardConnection(connection)
|
|
254
|
+
throw error
|
|
255
|
+
}
|
|
256
|
+
})
|
|
257
|
+
request.queue = result.catch(() => {})
|
|
258
|
+
return result
|
|
259
|
+
}
|
|
260
|
+
async function withRequest<T>(work: () => Promise<T>): Promise<T> {
|
|
261
|
+
if (requests.getStore()) return work()
|
|
262
|
+
const request: RequestConnection = { queue: Promise.resolve(), ended: false }
|
|
263
|
+
let failed = false
|
|
264
|
+
try { return await requests.run(request, work) }
|
|
265
|
+
catch (error) { failed = true; throw error }
|
|
266
|
+
finally {
|
|
267
|
+
request.ended = true
|
|
268
|
+
await request.queue
|
|
269
|
+
if (failed) await discardConnection(request.connection)
|
|
270
|
+
else await request.connection?.release()
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return { withConnection, withRequest }
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Exposed for parity tests against real PostgreSQL semantics via PGlite.
|
|
277
|
+
export async function openPostgresManagedDb(leased: PgConnect, options: ManagedDbOptions = {}, reuseConnections = false): Promise<ManagedDb> {
|
|
278
|
+
// Each statement told in its request's Server-Timing (request-timing.ts).
|
|
279
|
+
const connect: PgConnect = async () => {
|
|
280
|
+
const connection = await leased()
|
|
281
|
+
return { query: (sql, params) => { countStatement(); return connection.query(sql, params) }, release: discard => connection.release(discard) }
|
|
282
|
+
}
|
|
283
|
+
const initial = await connect()
|
|
284
|
+
try { await initialize(initial) } catch (err) { await discardConnection(initial); throw err }
|
|
285
|
+
await initial.release()
|
|
286
|
+
const { withConnection, withRequest } = requestConnections(connect)
|
|
287
|
+
const context = new AsyncLocalStorage<PgConnection>()
|
|
288
|
+
let closed = false
|
|
289
|
+
const driver: ManagedSqlDriver = {
|
|
290
|
+
prepare(source) {
|
|
291
|
+
const { sql, names } = postgresSql(source)
|
|
292
|
+
async function query(args: unknown[]) {
|
|
293
|
+
const db = context.getStore()
|
|
294
|
+
if (!db) throw new Error('Managed query outside transaction')
|
|
295
|
+
const values = names.length > 0 ? names.map(name => (args[0] as Record<string, unknown>)[name])
|
|
296
|
+
: args.length === 1 && typeof args[0] === 'object' && args[0] !== null ? [] : args
|
|
297
|
+
const result = await db.query(sql, values)
|
|
298
|
+
// Postgres int8 is returned as text by node-postgres/Neon. All store
|
|
299
|
+
// numbers are JS safe integers (timestamps, IDs, sizes and sequences).
|
|
300
|
+
for (const field of result.fields ?? []) {
|
|
301
|
+
if (field.dataTypeID !== 20) continue
|
|
302
|
+
for (const row of result.rows) {
|
|
303
|
+
if (row[field.name] == null) continue
|
|
304
|
+
const value = Number(row[field.name])
|
|
305
|
+
if (!Number.isSafeInteger(value)) throw new RangeError('Managed integer exceeds safe range')
|
|
306
|
+
row[field.name] = value
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return result
|
|
310
|
+
}
|
|
311
|
+
return {
|
|
312
|
+
get: async (...args) => (await query(args)).rows[0],
|
|
313
|
+
all: async (...args) => (await query(args)).rows,
|
|
314
|
+
run: async (...args) => ({ changes: (await query(args)).rowCount ?? 0 }),
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
async scope(write, work, { lock = write, statement = false } = {}) {
|
|
318
|
+
if (closed) throw new Error('Managed database is closed')
|
|
319
|
+
let committed = false
|
|
320
|
+
try { return await withConnection(async db => {
|
|
321
|
+
if (statement) return context.run(db, work)
|
|
322
|
+
let commitAttempted = false
|
|
323
|
+
try {
|
|
324
|
+
await db.query(write ? 'BEGIN' : 'BEGIN ISOLATION LEVEL REPEATABLE READ READ ONLY')
|
|
325
|
+
if (lock) await db.query(LOCK)
|
|
326
|
+
const result = await context.run(db, work)
|
|
327
|
+
commitAttempted = true
|
|
328
|
+
await db.query('COMMIT')
|
|
329
|
+
committed = true
|
|
330
|
+
return result
|
|
331
|
+
} catch (err) {
|
|
332
|
+
await db.query('ROLLBACK').catch(() => {})
|
|
333
|
+
if (write && commitAttempted) throw new Error('Managed commit outcome is uncertain', { cause: err })
|
|
334
|
+
throw err
|
|
335
|
+
}
|
|
336
|
+
}) } catch (error) {
|
|
337
|
+
if (write && committed) throw new Error('Managed commit outcome is uncertain', { cause: error })
|
|
338
|
+
throw error
|
|
339
|
+
}
|
|
340
|
+
},
|
|
341
|
+
close() { closed = true },
|
|
342
|
+
}
|
|
343
|
+
const methods = scopeManagedMethods(createManagedMethods(driver, options), driver)
|
|
344
|
+
if (reuseConnections) methods.withRequest = withRequest
|
|
345
|
+
return methods
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// Idle connections stay open this long between leases, so a warm instance's
|
|
349
|
+
// requests and feed polls (three seconds apart) skip the TLS, WebSocket and
|
|
350
|
+
// Postgres handshake a new connection repeats.
|
|
351
|
+
const NEON_POOL_IDLE_MS = 5_000
|
|
352
|
+
|
|
353
|
+
type NeonPoolClient = {
|
|
354
|
+
query: PgConnection['query']
|
|
355
|
+
release(discard?: boolean): void
|
|
356
|
+
on(event: string, listener: (...args: unknown[]) => void): void
|
|
357
|
+
}
|
|
358
|
+
export type NeonPool = {
|
|
359
|
+
connect(): Promise<NeonPoolClient>
|
|
360
|
+
end(): Promise<void>
|
|
361
|
+
on(event: string, listener: (...args: unknown[]) => void): void
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// `attachPool` is Vercel's attachDatabasePool on serverless instances: each
|
|
365
|
+
// release keeps the invocation alive until idle connections have closed, so
|
|
366
|
+
// no socket survives a frozen instance.
|
|
367
|
+
export async function openNeonManagedDb(url: string, options: ManagedDbOptions = {}, attachPool?: (pool: NeonPool) => void): Promise<ManagedDb> {
|
|
368
|
+
// Reuse the e2e optional-driver boundary.
|
|
369
|
+
const { Pool, neonConfig } = await import('../server-e2e/neon-driver.ts') as unknown as {
|
|
370
|
+
Pool: new (config: { connectionString: string; max: number; idleTimeoutMillis: number }) => NeonPool
|
|
371
|
+
neonConfig: { webSocketConstructor: typeof WebSocket }
|
|
372
|
+
}
|
|
373
|
+
neonConfig.webSocketConstructor = WebSocket
|
|
374
|
+
// Leases stay unbounded, one per request or operation as before: a cap would
|
|
375
|
+
// stall a request that holds one while it awaits work needing another.
|
|
376
|
+
const pool = new Pool({ connectionString: url, max: Infinity, idleTimeoutMillis: NEON_POOL_IDLE_MS })
|
|
377
|
+
// The pool evicts an idle connection the server closed. Neither that nor a
|
|
378
|
+
// remote disconnect while leased may become an unhandled EventEmitter error;
|
|
379
|
+
// a leased one must instead reject its next query, and is then discarded.
|
|
380
|
+
pool.on('error', () => {})
|
|
381
|
+
attachPool?.(pool)
|
|
382
|
+
const failed = new WeakSet<NeonPoolClient>(), watched = new WeakSet<NeonPoolClient>()
|
|
383
|
+
let ending: Promise<void> | undefined
|
|
384
|
+
const end = () => ending ??= pool.end()
|
|
385
|
+
let db: ManagedDb
|
|
386
|
+
try {
|
|
387
|
+
db = await openPostgresManagedDb(async () => {
|
|
388
|
+
// A lease's wait told in its request's Server-Timing: a new connection's
|
|
389
|
+
// TLS, WebSocket and Postgres handshake, where the pool had none idle.
|
|
390
|
+
const client = await timed('conn', () => pool.connect())
|
|
391
|
+
if (!watched.has(client)) { watched.add(client); client.on('error', () => { failed.add(client) }) }
|
|
392
|
+
return { query: (sql, params) => client.query(sql, params),
|
|
393
|
+
release: discard => Promise.try(() => client.release(discard === true || failed.has(client))) }
|
|
394
|
+
}, options, true)
|
|
395
|
+
} catch (err) { await end().catch(() => {}); throw err }
|
|
396
|
+
const close = db.close
|
|
397
|
+
return { ...db, async close() { try { await close() } finally { await end() } } }
|
|
398
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { DEPENDENCY_REVIEW_SCHEMA } from './dependency-reviews.ts'
|
|
2
|
+
import { LINK_REPORT_SCHEMA } from './link-reports.ts'
|
|
3
|
+
import { REPOSITORY_ALIAS_SCHEMA } from './repository-aliases.ts'
|
|
4
|
+
import { WORKSPACE_SHARE_SCHEMA } from './workspace-shares.ts'
|
|
5
|
+
import { TEAM_NPM_SCOPE_SCHEMA } from './team-npm-scopes.ts'
|
|
6
|
+
import { GITHUB_LINK_SCHEMA } from './github-links.ts'
|
|
7
|
+
|
|
8
|
+
// Created after the column migration, which predates it on older databases.
|
|
9
|
+
export const VIEW_SESSION_INDEX = 'CREATE INDEX IF NOT EXISTS managed_session_viewer_idx ON managed_session(viewer_session);'
|
|
10
|
+
// What a team's scopes join reports and bundles on: their repository, and the
|
|
11
|
+
// directory in it. Created after the column migrations, as above.
|
|
12
|
+
export const REPO_UPLOAD_INDEXES = `CREATE INDEX IF NOT EXISTS managed_report_repo_idx ON managed_report(repo_id, repo_directory);
|
|
13
|
+
CREATE INDEX IF NOT EXISTS managed_bundle_repo_idx ON managed_bundle(repo_id, repo_directory);`
|
|
14
|
+
|
|
15
|
+
// Shared by listing, access checks, and permission aggregation. A team sees
|
|
16
|
+
// reports rooted at its path or below it. Literal substring comparison keeps
|
|
17
|
+
// separators, case, and SQL wildcard characters significant.
|
|
18
|
+
export const withinTeamPath = (path: string) => `(tr.path IS NULL OR tr.path = ''
|
|
19
|
+
OR ${path} = tr.path
|
|
20
|
+
OR substr(${path}, 1, length(tr.path) + 1) = tr.path || '/')`
|
|
21
|
+
|
|
22
|
+
// Whether a scope of a non-hidden team of `user` (a placeholder, or a column)
|
|
23
|
+
// holds the repository directory of `row`, the alias of a row with repo_id
|
|
24
|
+
// and repo_directory (withinTeamPath).
|
|
25
|
+
export const inUserTeamScope = (user: string, row: string) => `EXISTS (SELECT 1 FROM managed_team_repo tr
|
|
26
|
+
JOIN managed_team_user tu ON tu.team_id = tr.team_id
|
|
27
|
+
JOIN managed_team t ON t.id = tu.team_id AND t.hidden = 0
|
|
28
|
+
WHERE tu.user_id = ${user} AND tr.repo_id = ${row}.repo_id AND ${withinTeamPath(`${row}.repo_directory`)})`
|
|
29
|
+
|
|
30
|
+
// A report's opening (report-opening.ts), added to databases created before it.
|
|
31
|
+
export const REPORT_OPENING_COLUMNS = [['confirmed_offered', 'INTEGER'], ['confirmed_default', 'INTEGER NOT NULL DEFAULT 0']] as const
|
|
32
|
+
|
|
33
|
+
export const MANAGED_SCHEMA = `
|
|
34
|
+
CREATE TABLE IF NOT EXISTS managed_user (
|
|
35
|
+
id TEXT PRIMARY KEY,
|
|
36
|
+
github_user_id INTEGER NOT NULL UNIQUE,
|
|
37
|
+
login TEXT NOT NULL,
|
|
38
|
+
name TEXT,
|
|
39
|
+
avatar_url TEXT,
|
|
40
|
+
role TEXT NOT NULL DEFAULT 'none',
|
|
41
|
+
-- GitHub user-to-server token, persisted so the repositories page can list
|
|
42
|
+
-- the user's repos (GET /user/repos) on demand. Refresh token + expiry are
|
|
43
|
+
-- null for non-expiring tokens (GitHub App with expiring tokens disabled).
|
|
44
|
+
gh_access_token TEXT,
|
|
45
|
+
gh_refresh_token TEXT,
|
|
46
|
+
gh_token_expires_at INTEGER,
|
|
47
|
+
created_at INTEGER NOT NULL,
|
|
48
|
+
updated_at INTEGER NOT NULL,
|
|
49
|
+
-- Presence is independent of admin edits and background token refreshes.
|
|
50
|
+
-- NULL for legacy accounts until a known session authenticates them.
|
|
51
|
+
last_seen_at INTEGER
|
|
52
|
+
) STRICT;
|
|
53
|
+
|
|
54
|
+
CREATE TABLE IF NOT EXISTS managed_session (
|
|
55
|
+
id TEXT PRIMARY KEY,
|
|
56
|
+
user_id TEXT NOT NULL REFERENCES managed_user(id) ON DELETE CASCADE,
|
|
57
|
+
csrf_token TEXT NOT NULL,
|
|
58
|
+
created_at INTEGER NOT NULL,
|
|
59
|
+
expires_at INTEGER NOT NULL,
|
|
60
|
+
-- Private X25519 JWK that this session's uploads are sealed to (see
|
|
61
|
+
-- common/managed/upload-seal.ts). Created on first use.
|
|
62
|
+
upload_key TEXT,
|
|
63
|
+
-- An administrator's read-only view as user_id: the admin's own session,
|
|
64
|
+
-- which must stay valid. Ending that session ends the view.
|
|
65
|
+
viewer_session TEXT REFERENCES managed_session(id) ON DELETE CASCADE
|
|
66
|
+
) STRICT;
|
|
67
|
+
|
|
68
|
+
CREATE INDEX IF NOT EXISTS managed_session_user_idx ON managed_session(user_id);
|
|
69
|
+
CREATE INDEX IF NOT EXISTS managed_session_expires_idx ON managed_session(expires_at);
|
|
70
|
+
|
|
71
|
+
-- Repositories selected to operate on. Keyed by GitHub's numeric repo id
|
|
72
|
+
-- (stable across renames). The row carries everything needed to read the repo's
|
|
73
|
+
-- contents server-side later: installation_id mints an App installation token
|
|
74
|
+
-- (Contents: Read) for PRIVATE repos — NULL means a PUBLIC repo readable without
|
|
75
|
+
-- the App — and full_name + default_branch locate the contents. added_by is the
|
|
76
|
+
-- selector, nulled (not cascaded) if that user is removed so the selection
|
|
77
|
+
-- survives.
|
|
78
|
+
CREATE TABLE IF NOT EXISTS managed_selected_repo (
|
|
79
|
+
repo_id INTEGER PRIMARY KEY,
|
|
80
|
+
full_name TEXT NOT NULL,
|
|
81
|
+
is_private INTEGER NOT NULL,
|
|
82
|
+
installation_id INTEGER,
|
|
83
|
+
default_branch TEXT NOT NULL,
|
|
84
|
+
-- Live browser hint; independent of the default discovered at selection.
|
|
85
|
+
cached_default_branch TEXT,
|
|
86
|
+
html_url TEXT NOT NULL,
|
|
87
|
+
added_by TEXT REFERENCES managed_user(id) ON DELETE SET NULL,
|
|
88
|
+
added_at INTEGER NOT NULL,
|
|
89
|
+
updated_at INTEGER NOT NULL,
|
|
90
|
+
active INTEGER NOT NULL DEFAULT 1,
|
|
91
|
+
-- Its pull requests' dependencies reviewed (repository-dependency-reviews.ts):
|
|
92
|
+
-- as many published reviews required of each version, and the commit at
|
|
93
|
+
-- whose lockfiles' versions none is (null for none).
|
|
94
|
+
dependency_review INTEGER NOT NULL DEFAULT 0,
|
|
95
|
+
dependency_reviews_required INTEGER NOT NULL DEFAULT 1,
|
|
96
|
+
dependency_review_since TEXT
|
|
97
|
+
) STRICT;
|
|
98
|
+
|
|
99
|
+
CREATE INDEX IF NOT EXISTS selected_repo_full_name_idx ON managed_selected_repo(full_name);
|
|
100
|
+
|
|
101
|
+
-- Bundles uploaded to the server (the "Manage bundles" page). Like reports, the
|
|
102
|
+
-- bytes are stored in the clear (blob-store, keyed by this opaque uuid id) for
|
|
103
|
+
-- the server to operate on. integrity is the content hash (sha512-<base64>,
|
|
104
|
+
-- byte-identical to the client's) so re-uploading the same bytes dedupes (UNIQUE);
|
|
105
|
+
-- it is also the key a report's bundleHashes match to auto-link.
|
|
106
|
+
-- uploaded_by / repo_id are the (nullable) user + repo links, both nulled (not
|
|
107
|
+
-- cascaded) when the referenced user / selected repo goes away.
|
|
108
|
+
CREATE TABLE IF NOT EXISTS managed_bundle (
|
|
109
|
+
id TEXT PRIMARY KEY,
|
|
110
|
+
slug TEXT NOT NULL,
|
|
111
|
+
integrity TEXT NOT NULL UNIQUE,
|
|
112
|
+
filename TEXT NOT NULL,
|
|
113
|
+
kind TEXT,
|
|
114
|
+
byte_size INTEGER NOT NULL,
|
|
115
|
+
uploaded_by TEXT REFERENCES managed_user(id) ON DELETE SET NULL,
|
|
116
|
+
-- Durable snapshot of the uploader's login at upload time, so "who uploaded
|
|
117
|
+
-- this" survives the uploader being removed (when uploaded_by nulls out).
|
|
118
|
+
uploaded_by_login TEXT,
|
|
119
|
+
repo_id INTEGER REFERENCES managed_selected_repo(repo_id) ON DELETE SET NULL,
|
|
120
|
+
repo_directory TEXT NOT NULL DEFAULT '',
|
|
121
|
+
visible INTEGER NOT NULL DEFAULT 1,
|
|
122
|
+
uploaded_at INTEGER NOT NULL,
|
|
123
|
+
-- 'upload' or 'build' (generated on this server). A server build of bytes
|
|
124
|
+
-- already stored promotes the row to 'build'; NULL predates the column.
|
|
125
|
+
provenance TEXT,
|
|
126
|
+
-- JSON {preset, conditions, platforms} of a JS/TS server build; NULL otherwise.
|
|
127
|
+
build_conditions TEXT
|
|
128
|
+
) STRICT;
|
|
129
|
+
|
|
130
|
+
CREATE INDEX IF NOT EXISTS managed_bundle_uploaded_at_idx ON managed_bundle(uploaded_at);
|
|
131
|
+
|
|
132
|
+
-- Reports uploaded to the server (the "Manage reports" page). A managed server
|
|
133
|
+
-- is TRUSTED, so the bytes are stored in the clear (blob-store, keyed by this
|
|
134
|
+
-- opaque uuid id) for the server to operate on later; this row carries the
|
|
135
|
+
-- metadata + attribution. uploaded_by / repo_id are the (nullable) user + repo
|
|
136
|
+
-- links, nulled (not cascaded) when the user / selected repo goes away. bundle_id
|
|
137
|
+
-- is the (nullable) auto-resolved link to a stored bundle; bundle_integrity is
|
|
138
|
+
-- the report's declared primary bundle (from its bundleHashes), kept so a later
|
|
139
|
+
-- bundle upload of that integrity can re-link. confirmed_offered is whether
|
|
140
|
+
-- the report, alone, may be switched to open on Confirmed (Manage → Reports,
|
|
141
|
+
-- report-opening.ts): 1 where its pass leaves Confirmed rows but it is no App
|
|
142
|
+
-- view on its own, 0 where the switch would change nothing, NULL where it is
|
|
143
|
+
-- yet to be read (one uploaded before the column).
|
|
144
|
+
-- confirmed_default is that switch, as a manager set it.
|
|
145
|
+
CREATE TABLE IF NOT EXISTS managed_report (
|
|
146
|
+
id TEXT PRIMARY KEY,
|
|
147
|
+
slug TEXT NOT NULL,
|
|
148
|
+
filename TEXT NOT NULL,
|
|
149
|
+
content_type TEXT NOT NULL,
|
|
150
|
+
byte_size INTEGER NOT NULL,
|
|
151
|
+
sha256 TEXT NOT NULL,
|
|
152
|
+
uploaded_by TEXT REFERENCES managed_user(id) ON DELETE SET NULL,
|
|
153
|
+
-- Durable snapshot of the uploader's login (see managed_bundle).
|
|
154
|
+
uploaded_by_login TEXT,
|
|
155
|
+
repo_id INTEGER REFERENCES managed_selected_repo(repo_id) ON DELETE SET NULL,
|
|
156
|
+
repo_directory TEXT NOT NULL DEFAULT '',
|
|
157
|
+
repo_embedded INTEGER NOT NULL DEFAULT 0,
|
|
158
|
+
analyzer TEXT,
|
|
159
|
+
visible INTEGER NOT NULL DEFAULT 0,
|
|
160
|
+
bundle_id TEXT REFERENCES managed_bundle(id) ON DELETE SET NULL,
|
|
161
|
+
bundle_integrity TEXT,
|
|
162
|
+
uploaded_at INTEGER NOT NULL,
|
|
163
|
+
confirmed_offered INTEGER,
|
|
164
|
+
confirmed_default INTEGER NOT NULL DEFAULT 0
|
|
165
|
+
) STRICT;
|
|
166
|
+
|
|
167
|
+
CREATE INDEX IF NOT EXISTS managed_report_uploaded_at_idx ON managed_report(uploaded_at);
|
|
168
|
+
CREATE INDEX IF NOT EXISTS managed_report_hash_idx ON managed_report(sha256, uploaded_at, id);
|
|
169
|
+
CREATE INDEX IF NOT EXISTS managed_report_bundle_integrity_idx ON managed_report(bundle_integrity);
|
|
170
|
+
CREATE INDEX IF NOT EXISTS managed_report_bundle_hash_idx ON managed_report(bundle_id, sha256);
|
|
171
|
+
|
|
172
|
+
-- Per-finding triage annotations — the managed (trusted-plaintext) counterpart
|
|
173
|
+
-- of the client's localStorage triage map, keyed the same way: by finding id
|
|
174
|
+
-- alone, not by report. Reports mostly repeat one another (a re-scan of the
|
|
175
|
+
-- same code carries the same finding ids) and a finding's triage is shared by
|
|
176
|
+
-- every report that carries it; which ids a viewer may read or write is
|
|
177
|
+
-- decided per report at the endpoint, not here. The wire shape lives in
|
|
178
|
+
-- common/managed/triage.ts. Whole-entry replace, NULL columns are unset;
|
|
179
|
+
-- flagged is tri-state: NULL unset / 1 flagged / 0 an explicit un-flag
|
|
180
|
+
-- tombstone. A cleared entry keeps its row with every field NULL — a
|
|
181
|
+
-- tombstone a reader adopts as "cleared", where a missing row means "never
|
|
182
|
+
-- annotated" (so a stale client copy can't resurrect a teammate's clear).
|
|
183
|
+
-- updated_by is the last writer (nulled when that user is removed);
|
|
184
|
+
-- updated_by_login is the durable login snapshot (see managed_bundle).
|
|
185
|
+
CREATE TABLE IF NOT EXISTS managed_finding_triage (
|
|
186
|
+
finding_id TEXT PRIMARY KEY,
|
|
187
|
+
color TEXT,
|
|
188
|
+
triage TEXT,
|
|
189
|
+
comment TEXT,
|
|
190
|
+
fix TEXT,
|
|
191
|
+
flagged INTEGER,
|
|
192
|
+
updated_by TEXT REFERENCES managed_user(id) ON DELETE SET NULL,
|
|
193
|
+
updated_by_login TEXT,
|
|
194
|
+
updated_at INTEGER NOT NULL
|
|
195
|
+
) STRICT;
|
|
196
|
+
|
|
197
|
+
-- The trail behind managed_finding_triage: one row per write that CHANGED an entry,
|
|
198
|
+
-- holding the entry as written (every field NULL = a clear), who wrote it and
|
|
199
|
+
-- when. managed_finding_triage stays the current-state projection reads hit; this is
|
|
200
|
+
-- walked only for a finding's history. The wire is whole-entry replace, so a
|
|
201
|
+
-- snapshot per write is exactly what arrived and "what changed" is the diff
|
|
202
|
+
-- against the previous row for the same id, computed on read. batch_id groups
|
|
203
|
+
-- the rows of one request. seq is the rowid: a total order that breaks ties
|
|
204
|
+
-- on at. actor_id / actor_login follow the uploaded_by / uploaded_by_login
|
|
205
|
+
-- convention (live account, durable login snapshot). Everything is kept by
|
|
206
|
+
-- default — the trail is the record; an operator may bound it per finding
|
|
207
|
+
-- (TRIAGE_HISTORY_LIMIT), in which case a finding's older events are trimmed
|
|
208
|
+
-- as new ones land. An id no report carries any more is the tombstone GC's
|
|
209
|
+
-- concern.
|
|
210
|
+
CREATE TABLE IF NOT EXISTS managed_finding_triage_event (
|
|
211
|
+
seq INTEGER PRIMARY KEY,
|
|
212
|
+
finding_id TEXT NOT NULL,
|
|
213
|
+
batch_id TEXT NOT NULL,
|
|
214
|
+
color TEXT,
|
|
215
|
+
triage TEXT,
|
|
216
|
+
comment TEXT,
|
|
217
|
+
fix TEXT,
|
|
218
|
+
flagged INTEGER,
|
|
219
|
+
actor_id TEXT REFERENCES managed_user(id) ON DELETE SET NULL,
|
|
220
|
+
actor_login TEXT,
|
|
221
|
+
at INTEGER NOT NULL
|
|
222
|
+
) STRICT;
|
|
223
|
+
CREATE INDEX IF NOT EXISTS finding_triage_event_finding_idx ON managed_finding_triage_event(finding_id, seq);
|
|
224
|
+
CREATE INDEX IF NOT EXISTS finding_triage_event_actor_at_idx ON managed_finding_triage_event(actor_id, at);
|
|
225
|
+
|
|
226
|
+
-- Teams group users + repos for access scoping. Hidden teams grant no access;
|
|
227
|
+
-- the two link tables below carry the many-many relations.
|
|
228
|
+
CREATE TABLE IF NOT EXISTS managed_team (
|
|
229
|
+
id TEXT PRIMARY KEY,
|
|
230
|
+
slug TEXT NOT NULL,
|
|
231
|
+
name TEXT NOT NULL UNIQUE,
|
|
232
|
+
hidden INTEGER NOT NULL DEFAULT 0,
|
|
233
|
+
dependency_review INTEGER NOT NULL DEFAULT 0,
|
|
234
|
+
created_at INTEGER NOT NULL,
|
|
235
|
+
updated_at INTEGER NOT NULL
|
|
236
|
+
) STRICT;
|
|
237
|
+
|
|
238
|
+
-- Team <-> repo, many-many, with an OPTIONAL path (a subpath of the repo the
|
|
239
|
+
-- team is scoped to; empty path = the whole repo). Distinct paths can coexist;
|
|
240
|
+
-- adding the whole repo replaces them. CASCADE removes links with either side. repo_id
|
|
241
|
+
-- references the selected (operate-on) repos.
|
|
242
|
+
CREATE TABLE IF NOT EXISTS managed_team_repo (
|
|
243
|
+
team_id TEXT NOT NULL REFERENCES managed_team(id) ON DELETE CASCADE,
|
|
244
|
+
repo_id INTEGER NOT NULL REFERENCES managed_selected_repo(repo_id) ON DELETE CASCADE,
|
|
245
|
+
path TEXT NOT NULL DEFAULT '',
|
|
246
|
+
PRIMARY KEY (team_id, repo_id, path)
|
|
247
|
+
) STRICT;
|
|
248
|
+
|
|
249
|
+
CREATE INDEX IF NOT EXISTS team_repo_repo_idx ON managed_team_repo(repo_id);
|
|
250
|
+
|
|
251
|
+
-- Team <-> user, many-many, with per-membership visibility permissions (see
|
|
252
|
+
-- common/managed/permissions.ts) — view_dependencies / view_security, both
|
|
253
|
+
-- default 0 (off). CASCADE so the membership dies with either side.
|
|
254
|
+
CREATE TABLE IF NOT EXISTS managed_team_user (
|
|
255
|
+
team_id TEXT NOT NULL REFERENCES managed_team(id) ON DELETE CASCADE,
|
|
256
|
+
user_id TEXT NOT NULL REFERENCES managed_user(id) ON DELETE CASCADE,
|
|
257
|
+
view_dependencies INTEGER NOT NULL DEFAULT 0,
|
|
258
|
+
view_security INTEGER NOT NULL DEFAULT 0,
|
|
259
|
+
PRIMARY KEY (team_id, user_id)
|
|
260
|
+
) STRICT;
|
|
261
|
+
|
|
262
|
+
CREATE INDEX IF NOT EXISTS team_user_user_idx ON managed_team_user(user_id);
|
|
263
|
+
` + WORKSPACE_SHARE_SCHEMA + LINK_REPORT_SCHEMA + REPOSITORY_ALIAS_SCHEMA + TEAM_NPM_SCOPE_SCHEMA + DEPENDENCY_REVIEW_SCHEMA + GITHUB_LINK_SCHEMA
|