@preventive/triage 1.0.0-alpha.8 → 1.0.0-alpha.81

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.
Files changed (442) hide show
  1. package/LICENSE-APACHE +202 -0
  2. package/README.md +16 -0
  3. package/api/reap.ts +16 -78
  4. package/cli.js +6 -0
  5. package/client/dependency-paths.d.ts +3 -0
  6. package/client/dependency-paths.js +36 -0
  7. package/client/finding-link.js +305 -0
  8. package/client/linked-findings.d.ts +1 -0
  9. package/client/linked-findings.js +115 -0
  10. package/common/bundle-commit.d.ts +1 -0
  11. package/common/bundle-commit.js +4 -0
  12. package/common/bundle-compare-diff.d.ts +6 -0
  13. package/common/bundle-compare-diff.js +377 -0
  14. package/common/bundle-compare-inputs.d.ts +3 -0
  15. package/common/bundle-compare-inputs.js +141 -0
  16. package/common/bundle-compare-versions.js +172 -0
  17. package/common/bundle-comparison.d.ts +8 -0
  18. package/common/bundle-comparison.js +69 -0
  19. package/common/bundle-imports.js +20 -0
  20. package/common/bundle-metadata.d.ts +15 -0
  21. package/common/bundle-metadata.js +226 -0
  22. package/common/bundle-pkg-of.d.ts +1 -0
  23. package/common/bundle-pkg-of.js +90 -0
  24. package/common/bundle-reasons.d.ts +6 -0
  25. package/common/bundle-reasons.js +58 -0
  26. package/common/bundle-source-links.d.ts +6 -0
  27. package/common/bundle-source-links.js +216 -0
  28. package/common/bundle-sourcemap.d.ts +10 -0
  29. package/common/bundle-sourcemap.js +100 -0
  30. package/common/bundle-sources.d.ts +10 -0
  31. package/common/bundle-sources.js +374 -0
  32. package/common/bundle-stats.js +41 -0
  33. package/common/bundle-tabs.js +1 -0
  34. package/common/code-language.js +66 -0
  35. package/common/default-scan-models.ts +36 -0
  36. package/common/dependency-reviews.d.ts +18 -0
  37. package/common/dependency-reviews.js +64 -0
  38. package/common/finding-duplicates.js +63 -0
  39. package/common/finding-filters.js +313 -0
  40. package/common/finding-id.js +47 -0
  41. package/common/finding-repo.d.ts +5 -0
  42. package/common/finding-repo.js +67 -0
  43. package/common/github-issue-labels.d.ts +1 -0
  44. package/common/github-issue-labels.js +11 -0
  45. package/common/github-pr.ts +56 -0
  46. package/common/gzip.js +59 -0
  47. package/common/line-diff.d.ts +14 -0
  48. package/common/line-diff.js +181 -0
  49. package/common/linked-workspace-groups.js +63 -0
  50. package/common/managed/agent-tasks.ts +292 -0
  51. package/common/managed/comments.ts +43 -0
  52. package/common/managed/dependency-routes.js +25 -0
  53. package/common/managed/directory-packages.ts +28 -0
  54. package/common/managed/finding-detail.d.ts +5 -0
  55. package/common/managed/finding-detail.js +75 -0
  56. package/common/managed/finding-values.d.ts +2 -0
  57. package/common/managed/finding-values.js +138 -0
  58. package/common/managed/github-agents.ts +114 -0
  59. package/common/managed/github-logins.ts +49 -0
  60. package/common/managed/lite-name.d.ts +2 -0
  61. package/common/managed/lite-name.js +20 -0
  62. package/common/managed/npm-packages.d.ts +9 -0
  63. package/common/managed/npm-packages.js +63 -0
  64. package/common/managed/permissions.ts +31 -0
  65. package/common/managed/report-content.ts +72 -0
  66. package/common/managed/report-filter.ts +120 -0
  67. package/common/managed/repository-alias.ts +65 -0
  68. package/common/managed/review-view-routes.js +23 -0
  69. package/common/managed/risk-routes.js +30 -0
  70. package/common/managed/roles.ts +41 -0
  71. package/common/managed/routes.d.ts +2 -0
  72. package/common/managed/routes.js +385 -0
  73. package/common/managed/scan-models.ts +6 -0
  74. package/common/managed/stasis-config.ts +7 -0
  75. package/common/managed/team-app.d.ts +19 -0
  76. package/common/managed/team-app.js +129 -0
  77. package/common/managed/team-filters.js +26 -0
  78. package/common/managed/triage.ts +83 -0
  79. package/common/managed/upload-seal.ts +126 -0
  80. package/common/pretty-json.js +98 -0
  81. package/common/pretty-kinds.js +20 -0
  82. package/common/pretty-print.d.ts +6 -0
  83. package/common/pretty-print.js +36 -0
  84. package/common/pretty-sourcemap.js +70 -0
  85. package/common/repo-commit.d.ts +4 -0
  86. package/common/repo-commit.js +30 -0
  87. package/common/revalidation-conflicts.js +48 -0
  88. package/common/revalidation-input-groups.js +56 -0
  89. package/common/save-error-reason.ts +20 -7
  90. package/common/scan-server.ts +13 -0
  91. package/common/security-links.d.ts +5 -0
  92. package/common/security-links.js +33 -0
  93. package/common/server-info.ts +46 -0
  94. package/common/sourcemap-listing.js +78 -0
  95. package/common/sourcemap-mappings.js +136 -0
  96. package/common/sourcemap-unlist.js +85 -0
  97. package/common/stasis-files.d.ts +5 -0
  98. package/common/stasis-files.js +20 -0
  99. package/common/stasis-tgz.d.ts +6 -0
  100. package/common/stasis-tgz.js +27 -0
  101. package/common/utf8.d.ts +3 -0
  102. package/common/utf8.js +45 -0
  103. package/common/whitespace-insensitive.js +19 -0
  104. package/common/workspace-app.js +91 -0
  105. package/common/workspace-groups.js +176 -0
  106. package/out/activity.js +2 -0
  107. package/out/brotli-fallback.js +3 -3
  108. package/out/chunk-2XUEZHIP.js +28 -0
  109. package/out/chunk-55YIWY3H.js +5 -0
  110. package/out/chunk-563V5VVT.js +266 -0
  111. package/out/chunk-5AVGKFMR.js +1 -0
  112. package/out/chunk-5EAVJAD2.js +3 -0
  113. package/out/chunk-5M2X3QPK.js +6 -0
  114. package/out/chunk-5QWPKTCE.js +40 -0
  115. package/out/chunk-5UJHJWFU.js +4 -0
  116. package/out/chunk-6CCSTJWB.js +1 -0
  117. package/out/chunk-6VOB5WXX.js +2 -0
  118. package/out/chunk-6WMQVUT2.js +3 -0
  119. package/out/chunk-6Y6PZ2BU.js +9 -0
  120. package/out/chunk-74JZTGTO.js +11 -0
  121. package/out/chunk-7BKKYVWR.js +7 -0
  122. package/out/chunk-7C7DWL7I.js +1 -0
  123. package/out/chunk-7HP2VYIC.js +2 -0
  124. package/out/chunk-7YFJUT2P.js +1 -0
  125. package/out/chunk-7YO4QV5P.js +1 -0
  126. package/out/chunk-A4BBBHQU.js +1 -0
  127. package/out/chunk-B64CTMVU.js +4 -0
  128. package/out/chunk-BEKYZCPX.js +14 -0
  129. package/out/chunk-C4Z6ZBXV.js +10 -0
  130. package/out/chunk-CU3FPB3P.js +1 -0
  131. package/out/chunk-DEVAORP2.js +1 -0
  132. package/out/chunk-DOYTKRIR.js +53 -0
  133. package/out/chunk-DUASGS2O.js +8 -0
  134. package/out/chunk-EEJA7JBI.js +13 -0
  135. package/out/chunk-FSU2PLJL.js +1 -0
  136. package/out/chunk-GO7FT4OD.js +1 -0
  137. package/out/chunk-GX5UXWT4.js +1 -0
  138. package/out/chunk-H4FEC57K.js +1 -0
  139. package/out/chunk-ITUKKCCK.js +10 -0
  140. package/out/chunk-IYPY47MC.js +1 -0
  141. package/out/chunk-K4XJHM2T.js +1 -0
  142. package/out/chunk-LBD3M3J6.js +1 -0
  143. package/out/chunk-LVSLM7HB.js +1 -0
  144. package/out/chunk-LVW7WWV4.js +1 -0
  145. package/out/chunk-N57OWFKY.js +15 -0
  146. package/out/chunk-NRPC74AM.js +1 -0
  147. package/out/chunk-OAWQNDAO.js +3 -0
  148. package/out/chunk-OOJM4CTU.js +1 -0
  149. package/out/chunk-PEE47ANR.js +1 -0
  150. package/out/chunk-PKLVXUEI.js +11 -0
  151. package/out/chunk-PLGH63UC.js +2 -0
  152. package/out/chunk-PNHBZGDD.js +1 -0
  153. package/out/chunk-PTFYDJUP.js +1 -0
  154. package/out/chunk-PWFUOLZK.js +17 -0
  155. package/out/chunk-PXK7EU4V.js +1 -0
  156. package/out/chunk-QD3IBSF4.js +7 -0
  157. package/out/chunk-QI66YA4F.js +1 -0
  158. package/out/chunk-QRKFPLA4.js +80 -0
  159. package/out/chunk-R3NZFXVR.js +1 -0
  160. package/out/chunk-R5O6FAW4.js +2 -0
  161. package/out/chunk-RPNO56H2.js +1 -0
  162. package/out/chunk-SSPDMA6D.js +1 -0
  163. package/out/chunk-SZWPYLPC.js +1 -0
  164. package/out/chunk-TUII34K2.js +1 -0
  165. package/out/chunk-UJP4PQJA.js +1 -0
  166. package/out/chunk-UJSJMXEG.js +1 -0
  167. package/out/chunk-UR4WYMIP.js +1 -0
  168. package/out/chunk-VHEXSGGP.js +1 -0
  169. package/out/chunk-VYYUMYVW.js +9 -0
  170. package/out/chunk-WCDYSIKG.js +1 -0
  171. package/out/chunk-WFBVS4QI.js +1 -0
  172. package/out/chunk-XM4RLC4A.js +2 -0
  173. package/out/chunk-ZQHLECTI.js +1 -0
  174. package/out/client-managed-import.js +4 -0
  175. package/out/client-managed.js +37 -0
  176. package/out/client-sync.js +11 -17
  177. package/out/compare.js +26 -0
  178. package/out/dialogs.js +40 -0
  179. package/out/github-issue-authorized.html +3 -0
  180. package/out/github-issue-authorized.js +1 -0
  181. package/out/graph.js +19 -4
  182. package/out/index.html +104 -24
  183. package/out/prism.js +14 -10
  184. package/out/scan.js +2 -0
  185. package/out/stasis.svg +20 -0
  186. package/out/terminal.js +367 -39
  187. package/out/view.css +1 -1
  188. package/out/view.js +19 -147
  189. package/package.json +409 -64
  190. package/risk/actions/findings.js +161 -0
  191. package/risk/actions/resolve.js +287 -0
  192. package/risk/actions/scripts/commands.js +182 -0
  193. package/risk/actions/scripts/grade.js +113 -0
  194. package/risk/actions/scripts/packages.js +123 -0
  195. package/risk/actions/scripts/shell.js +169 -0
  196. package/risk/actions/uses.js +94 -0
  197. package/risk/actions/workflow.js +183 -0
  198. package/risk/files/characters.js +354 -0
  199. package/risk/files/hosts.js +206 -0
  200. package/risk/files/readability.js +185 -0
  201. package/risk/files/runs-code.js +568 -0
  202. package/risk/files/script.js +410 -0
  203. package/risk/files/source-map-link.js +43 -0
  204. package/risk/files/stamps.js +47 -0
  205. package/risk/index.d.ts +294 -0
  206. package/risk/index.js +12 -0
  207. package/risk/npm/assess.js +285 -0
  208. package/risk/npm/combined.js +68 -0
  209. package/risk/npm/compare.js +236 -0
  210. package/risk/npm/dependencies.js +172 -0
  211. package/risk/npm/diff.js +79 -0
  212. package/risk/npm/downloads.js +84 -0
  213. package/risk/npm/files.js +445 -0
  214. package/risk/npm/held.js +67 -0
  215. package/risk/npm/install-scripts.js +34 -0
  216. package/risk/npm/malware.js +38 -0
  217. package/risk/npm/manifest.js +65 -0
  218. package/risk/npm/new-dependency.js +60 -0
  219. package/risk/npm/old-version.js +108 -0
  220. package/risk/npm/registry.js +393 -0
  221. package/risk/npm/release.js +85 -0
  222. package/risk/npm/score.js +59 -0
  223. package/risk/npm/specs.js +124 -0
  224. package/risk/npm/tarball.js +169 -0
  225. package/server-common/database-config.ts +16 -0
  226. package/server-common/initialize.ts +18 -0
  227. package/server-common/npm-advisories.ts +101 -0
  228. package/{server → server-common}/origin.ts +5 -5
  229. package/server-common/reap.ts +48 -0
  230. package/server-common/scan-config.ts +19 -0
  231. package/server-common/standalone.ts +29 -0
  232. package/server-common/storage-crypto.ts +182 -0
  233. package/server-common/storage-log.ts +38 -0
  234. package/server-common/vercel-blob.ts +103 -0
  235. package/server-e2e/app.ts +487 -0
  236. package/{server → server-e2e}/bus-receiver.ts +2 -1
  237. package/{server → server-e2e}/cli.js +9 -4
  238. package/{server → server-e2e}/config.ts +50 -42
  239. package/{server → server-e2e}/db-neon.ts +2 -2
  240. package/{server → server-e2e}/db-revision-sql.ts +1 -1
  241. package/{server → server-e2e}/db-stmt.ts +2 -2
  242. package/{server → server-e2e}/db.ts +7 -7
  243. package/{server → server-e2e}/http.ts +44 -13
  244. package/{server → server-e2e}/hub.ts +40 -9
  245. package/server-e2e/index.ts +17 -0
  246. package/server-e2e/lifecycle.ts +95 -0
  247. package/{server → server-e2e}/neon-driver.ts +2 -2
  248. package/{server → server-e2e}/npm-proxy.ts +12 -145
  249. package/{server → server-e2e}/objstore/blob-vercel.ts +10 -114
  250. package/{server → server-e2e}/objstore/blob.ts +1 -1
  251. package/{server → server-e2e}/objstore/fetch-mint-guard.ts +2 -2
  252. package/{server → server-e2e}/objstore/handlers.ts +9 -8
  253. package/{server → server-e2e}/objstore/init.ts +19 -27
  254. package/{server → server-e2e}/objstore/reaper.ts +1 -1
  255. package/{server → server-e2e}/objstore/rest-deny.ts +1 -1
  256. package/{server → server-e2e}/objstore/rest-mint.ts +3 -3
  257. package/{server → server-e2e}/objstore/rest.ts +3 -3
  258. package/{server → server-e2e}/objstore/store-neon.ts +6 -10
  259. package/{server → server-e2e}/objstore/store.ts +7 -7
  260. package/{server → server-e2e}/objstore/tokens.ts +2 -2
  261. package/{server → server-e2e}/pubsub.ts +12 -9
  262. package/{server → server-e2e}/sign.ts +4 -4
  263. package/{server → server-e2e}/sse-server.ts +60 -33
  264. package/{server → server-e2e}/static.ts +18 -17
  265. package/{server → server-e2e}/sync-handlers.ts +64 -30
  266. package/{server → server-e2e}/ws-server.ts +20 -9
  267. package/server-managed/activity.ts +269 -0
  268. package/server-managed/agent-merges.ts +109 -0
  269. package/server-managed/app-agents.ts +23 -0
  270. package/server-managed/avatar-store.ts +13 -0
  271. package/server-managed/blob-store.ts +26 -0
  272. package/server-managed/brotli.ts +10 -0
  273. package/server-managed/bundle-advisories.ts +79 -0
  274. package/server-managed/bundle-advisory-inventory.ts +85 -0
  275. package/server-managed/bundle-build-diagnostics.d.ts +10 -0
  276. package/server-managed/bundle-build-diagnostics.js +23 -0
  277. package/server-managed/bundle-build-leases.ts +41 -0
  278. package/server-managed/bundle-build-worker.js +380 -0
  279. package/server-managed/bundle-build.ts +326 -0
  280. package/server-managed/bundle-cache.ts +261 -0
  281. package/server-managed/bundle-catalog.ts +29 -0
  282. package/server-managed/bundle-commits.ts +133 -0
  283. package/server-managed/bundle-dependency-reviews.ts +91 -0
  284. package/server-managed/bundle-store.ts +24 -0
  285. package/server-managed/bundle-summary-cache.ts +139 -0
  286. package/server-managed/bundle-validation.ts +33 -0
  287. package/server-managed/bundle.ts +151 -0
  288. package/server-managed/cache-storage.ts +20 -0
  289. package/server-managed/cli.js +21 -0
  290. package/server-managed/combined.ts +43 -0
  291. package/server-managed/comments.ts +138 -0
  292. package/server-managed/commit-coauthors.ts +105 -0
  293. package/server-managed/commit-lockfiles.ts +78 -0
  294. package/server-managed/comparison.ts +51 -0
  295. package/server-managed/config.ts +163 -0
  296. package/server-managed/content-access.ts +15 -0
  297. package/server-managed/crypto.ts +25 -0
  298. package/server-managed/db-methods.ts +1915 -0
  299. package/server-managed/db-neon.ts +398 -0
  300. package/server-managed/db-schema.ts +263 -0
  301. package/server-managed/db-table-names.ts +22 -0
  302. package/server-managed/db.ts +149 -0
  303. package/server-managed/dependabot-access.ts +61 -0
  304. package/server-managed/dependabot-alerts.ts +180 -0
  305. package/server-managed/dependency-review-comments.ts +158 -0
  306. package/server-managed/dependency-reviews.ts +369 -0
  307. package/server-managed/github-accounts.ts +59 -0
  308. package/server-managed/github-actions.ts +71 -0
  309. package/server-managed/github-app.ts +347 -0
  310. package/server-managed/github-errors.ts +92 -0
  311. package/server-managed/github-graphql.ts +42 -0
  312. package/server-managed/github-issue-links.ts +264 -0
  313. package/server-managed/github-issue-oauth.ts +30 -0
  314. package/server-managed/github-issues.ts +157 -0
  315. package/server-managed/github-link-oauth.ts +56 -0
  316. package/server-managed/github-links.ts +204 -0
  317. package/server-managed/github-metadata.ts +213 -0
  318. package/server-managed/github-oauth.ts +264 -0
  319. package/server-managed/github-pulls.ts +257 -0
  320. package/server-managed/github-requests.ts +181 -0
  321. package/server-managed/github-users.ts +30 -0
  322. package/server-managed/github-values.ts +26 -0
  323. package/server-managed/history-windows.ts +172 -0
  324. package/server-managed/http-response.ts +76 -0
  325. package/server-managed/http.ts +6327 -0
  326. package/server-managed/import-triage.ts +51 -0
  327. package/server-managed/index.ts +204 -0
  328. package/server-managed/kept-briefly.ts +37 -0
  329. package/server-managed/kept.ts +28 -0
  330. package/server-managed/link-reports.ts +149 -0
  331. package/server-managed/listed-activity.ts +39 -0
  332. package/server-managed/locked-packages.ts +234 -0
  333. package/server-managed/lockfile-scope.ts +58 -0
  334. package/server-managed/lru.ts +30 -0
  335. package/server-managed/managed-issues.ts +92 -0
  336. package/server-managed/management-catalog.ts +45 -0
  337. package/server-managed/management.ts +116 -0
  338. package/server-managed/npm-delta-worker.js +142 -0
  339. package/server-managed/npm-delta.ts +277 -0
  340. package/server-managed/npm-insights.ts +455 -0
  341. package/server-managed/npm-kept.ts +265 -0
  342. package/server-managed/npm-loads.ts +259 -0
  343. package/server-managed/npm-manifest.ts +117 -0
  344. package/server-managed/npm-packages.ts +469 -0
  345. package/server-managed/npm-patch-paths.ts +86 -0
  346. package/server-managed/npm-patch.ts +455 -0
  347. package/server-managed/npm-provenance.ts +127 -0
  348. package/server-managed/npm-risk.ts +287 -0
  349. package/server-managed/object-storage-disk.ts +147 -0
  350. package/server-managed/object-storage-vercel.ts +71 -0
  351. package/server-managed/object-storage.ts +82 -0
  352. package/server-managed/package-entry-points.ts +127 -0
  353. package/server-managed/pretty-copies.ts +22 -0
  354. package/server-managed/pretty-format.d.ts +3 -0
  355. package/server-managed/pretty-format.js +13 -0
  356. package/server-managed/pretty-print.ts +442 -0
  357. package/server-managed/public-workspace.ts +243 -0
  358. package/server-managed/pull-comment-reviews.ts +161 -0
  359. package/server-managed/pull-dependencies.ts +370 -0
  360. package/server-managed/pull-dependency-reviews.ts +407 -0
  361. package/server-managed/pull-reviews.ts +202 -0
  362. package/server-managed/queue.ts +54 -0
  363. package/server-managed/release-commits.ts +85 -0
  364. package/server-managed/rename-diff-worker.js +30 -0
  365. package/server-managed/rename-diff.ts +237 -0
  366. package/server-managed/repo-path.ts +21 -0
  367. package/server-managed/report-migration.ts +32 -0
  368. package/server-managed/report-opening.ts +77 -0
  369. package/server-managed/report-query.ts +10 -0
  370. package/server-managed/report-response.ts +16 -0
  371. package/server-managed/report-sources.ts +185 -0
  372. package/server-managed/report-store.ts +77 -0
  373. package/server-managed/repository-actions.ts +220 -0
  374. package/server-managed/repository-agents.ts +422 -0
  375. package/server-managed/repository-aliases.ts +119 -0
  376. package/server-managed/repository-browser.ts +361 -0
  377. package/server-managed/repository-changes.ts +280 -0
  378. package/server-managed/repository-code.ts +222 -0
  379. package/server-managed/repository-dependency-reviews.ts +182 -0
  380. package/server-managed/repository-discovery.ts +83 -0
  381. package/server-managed/repository-history.ts +428 -0
  382. package/server-managed/repository-issues.ts +293 -0
  383. package/server-managed/repository-policy.ts +27 -0
  384. package/server-managed/repository-pulls.ts +207 -0
  385. package/server-managed/repository-pulse.ts +477 -0
  386. package/server-managed/repository-risk-assess.ts +108 -0
  387. package/server-managed/repository-risk-audit.ts +78 -0
  388. package/server-managed/repository-risk-caches.ts +37 -0
  389. package/server-managed/repository-risk-read.ts +260 -0
  390. package/server-managed/repository-risk-stasis.ts +61 -0
  391. package/server-managed/repository-risk-turn.ts +97 -0
  392. package/server-managed/repository-risk.ts +516 -0
  393. package/server-managed/repository-squashes.ts +160 -0
  394. package/server-managed/repository-stamp.ts +41 -0
  395. package/server-managed/request-timing.ts +63 -0
  396. package/server-managed/reviewed-dependencies.ts +170 -0
  397. package/server-managed/revisions.ts +35 -0
  398. package/server-managed/scan-downloads.ts +121 -0
  399. package/server-managed/session.ts +132 -0
  400. package/server-managed/slugs.ts +38 -0
  401. package/server-managed/solidity-entry-points.ts +71 -0
  402. package/server-managed/sql-postgres.ts +34 -0
  403. package/server-managed/sql.ts +107 -0
  404. package/server-managed/stasis-config.ts +147 -0
  405. package/server-managed/stasis-dependencies.ts +221 -0
  406. package/server-managed/static.ts +28 -0
  407. package/server-managed/storage-command.ts +16 -0
  408. package/server-managed/storage-db.ts +183 -0
  409. package/server-managed/storage-encryption.ts +288 -0
  410. package/server-managed/storage-maintenance.ts +259 -0
  411. package/server-managed/storage-payload.ts +121 -0
  412. package/server-managed/storage-stores.ts +91 -0
  413. package/server-managed/storage.ts +82 -0
  414. package/server-managed/team-app-summaries.ts +56 -0
  415. package/server-managed/team-app.ts +156 -0
  416. package/server-managed/team-catalog.ts +7 -0
  417. package/server-managed/team-feed.ts +180 -0
  418. package/server-managed/team-npm-scopes.ts +103 -0
  419. package/server-managed/team-reports.ts +368 -0
  420. package/server-managed/triage-response.ts +16 -0
  421. package/server-managed/type-only-proof.js +161 -0
  422. package/server-managed/type-only-worker.js +31 -0
  423. package/server-managed/type-only.ts +135 -0
  424. package/server-managed/uploads.ts +106 -0
  425. package/server-managed/upstream-cache.ts +256 -0
  426. package/server-managed/view-as.ts +58 -0
  427. package/server-managed/worker-turns.ts +76 -0
  428. package/server-managed/workspace-shares.ts +170 -0
  429. package/server.ts +70 -0
  430. package/strip-types-loader.js +13 -10
  431. package/server/index.ts +0 -480
  432. package/server/lifecycle.ts +0 -208
  433. /package/{LICENSE → LICENSE-MIT} +0 -0
  434. /package/{server → server-e2e}/auth.ts +0 -0
  435. /package/{server → server-e2e}/config.example.json +0 -0
  436. /package/{server → server-e2e}/objstore/blob-fs.ts +0 -0
  437. /package/{server → server-e2e}/objstore/fs.ts +0 -0
  438. /package/{server → server-e2e}/objstore/sign.ts +0 -0
  439. /package/{server → server-e2e}/peer.ts +0 -0
  440. /package/{server → server-e2e}/sse-session.ts +0 -0
  441. /package/{server → server-e2e}/util.ts +0 -0
  442. /package/{server → server-e2e}/validation.ts +0 -0
@@ -0,0 +1,377 @@
1
+ // Shared bundle comparison — no Lit, no DOM, no `state`. Given two
2
+ // `Map<path, content>` file maps (the shape `bundleFilesAsMap` returns
3
+ // for either a sourcemap or a stasis bundle: every file the terminal
4
+ // mounts, source or resource, with no directory captures) plus a
5
+ // `pkgOf(path)` bucketing function, it computes a structural diff:
6
+ // which files exist only in one side, which exist in both but changed,
7
+ // per-package size deltas, and the roll-up totals.
8
+ //
9
+ // Kept free of Lit, the DOM and the OPFS parse pipeline on purpose, so
10
+ // `<bundle-compare>` (the Compare slide in the bundles view) and its
11
+ // unit test can both consume the same logic — the test exercises this
12
+ // module directly. Its imports are the file sizer the Overview uses and
13
+ // @preventive/compare's renames and layout, all pure. The component is a
14
+ // thin rendering shell around `computeBundleDiff`.
15
+ //
16
+ // `base` is the currently-open bundle (the tab you're viewing);
17
+ // `other` is the bundle picked to compare against. The result names
18
+ // the two sides `onlyBase` / `onlyOther` rather than added / removed
19
+ // so the UI can label them with each bundle's actual name — "added"
20
+ // is ambiguous without knowing which side is newer.
21
+
22
+ import { compareTrees, treeLayout } from '@preventive/compare'
23
+ import { bundleFileByteLength } from './bundle-sources.js'
24
+ import { resolutionKey } from './bundle-compare-inputs.js'
25
+
26
+ // Resolutions compare independently from file bytes: identical files can be
27
+ // wired together differently. Inputs are keyed by importer, specifier,
28
+ // conditions (including import attributes), and platform. Resolutions whose
29
+ // targets changed are reported (`changed`, repointed); one recorded on a side
30
+ // alone (`onlyBase`, `onlyOther`) only where its importer holds the same
31
+ // contents on both sides (`identical`, of its path as the other bundle lays
32
+ // it out), as a file whose code changed gains and drops imports with it.
33
+ // Each row names its target on either side, null on the side without one.
34
+ // `renames` (base path → other path, see renamesOf) names base files as
35
+ // the other bundle does: a renamed importer's resolutions pair with its new
36
+ // path's, reported under it, and a target renamed is the same target.
37
+ // `basePaths` and `root` (computeBundleDiff's `files`) name the rest where
38
+ // the bundles' roots differ, a base target shown as the other bundle would
39
+ // lay it out; a path no file has (an importer the bundle didn't capture, a
40
+ // builtin) may read either as it is or through the root.
41
+ export function computeResolutionDiff(base, other, renames = new Map(), basePaths = new Map(), root = null, identical = () => false) {
42
+ const names = path => {
43
+ const known = renames.get(path) ?? basePaths.get(path)
44
+ return known === undefined ? [...new Set([path, through(root, path) ?? path])] : [known]
45
+ }
46
+ const changed = [], onlyBase = [], onlyOther = []
47
+ const paired = new Set()
48
+ for (const before of base.values()) {
49
+ const after = names(before.parent).map(parent => other.get(resolutionKey(parent, before.specifier, before.conditions, before.platform))).find(Boolean)
50
+ const baseTarget = basePaths.get(before.target) ?? before.target
51
+ if (after) {
52
+ paired.add(after.key)
53
+ if (!names(before.target).includes(after.target)) {
54
+ const { target: otherTarget, ...identity } = after
55
+ changed.push({ ...identity, baseTarget, otherTarget })
56
+ }
57
+ continue
58
+ }
59
+ const parent = names(before.parent).find(identical)
60
+ if (parent === undefined) continue
61
+ const { specifier, conditions, platform } = before
62
+ onlyBase.push({ key: resolutionKey(parent, specifier, conditions, platform), parent, specifier, conditions, platform, baseTarget, otherTarget: null })
63
+ }
64
+ for (const after of other.values()) {
65
+ if (paired.has(after.key) || !identical(after.parent)) continue
66
+ const { target: otherTarget, ...identity } = after
67
+ onlyOther.push({ ...identity, baseTarget: null, otherTarget })
68
+ }
69
+ for (const rows of [changed, onlyBase, onlyOther]) rows.sort((a, b) => a.key.localeCompare(b.key))
70
+ return { changed, onlyBase, onlyOther, totalChanges: changed.length + onlyBase.length + onlyOther.length }
71
+ }
72
+
73
+ // A file's size, by the measure the Overview and Treemap use: text by the
74
+ // UTF-8 it encodes to, a base64 resource by the bytes it decodes to. A
75
+ // file with no size to give (a base64 spelling that does not decode)
76
+ // counts as zero bytes, but is still compared.
77
+ function byteLen(content) {
78
+ return bundleFileByteLength(content) ?? 0
79
+ }
80
+
81
+ // Whether two sides hold the same file. Text compares as text; a base64
82
+ // resource arrives as a fresh `{ format: 'base64', data }` on each side,
83
+ // so it compares by its spelling — identity would call every image
84
+ // changed. A file that is text on one side and base64 on the other has
85
+ // changed. An npm package's binary file compares by its digest.
86
+ function sameContent(a, b) {
87
+ return a === b || (a?.format === 'base64' && b?.format === 'base64' && a.data === b.data)
88
+ || (a?.format === 'digest' && b?.format === 'digest' && a.digest === b.digest)
89
+ }
90
+
91
+ // What a stasis bundle records of a file beside its bytes: the format it
92
+ // loads it in (a resource is carried as data, the rest run as code), whether
93
+ // it carries an execute bit, and whether the bundle starts from it; of an npm
94
+ // version's file (fileRowDetails), its execute bit alone. A function of the
95
+ // file's path; null for another kind of bundle, which records none of it.
96
+ export function bundleFileMeta(details) {
97
+ if (details?.npmExecutable instanceof Set) return path => ({ executable: details.npmExecutable.has(path) })
98
+ if (details?.kind !== 'stasis' || !details.bundle) return null
99
+ const { formats, executable, entries } = details.bundle
100
+ return path => ({ format: formats?.get(path), executable: executable?.has(path) ?? false, entry: entries?.has(path) ?? false })
101
+ }
102
+
103
+ // How a file's record changed from one stasis bundle to the other, as
104
+ // `{ field, from, to }` (bundleFileMeta's fields): none where either side
105
+ // records nothing. A format left unsaid is one too: stasis runs such a
106
+ // file as code, so a resource whose format is dropped runs.
107
+ function metaChanges(before, after) {
108
+ if (!before || !after) return []
109
+ return ['format', 'executable', 'entry'].filter(field => before[field] !== after[field]).map(field => ({ field, from: before[field], to: after[field] }))
110
+ }
111
+
112
+ // Comparator: largest absolute delta first, then path/label ascending
113
+ // so equal-magnitude rows stay stably ordered. Used for the changed
114
+ // file + package lists, where the biggest mover is the most
115
+ // interesting row.
116
+ function byAbsDeltaThenKey(key) {
117
+ return (a, b) => {
118
+ const d = Math.abs(b.delta) - Math.abs(a.delta)
119
+ // `d || …` falls through to the tiebreak only when the magnitudes
120
+ // match (d === 0); a non-zero d is returned as-is.
121
+ return d || a[key].localeCompare(b[key])
122
+ }
123
+ }
124
+
125
+ // Largest byte size first, then key ascending — for the only-in-one-
126
+ // side lists, where there's no delta to rank by.
127
+ function byBytesThenKey(key) {
128
+ return (a, b) => {
129
+ const d = b.bytes - a.bytes
130
+ return d || a[key].localeCompare(b[key])
131
+ }
132
+ }
133
+
134
+ // A file's content as compareTrees reads it to find renames, each kind tagged
135
+ // apart: text as it is (a lone surrogate, which no UTF-8 holds, as U+FFFD); a
136
+ // resource by its spelling or its digest; and one with none, by its place in
137
+ // its list alone, so that only its path pairs it.
138
+ function treeData(content, at) {
139
+ if (typeof content === 'string') return `\0text\0${content.toWellFormed()}`
140
+ if (content?.format === 'base64') return `\0base64\0${content.data}`
141
+ return content?.format === 'digest' ? `\0digest\0${content.digest}` : `\0none\0${at}`
142
+ }
143
+
144
+ // git's diff.renameLimit for a package's renames: past this many removed files
145
+ // by added ones, squared, no pair is scored, as that would hold the page for
146
+ // seconds, and only identical content and paths pair them.
147
+ const RENAME_LIMIT = 250
148
+
149
+ // The files of `onlyBase` renamed to one of `onlyOther`, both by path as the
150
+ // other bundle lays them out, within a package: `Map<base path, other path>`,
151
+ // as @preventive/compare's compareTrees finds them, by content as git diff -M
152
+ // does and where their paths say so. Whether a renamed file changed is
153
+ // sameContent's to say, not this reading's. A path no UTF-8 holds is left out.
154
+ function renamesOf(onlyBase, onlyOther, base, other, pkgOf) {
155
+ const entries = (rows, files, side) => rows.filter(({ path }) => path !== '' && path.isWellFormed())
156
+ .map(({ path }, at) => ({ name: path, data: treeData(files.get(path), `${side}${at}`) }))
157
+ const options = { paths: 'keys', renameGroup: pkgOf, renameLimit: RENAME_LIMIT, lines: false }
158
+ const changes = compareTrees(entries(onlyBase, base, 'a'), entries(onlyOther, other, 'b'), options)
159
+ return new Map(changes.filter(({ status }) => status === 'renamed').map(change => [change.old.path, change.new.path]))
160
+ }
161
+
162
+ // A base path through `root` as treeLayout reads it, or null for one outside
163
+ // a base root.
164
+ function through(root, path) {
165
+ if (!root) return path
166
+ if (root.base === '') return `${root.other}${path}`
167
+ return path.startsWith(root.base) ? path.slice(root.base.length) : null
168
+ }
169
+
170
+ // Per-package accumulator factory. Tracks each side's byte total plus
171
+ // per-bucket file counts so a package is flagged `changed` whenever
172
+ // ANY of its files moved — not only when the byte total happens to
173
+ // differ (two versions can shuffle content while landing on the same
174
+ // size).
175
+ function emptyPkgAcc() {
176
+ return {
177
+ baseBytes: 0,
178
+ otherBytes: 0,
179
+ onlyBaseFiles: 0,
180
+ onlyOtherFiles: 0,
181
+ changedFiles: 0,
182
+ }
183
+ }
184
+
185
+ // Compare two bundle source maps. Returns:
186
+ // {
187
+ // totals: { baseFiles, baseBytes, otherFiles, otherBytes,
188
+ // onlyBaseFiles, onlyBaseBytes, onlyOtherFiles,
189
+ // onlyOtherBytes, changedFiles, changedDelta,
190
+ // unchangedFiles, fileDelta, byteDelta, identical },
191
+ // files: {
192
+ // onlyBase: [{ path, bytes }],
193
+ // onlyOther: [{ path, bytes }],
194
+ // changed: [{ path, baseBytes, otherBytes, delta, basePath?, modified?, meta? }],
195
+ // },
196
+ // packages: {
197
+ // onlyBase: [{ pkg, bytes }],
198
+ // onlyOther: [{ pkg, bytes }],
199
+ // changed: [{ pkg, baseBytes, otherBytes, delta }],
200
+ // },
201
+ // }
202
+ //
203
+ // `delta` is always `other − base` (positive = the compared bundle is
204
+ // larger). A file renamed (see renamesOf) is changed, not
205
+ // removed and added: its row's `path` is the other side's, `renamedFrom`
206
+ // the base's, `modified` whether its contents changed too, and it counts in
207
+ // `renamedFiles` as well, its contents moved or not.
208
+ // Where one bundle's files sit under a directory of the other's (`root`, see
209
+ // treeLayout), the base's are compared as the other lays them out: a row's
210
+ // `path` (and `renamedFrom`) reads that way, and `basePath` names the file
211
+ // in the base bundle wherever that differs from `path`. `files.basePaths`
212
+ // maps every base file to how it reads. `layout` (treeLayout) may come
213
+ // from the caller, to key `pkgOf` by the same paths: it is asked of files
214
+ // as the other bundle lays them out.
215
+ // `meta`, each side's bundleFileMeta where it has one, compares what two
216
+ // stasis bundles record of a file beside its bytes: a row whose record
217
+ // changed carries how (`meta`, metaChanges), and a file whose record alone
218
+ // changed is changed too, `modified: false`, its bytes the same.
219
+ // `identical` is true when the two bundles carry the same files with
220
+ // byte-identical content, resources included, each recorded alike.
221
+ export function computeBundleDiff(base, other, pkgOf, layout = treeLayout(base.keys(), other.keys()), meta = []) {
222
+ const { root, paths: basePaths } = layout
223
+ // The base's files as the other lays them out, and back.
224
+ const baseFile = new Map([...basePaths].map(([from, to]) => [to, from]))
225
+ base = new Map([...base].map(([path, content]) => [basePaths.get(path), content]))
226
+ const atBase = path => baseFile.get(path) === path ? {} : { basePath: baseFile.get(path) }
227
+ // How a file's record changed, by its base path and its path, as a row's fields.
228
+ const recorded = (from, to) => {
229
+ const changes = metaChanges(meta[0]?.(from), meta[1]?.(to))
230
+ return changes.length > 0 ? { meta: changes } : {}
231
+ }
232
+ const onlyBase = []
233
+ const onlyOther = []
234
+ const changed = []
235
+ let baseBytes = 0
236
+ let otherBytes = 0
237
+ let onlyBaseBytes = 0
238
+ let onlyOtherBytes = 0
239
+ let changedDelta = 0
240
+ let unchangedFiles = 0
241
+ const pkgs = new Map()
242
+ const pkgAcc = (path) => {
243
+ const key = pkgOf(path)
244
+ let acc = pkgs.get(key)
245
+ if (!acc) { acc = emptyPkgAcc(); pkgs.set(key, acc) }
246
+ return acc
247
+ }
248
+
249
+ const allPaths = new Set([...base.keys(), ...other.keys()])
250
+ for (const path of allPaths) {
251
+ const inBase = base.has(path)
252
+ const inOther = other.has(path)
253
+ const acc = pkgAcc(path)
254
+ if (inBase && inOther) {
255
+ const bC = base.get(path)
256
+ const oC = other.get(path)
257
+ const same = sameContent(bC, oC)
258
+ const record = recorded(baseFile.get(path), path)
259
+ const bB = byteLen(bC)
260
+ // Identical content shares the byte count, so only measure the
261
+ // other side when the files actually differ.
262
+ const oB = same ? bB : byteLen(oC)
263
+ baseBytes += bB
264
+ otherBytes += oB
265
+ acc.baseBytes += bB
266
+ acc.otherBytes += oB
267
+ if (same && !record.meta) {
268
+ unchangedFiles++
269
+ } else {
270
+ const delta = oB - bB
271
+ changed.push({ path, ...atBase(path), baseBytes: bB, otherBytes: oB, delta, ...record, ...same ? { modified: false } : {} })
272
+ changedDelta += delta
273
+ acc.changedFiles++
274
+ }
275
+ } else if (inBase) {
276
+ const bB = byteLen(base.get(path))
277
+ baseBytes += bB
278
+ onlyBaseBytes += bB
279
+ acc.baseBytes += bB
280
+ acc.onlyBaseFiles++
281
+ onlyBase.push({ path, ...atBase(path), bytes: bB })
282
+ } else {
283
+ const oB = byteLen(other.get(path))
284
+ otherBytes += oB
285
+ onlyOtherBytes += oB
286
+ acc.otherBytes += oB
287
+ acc.onlyOtherFiles++
288
+ onlyOther.push({ path, bytes: oB })
289
+ }
290
+ }
291
+
292
+ const renames = renamesOf(onlyBase, onlyOther, base, other, pkgOf)
293
+ if (renames.size > 0) {
294
+ const renamedTo = new Set(renames.values())
295
+ for (const [from, to] of renames) {
296
+ const bC = base.get(from), oC = other.get(to)
297
+ const same = sameContent(bC, oC)
298
+ const bB = byteLen(bC), oB = same ? bB : byteLen(oC)
299
+ onlyBaseBytes -= bB
300
+ onlyOtherBytes -= oB
301
+ changed.push({ path: to, renamedFrom: from, basePath: baseFile.get(from), baseBytes: bB, otherBytes: oB, delta: oB - bB, modified: !same, ...recorded(baseFile.get(from), to) })
302
+ changedDelta += oB - bB
303
+ // Both in one package (its key is in the rename's).
304
+ const acc = pkgAcc(from)
305
+ acc.onlyBaseFiles--
306
+ acc.onlyOtherFiles--
307
+ acc.changedFiles++
308
+ }
309
+ onlyBase.splice(0, onlyBase.length, ...onlyBase.filter(row => !renames.has(row.path)))
310
+ onlyOther.splice(0, onlyOther.length, ...onlyOther.filter(row => !renamedTo.has(row.path)))
311
+ }
312
+
313
+ // Classify each package from its accumulator: present on exactly one
314
+ // side → onlyBase / onlyOther; present on both with any moved file →
315
+ // changed; otherwise unchanged (dropped — the lists surface only
316
+ // what differs).
317
+ const pkgOnlyBase = []
318
+ const pkgOnlyOther = []
319
+ const pkgChanged = []
320
+ const pkgUnchanged = []
321
+ for (const [pkg, acc] of pkgs) {
322
+ // Present on a side if any of its files contributed there — its
323
+ // byte total, an only-this-side file, or a changed file (which
324
+ // exists on both). A changed file alone is enough to count as
325
+ // present even when that side's bytes net to zero.
326
+ const onBase = acc.baseBytes > 0 || acc.onlyBaseFiles > 0 || acc.changedFiles > 0
327
+ const onOther = acc.otherBytes > 0 || acc.onlyOtherFiles > 0 || acc.changedFiles > 0
328
+ const movedFiles = acc.onlyBaseFiles + acc.onlyOtherFiles + acc.changedFiles
329
+ if (onBase && !onOther) {
330
+ pkgOnlyBase.push({ pkg, bytes: acc.baseBytes })
331
+ } else if (onOther && !onBase) {
332
+ pkgOnlyOther.push({ pkg, bytes: acc.otherBytes })
333
+ } else if (movedFiles > 0 || acc.baseBytes !== acc.otherBytes) {
334
+ pkgChanged.push({
335
+ pkg,
336
+ baseBytes: acc.baseBytes,
337
+ otherBytes: acc.otherBytes,
338
+ delta: acc.otherBytes - acc.baseBytes,
339
+ })
340
+ } else {
341
+ pkgUnchanged.push({ pkg, bytes: acc.baseBytes })
342
+ }
343
+ }
344
+
345
+ onlyBase.sort(byBytesThenKey('path'))
346
+ onlyOther.sort(byBytesThenKey('path'))
347
+ changed.sort(byAbsDeltaThenKey('path'))
348
+ pkgOnlyBase.sort(byBytesThenKey('pkg'))
349
+ pkgOnlyOther.sort(byBytesThenKey('pkg'))
350
+ pkgChanged.sort(byAbsDeltaThenKey('pkg'))
351
+
352
+ return {
353
+ totals: {
354
+ baseFiles: base.size,
355
+ baseBytes,
356
+ otherFiles: other.size,
357
+ otherBytes,
358
+ onlyBaseFiles: onlyBase.length,
359
+ onlyBaseBytes,
360
+ onlyOtherFiles: onlyOther.length,
361
+ onlyOtherBytes,
362
+ changedFiles: changed.length,
363
+ renamedFiles: renames.size,
364
+ changedDelta,
365
+ unchangedFiles,
366
+ fileDelta: other.size - base.size,
367
+ byteDelta: otherBytes - baseBytes,
368
+ identical: onlyBase.length === 0 && onlyOther.length === 0 && changed.length === 0,
369
+ },
370
+ files: { onlyBase, onlyOther, changed, root, basePaths },
371
+ // `unchanged` lends a version-only change its (equal) sizes.
372
+ packages: { onlyBase: pkgOnlyBase, onlyOther: pkgOnlyOther, changed: pkgChanged, unchanged: pkgUnchanged },
373
+ }
374
+ }
375
+
376
+ // The versions' part (bundle-compare-versions.js), as one comparison reads it.
377
+ export { comparePackages, compareSemver, computeVersionUpdates, versionDirection } from './bundle-compare-versions.js'
@@ -0,0 +1,3 @@
1
+ import type { BundleDetails } from './bundle-metadata.js'
2
+ export function bundleCompareFiles(details: BundleDetails, scope?: string | null): Map<string, unknown>
3
+ export function bundleCompareSideScopes(base: BundleDetails, other: BundleDetails, scope?: string | null): [string, string]
@@ -0,0 +1,141 @@
1
+ import { bundleFilesAsMap } from './bundle-sources.js'
2
+
3
+ // A side's files, and the named trees holding any of them, with those they hold.
4
+ function namedTrees(details) {
5
+ const files = bundleFilesAsMap(details), trees = new Map()
6
+ for (const [name, paths] of Object.entries(details?.bundle?.reason ?? {})) {
7
+ const present = new Set(Array.isArray(paths) ? paths.filter(path => files.has(path)) : [])
8
+ if (present.size > 0) trees.set(name, present)
9
+ }
10
+ return { stasis: details?.kind === 'stasis', files, trees }
11
+ }
12
+
13
+ // Trees two sides name apart for the same files: a side naming the second of
14
+ // a pair and not the first, the other the first and not the second, has it
15
+ // compared as the first. A static build names the Metro bundle's `bundle:metro`
16
+ // and the rest `bundle`, as a capture names them `metro` and `run`: `bundle` is
17
+ // `run` only where `bundle:metro` is `metro`, on the same side.
18
+ const ALIASES = [['extra', 'add'], ['metro', 'bundle:metro']]
19
+ function aliased(sides) {
20
+ if (sides.length !== 2) return sides
21
+ const apart = (name, alias) => sides.find((side, i) => side.trees.has(alias) && !side.trees.has(name)
22
+ && sides[1 - i].trees.has(name) && !sides[1 - i].trees.has(alias))
23
+ const renames = sides.map(() => new Map())
24
+ for (const [name, alias] of ALIASES) {
25
+ const side = apart(name, alias)
26
+ if (side) renames[sides.indexOf(side)].set(alias, name)
27
+ }
28
+ const built = apart('metro', 'bundle:metro')
29
+ if (built && apart('run', 'bundle') === built) renames[sides.indexOf(built)].set('bundle', 'run')
30
+ // `actual`: the name a side gives a tree it is compared as another by.
31
+ return sides.map((side, i) => renames[i].size === 0 ? side : { ...side,
32
+ trees: new Map([...side.trees].map(([name, paths]) => [renames[i].get(name) ?? name, paths])),
33
+ actual: new Map([...renames[i]].map(([alias, name]) => [name, alias])) })
34
+ }
35
+
36
+ // The one tree of a stasis side naming every file it has (its own selector
37
+ // hidden, as common/bundle-reasons.js hides it), where no other side names it:
38
+ // such a side is compared within that tree under any of the others' trees.
39
+ function soleTree(side, sides) {
40
+ if (!side.stasis || side.trees.size !== 1) return null
41
+ const [[name, paths]] = side.trees
42
+ return paths.size === side.files.size && !sides.some(other => other !== side && other.trees.has(name)) ? name : null
43
+ }
44
+
45
+ // A side naming no tree, or one alone holding all its files.
46
+ const trivial = side => side.trees.size === 0 || (side.trees.size === 1 && [...side.trees.values()][0].size === side.files.size)
47
+
48
+ // A tree of each side the other names none of, compared with each other, as
49
+ // one scope: the same whichever side is the base, as a swap keeps it.
50
+ const PAIR = 'reasons:'
51
+ const pairScope = (first, second) => `${PAIR}${JSON.stringify([first, second].toSorted())}`
52
+ function pairOf(scope) {
53
+ if (!scope.startsWith(PAIR)) return null
54
+ try {
55
+ const pair = JSON.parse(scope.slice(PAIR.length))
56
+ return Array.isArray(pair) && pair.length === 2 && pair.every(name => typeof name === 'string') ? pair : null
57
+ } catch { return null }
58
+ }
59
+
60
+ // Use the union of named trees, each as its side is compared (aliased). A tree
61
+ // absent from one stasis bundle contains no files there; falling back to all
62
+ // files would invent additions/removals. A bundle that names no trees (a
63
+ // sourcemap) is compared whole under any of them, as is one whose sole tree
64
+ // holds all its files where the other names none of it (soleTree), its tree
65
+ // left out. Where neither side is trivial and each names a tree the other
66
+ // doesn't, the trees both name are offered, and each of the first side's own
67
+ // paired with each of the second's (pairScope), labelled from the first to the
68
+ // second. Unlike a single-bundle graph, retain a scope that includes every file
69
+ // on one side.
70
+ export function bundleCompareScopes(...details) {
71
+ const sides = aliased(details.map(namedTrees))
72
+ if (sides.length === 2 && !sides.some(trivial)) {
73
+ const [first, second] = sides.map(side => [...side.trees.keys()].toSorted())
74
+ const shared = first.filter(name => second.includes(name))
75
+ const [firstOwn, secondOwn] = [first, second].map(names => names.filter(name => !shared.includes(name)))
76
+ if (firstOwn.length > 0 && secondOwn.length > 0) {
77
+ return [...shared.map(name => ({ id: `reason:${name}`, label: name })),
78
+ ...firstOwn.flatMap(from => secondOwn.map(to => ({ id: pairScope(from, to), label: `${from} → ${to}` })))]
79
+ }
80
+ }
81
+ const scoped = sides.filter(side => soleTree(side, sides) === null)
82
+ const names = new Set(scoped.flatMap(side => [...side.trees.keys()]))
83
+ // A scope is only useful as a filter if it changes the files compared on
84
+ // some side. Keep every scope when at least one does, otherwise hide the
85
+ // selector, as single-bundle views do (see common/bundle-reasons.js).
86
+ const narrows = name => scoped.some(side => side.stasis && (side.trees.get(name)?.size ?? 0) < side.files.size)
87
+ if (![...names].some(narrows)) return []
88
+ return [...names].toSorted().map(name => ({ id: `reason:${name}`, label: name }))
89
+ }
90
+
91
+ // Each side's scope in a comparison within `scope`: within the tree of a pair
92
+ // (pairScope) it names; a side whose sole tree holds all its files, the other
93
+ // naming none of it (soleTree), within that tree; each within the tree it
94
+ // names as it is compared (aliased).
95
+ export function bundleCompareSideScopes(base, other, scope = '') {
96
+ if (!scope) return ['', '']
97
+ const pair = pairOf(scope), sides = aliased([base, other].map(namedTrees))
98
+ const named = scope.startsWith('reason:') ? scope.slice('reason:'.length) : null
99
+ return sides.map(side => {
100
+ const name = pair ? pair.find(tree => side.trees.has(tree)) : soleTree(side, sides) ?? named
101
+ return name == null ? scope : `reason:${side.actual?.get(name) ?? name}`
102
+ })
103
+ }
104
+
105
+ export function bundleCompareFiles(details, scope = '') {
106
+ const files = bundleFilesAsMap(details)
107
+ if (!scope || details?.kind !== 'stasis') return files
108
+ const paths = details?.bundle?.reason?.[scope.replace(/^reason:/u, '')]
109
+ const selected = new Set(Array.isArray(paths) ? paths : [])
110
+ return new Map([...files].filter(([path]) => selected.has(path)))
111
+ }
112
+
113
+ // A resolution's identity: its importer, specifier, conditions (import
114
+ // attributes included), and Metro platform.
115
+ export function resolutionKey(parent, specifier, conditions, platform) {
116
+ return JSON.stringify([parent, specifier, conditions, platform])
117
+ }
118
+
119
+ // Keep the full resolution identity: collapsing to graph edges would lose
120
+ // specifier, condition/import-attribute, and Metro platform changes.
121
+ export function bundleCompareResolutions(details, scope = '') {
122
+ const result = new Map()
123
+ if (details?.kind !== 'stasis' || !details.bundle) return result
124
+ const files = scope ? bundleFilesAsMap(details) : null
125
+ const selected = scope ? bundleCompareFiles(details, scope) : null
126
+ for (const [conditions, byParent] of details.bundle.imports) {
127
+ for (const [parent, specifiers] of byParent) {
128
+ for (const [specifier, resolved] of specifiers) {
129
+ const targets = typeof resolved === 'string' ? [[null, resolved]] : resolved
130
+ for (const [platform, target] of targets) {
131
+ // Include imports from scoped files, plus imports into the scope
132
+ // from uncaptured parents (e.g. an app in a dependencies-only bundle).
133
+ if (selected && !selected.has(parent) && (files.has(parent) || !selected.has(target))) continue
134
+ const key = resolutionKey(parent, specifier, conditions, platform)
135
+ result.set(key, { key, parent, specifier, conditions, platform, target })
136
+ }
137
+ }
138
+ }
139
+ }
140
+ return result
141
+ }