@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,183 @@
1
+ // A workflow, or an action's metadata, read for what it runs: its events, its
2
+ // jobs' steps (`uses`, `run`) and images, each on its line from 1.
3
+ import { YamlError, parseYaml } from '@preventive/lockfile/yaml.js'
4
+ import { readImage, readUses } from './uses.js'
5
+
6
+ const isMap = value => value !== null && typeof value === 'object' && !Array.isArray(value)
7
+ const stringOf = value => typeof value === 'string' ? value : null
8
+
9
+ // The line, from 1, `key` of a mapping or an entry of a sequence is on.
10
+ function lineOf(file, container, key, fallback) {
11
+ const at = container !== null && typeof container === 'object' ? file.positions.get(container) : undefined
12
+ const line = at instanceof Map ? at.get(key) : at?.[key]
13
+ return line === undefined ? fallback : line + 1
14
+ }
15
+
16
+ // The comment a line ends with, from 1.
17
+ const commentOn = (file, line) => /(?:^|[ \t])(#.*)$/u.exec(file.lines[line - 1] ?? '')?.[1] ?? null
18
+
19
+ // A step's or a job's `uses`, on its line, with the comment that line ends with.
20
+ function usesOf(file, owner, fallback, job = false) {
21
+ if (typeof owner.uses !== 'string') return null
22
+ const line = lineOf(file, owner, 'uses', fallback)
23
+ return { ...readUses(owner.uses, { job, comment: commentOn(file, line) }), line }
24
+ }
25
+
26
+ // A path's parts from the workspace, null for one out of it.
27
+ function partsOf(path) {
28
+ const parts = path.split('/').filter(part => part !== '' && part !== '.')
29
+ return parts.includes('..') ? null : parts
30
+ }
31
+
32
+ const hasExpression = text => /\$\{\{/u.test(text)
33
+ const OWN_REPOSITORY = /^\$\{\{\s*github\.repository\s*\}\}$/u
34
+ const inputText = value => value === undefined || value === null ? '' : String(value).trim()
35
+
36
+ // A checkout's ref as a reference names it: a commit in either case; HEAD,
37
+ // the default branch, for none; `refs/heads/…` and `refs/tags/…`, a branch
38
+ // or a tag alone; else one checkout looks for as a branch before a tag
39
+ // (`checkout`), not a tag first as a `uses:` is.
40
+ function checkoutRef(written) {
41
+ if (written === '') return { ref: 'HEAD' }
42
+ if (/^[\da-f]{40}$/iu.test(written)) return { ref: written.toLowerCase() }
43
+ const qualified = /^refs\/(heads|tags)\/(.+)$/iu.exec(written)
44
+ if (qualified) return { ref: `refs/${qualified[1].toLowerCase()}/${qualified[2]}` }
45
+ return /^refs\//iu.test(written) ? { ref: written } : { ref: written, branchFirst: true }
46
+ }
47
+
48
+ // What a step checks out (actions/checkout) and where (`at`, the path's
49
+ // parts): the repository's own (`own`); another's `repository` at its ref
50
+ // (checkoutRef), with the comment its ref's line ends with; or, where an
51
+ // expression names which, `unknown`. Null for no checkout, or one to a
52
+ // path an expression names.
53
+ function checkoutOf(file, step, uses) {
54
+ if (uses?.kind !== 'action' || uses.repo.toLowerCase() !== 'actions/checkout') return null
55
+ const inputs = isMap(step.with) ? step.with : {}
56
+ const path = inputText(inputs.path)
57
+ const at = hasExpression(path) ? null : partsOf(path)
58
+ if (!at) return null
59
+ const repository = inputText(inputs.repository), written = inputText(inputs.ref)
60
+ if (repository === '' || OWN_REPOSITORY.test(repository)) return { at, own: true }
61
+ if (hasExpression(repository) || hasExpression(written)) return { at, unknown: true }
62
+ return { at, repository, ...checkoutRef(written), comment: inputs.ref === undefined ? null : commentOn(file, lineOf(file, inputs, 'ref', null)) }
63
+ }
64
+
65
+ // A step's condition: null where it always runs (none, or true), false
66
+ // where it never does, else its expression's text.
67
+ function conditionOf(step) {
68
+ if (step.if === undefined || step.if === null || step.if === true) return null
69
+ const text = step.if === false ? 'false' : String(step.if).trim().replace(/^\$\{\{([^]*)\}\}$/u, '$1').trim()
70
+ if (text === '' || text === 'true') return null
71
+ return text === 'false' ? false : text
72
+ }
73
+
74
+ // A step's `./` action, where a checkout before it in its job is at its
75
+ // path, the latest's that runs whenever the step does (none's condition,
76
+ // or the step's own): another repository's, as a `uses:` naming it at its
77
+ // ref; the repository's own, from the path it is checked out to; as
78
+ // written where an expression names which.
79
+ function checkedOut(uses, checkouts, when) {
80
+ if (uses?.kind !== 'local' || uses.self) return uses
81
+ const dir = partsOf(uses.path)
82
+ const checkout = dir && checkouts.findLast(({ at, ...each }) => (each.when === null || each.when === when) && at.every((part, index) => dir[index] === part))
83
+ if (!checkout || checkout.unknown || (checkout.own && checkout.at.length === 0)) return uses
84
+ const rest = dir.slice(checkout.at.length).join('/')
85
+ if (checkout.own) return { ...uses, path: rest }
86
+ const read = readUses(`${checkout.repository}${rest ? `/${rest}` : ''}@${checkout.ref}`, { comment: checkout.comment })
87
+ if (read.kind !== 'action') return uses
88
+ return { ...read, ...checkout.branchFirst && read.pin !== 'sha' && { checkout: true }, line: uses.line }
89
+ }
90
+
91
+ function triggersOf(on) {
92
+ if (typeof on === 'string') return [on]
93
+ if (Array.isArray(on)) return on.filter(event => typeof event === 'string')
94
+ return isMap(on) ? Object.keys(on) : []
95
+ }
96
+
97
+ // The line a `|` block scalar's text starts on, after its key's; else null.
98
+ const LITERAL_HEADER = /:[ \t]+(?:&\S+[ \t]+)?\|[1-9+-]{0,2}[ \t]*(?:#.*)?$/u
99
+ const literalStart = (file, line) => line !== null && LITERAL_HEADER.test(file.lines[line - 1] ?? '') ? line + 1 : null
100
+
101
+ // A `run:` step's script, and its directory, else `directory` (defaults.run);
102
+ // `production` where its `env`, else the job's or the workflow's (`env`),
103
+ // sets NODE_ENV so, as an install then leaves devDependencies out.
104
+ const envOf = (owner, outer = {}) => ({ ...outer, ...isMap(owner?.env) ? owner.env : {} })
105
+ function runOf(file, step, directory, env) {
106
+ const script = stringOf(step.run)
107
+ if (script === null) return null
108
+ const line = lineOf(file, step, 'run', null)
109
+ return { script, line, start: literalStart(file, line), workingDirectory: stringOf(step['working-directory']) ?? directory,
110
+ production: envOf(step, env).NODE_ENV === 'production' }
111
+ }
112
+
113
+ // A step's or a job's `with`, and the line each input is on.
114
+ function inputsOf(file, owner, line) {
115
+ const inputs = isMap(owner.with) ? owner.with : null
116
+ return { with: inputs, withLines: inputs ? Object.fromEntries(Object.keys(inputs).map(key => [key, lineOf(file, inputs, key, line)])) : {} }
117
+ }
118
+
119
+ // A job's steps, each `./` action as the checkouts before it that run have it.
120
+ function stepsOf(file, steps, directory, env = {}) {
121
+ if (!Array.isArray(steps)) return []
122
+ const checkouts = []
123
+ return steps.flatMap((step, index) => {
124
+ if (!isMap(step)) return []
125
+ const line = lineOf(file, steps, index, null)
126
+ const uses = usesOf(file, step, line), when = conditionOf(step)
127
+ const checkout = when === false ? null : checkoutOf(file, step, uses)
128
+ if (checkout) checkouts.push({ ...checkout, when })
129
+ return [{ line, uses: checkedOut(uses, checkouts, when), run: runOf(file, step, directory, env), ...inputsOf(file, step, line) }]
130
+ })
131
+ }
132
+
133
+ // The directory a workflow's or a job's `defaults.run` names, else `outer`.
134
+ const directoryOf = (owner, outer) => stringOf(isMap(owner?.defaults) && isMap(owner.defaults.run) ? owner.defaults.run['working-directory'] : null) ?? outer
135
+
136
+ // The images a job runs in: its container's and its services'.
137
+ function imagesOf(file, job) {
138
+ const images = []
139
+ const container = isMap(job.container) ? job.container.image : job.container
140
+ if (typeof container === 'string') images.push({ text: container, line: lineOf(file, isMap(job.container) ? job.container : job, isMap(job.container) ? 'image' : 'container', null) })
141
+ if (isMap(job.services)) {
142
+ for (const service of Object.values(job.services)) {
143
+ if (isMap(service) && typeof service.image === 'string') images.push({ text: service.image, line: lineOf(file, service, 'image', null) })
144
+ }
145
+ }
146
+ return images.map(image => ({ ...image, read: readImage(image.text) }))
147
+ }
148
+
149
+ function jobsOf(file, doc) {
150
+ if (!isMap(doc.jobs)) throw new YamlError('a workflow has no jobs')
151
+ const directory = directoryOf(doc, null)
152
+ return Object.values(doc.jobs).filter(isMap).map(job => ({ uses: usesOf(file, job, null, true), secrets: job.secrets ?? null, ...inputsOf(file, job, null),
153
+ steps: stepsOf(file, job.steps, directoryOf(job, directory), envOf(job, envOf(doc))), images: imagesOf(file, job) }))
154
+ }
155
+
156
+ // An action's `runs`: its runtime, a composite one's steps as a job, and a
157
+ // Docker one's image or Dockerfile.
158
+ function runsOf(file, doc) {
159
+ const runs = isMap(doc.runs) ? doc.runs : null
160
+ if (!runs || typeof runs.using !== 'string') throw new YamlError('an action has no runs.using')
161
+ const using = runs.using.toLowerCase()
162
+ const usingLine = lineOf(file, runs, 'using', null)
163
+ const image = using === 'docker' ? stringOf(runs.image) : null
164
+ const imageLine = lineOf(file, runs, 'image', usingLine)
165
+ const docker = image?.startsWith('docker://') ? { text: image.slice('docker://'.length), line: imageLine, read: readImage(image.slice('docker://'.length)) } : null
166
+ const steps = using === 'composite' ? stepsOf(file, runs.steps, null) : []
167
+ return { using, usingLine, dockerfile: image && !docker ? { path: image.replace(/^\.\//u, ''), line: imageLine } : null, jobs: [{ uses: null, steps, images: docker ? [docker] : [] }] }
168
+ }
169
+
170
+ // A workflow (`kind` 'workflow') or an action's metadata ('action') read, or
171
+ // the YamlError of one GitHub can't run.
172
+ export function readWorkflow(kind, text) {
173
+ try {
174
+ const file = { lines: text.split('\n'), positions: new WeakMap() }
175
+ const doc = parseYaml(text, { workflow: true, lines: file.positions })
176
+ if (!isMap(doc)) throw new YamlError(`${kind === 'action' ? 'an action' : 'a workflow'} is not a mapping`)
177
+ if (kind === 'action') return { triggers: [], ...runsOf(file, doc) }
178
+ return { triggers: triggersOf(doc.on), using: null, usingLine: null, dockerfile: null, jobs: jobsOf(file, doc) }
179
+ } catch (error) {
180
+ if (error instanceof YamlError) return error
181
+ throw error
182
+ }
183
+ }
@@ -0,0 +1,354 @@
1
+ // The characters a text holds that can make it read other than it runs, or
2
+ // hide text in it: control and bidirectional characters, and the invisible
3
+ // characters a payload or a name no one sees can be spelled in (variation
4
+ // selectors, Hangul fillers, tags), and letters out of place in a word of
5
+ // another script (mixedScripts). Shared with a code viewer that shows each
6
+ // as a labelled box (ui/view/control-chars.js), which leaves what spells an
7
+ // emoji, a recommended flag or a line's end as it is (passed), and marks
8
+ // each letter out of place.
9
+
10
+ // What a text holds beyond printing characters and its line breaks: the C0
11
+ // controls other than tab, line feed and carriage return, DEL, the C1
12
+ // controls, and the bidirectional controls that can make code read other than
13
+ // it runs ("Trojan Source"); and the invisible characters that can hide text
14
+ // in it (invisibleCharacters), as a payload hidden in
15
+ // variation selectors or a variable named by a Hangul filler.
16
+ export const CONTROLS = /(?![\t\n\r])\p{Cc}|[\u202A-\u202E\u2066-\u2069]/gu
17
+ const NON_ASCII = /\P{ASCII}/u
18
+
19
+ // What shows as nothing, or as another character, where a viewer draws it as
20
+ // text: the controls but tab and line feed (C0, DEL, C1), the format
21
+ // characters (Cf: zero-width ones, the bidi controls, tags), lone surrogates
22
+ // (Cs; `u` reads a pair as the one character it spells), private use (Co) and
23
+ // unassigned (Cn) code points, the line and paragraph separators, spaces other
24
+ // than a space, the default-ignorable characters and the Braille blank. A code
25
+ // viewer boxes each (ui/view/control-chars.js), and a source map's listing
26
+ // writes a line holding one as JSON (common/sourcemap-listing.js).
27
+ // eslint-disable-next-line no-control-regex
28
+ export const UNSEEN = /[\u0000-\u0008\u000B-\u001F\u007F-\u009F\u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u2800\u3000\p{Cf}\p{Cs}\p{Co}\p{Cn}\p{Default_Ignorable_Code_Point}]/u
29
+
30
+ // A file's text: `kind` 'ascii' or 'utf8', by whether it holds anything past
31
+ // ASCII, else 'binary' (which the server tells by its bytes, sending no
32
+ // text); `controls` the control and invisible characters a text holds, and
33
+ // its letters out of place (mixedScripts), how often by code point, or null
34
+ // for none.
35
+ export function npmTextEncoding(text) {
36
+ if (typeof text !== 'string') return { kind: 'binary', controls: null }
37
+ const controls = new Map()
38
+ for (const [char] of text.matchAll(CONTROLS)) controls.set(char.codePointAt(0), (controls.get(char.codePointAt(0)) ?? 0) + 1)
39
+ // The invisible characters are all past ASCII, as is a letter of any
40
+ // script but Latin, which a word of mixed scripts holds: looked for in a
41
+ // text that has any, from its first.
42
+ const past = text.search(NON_ASCII)
43
+ if (past !== -1) {
44
+ for (const [code, times] of invisibleCharacters(text, past) ?? []) controls.set(code, times)
45
+ mixedScripts(text, (at, code) => controls.set(code, (controls.get(code) ?? 0) + 1), past)
46
+ }
47
+ return { kind: past === -1 ? 'ascii' : 'utf8', controls: controls.size > 0 ? controls : null }
48
+ }
49
+
50
+ // A pictograph is an assigned one (Emoji): Extended_Pictographic also takes
51
+ // in code points reserved for emoji to come, unassigned, each boxed itself,
52
+ // and a joiner or selector beside one would go unseen.
53
+ const EMOJI_BEFORE = /(?=\p{Emoji})\p{Extended_Pictographic}(?:\u{FE0F}|[\u{1F3FB}-\u{1F3FF}])?$/u
54
+ const EMOJI_AFTER = /^(?=\p{Emoji})\p{Extended_Pictographic}/u
55
+ const PICTOGRAPH_BEFORE = /(?=\p{Emoji})\p{Extended_Pictographic}$/u
56
+ const KEYCAP_BASE = /^[\d#*]$/u
57
+ const isTag = code => code >= 0xe0020 && code <= 0xe007f
58
+ // The subdivision flags Unicode recommends (RGI), their tags spelling the
59
+ // subdivision after a black flag: England's, Scotland's and Wales's. Others
60
+ // show as a black flag and their tags as nothing, as a payload in them would.
61
+ const FLAGS = new Set(['gbeng', 'gbsct', 'gbwls'])
62
+ const tagged = (text, from, to) => to - from === 10 ? String.fromCodePoint(...Array.from({ length: 5 }, (_, i) => text.codePointAt(from + 2 * i) - 0xe0000)) : ''
63
+
64
+ // Where to go on from where `code` at `at` in `text` stays text, else -1 for
65
+ // one to show. A CR before a newline is part of the line end, as is one that
66
+ // ends `text` where `lineEnd` says a newline follows it. A joiner between two
67
+ // emoji joins them into one, a recommended subdivision flag's tags, up to the
68
+ // cancel tag, name its region (FLAGS), and the text or emoji presentation
69
+ // selector after a pictograph, or the emoji one between a keycap's digit, #
70
+ // or * and its mark, draws it; after a letter or a digit alone it is another
71
+ // name.
72
+ export function passed(text, at, code, lineEnd) {
73
+ if (code === 0x0d && (text[at + 1] === '\n' || lineEnd && at + 1 === text.length)) return at + 1
74
+ if (code === 0x200d && EMOJI_BEFORE.test(text.slice(Math.max(0, at - 4), at)) && EMOJI_AFTER.test(text.slice(at + 1, at + 3))) return at + 1
75
+ if ((code === 0xfe0e || code === 0xfe0f) && PICTOGRAPH_BEFORE.test(text.slice(Math.max(0, at - 2), at))) return at + 1
76
+ if (code === 0xfe0f && KEYCAP_BASE.test(text[at - 1] ?? '') && text[at + 1] === '\u20E3') return at + 1
77
+ if (isTag(code) && !isTag(text.codePointAt(at - 2))) {
78
+ let end = at
79
+ while (isTag(text.codePointAt(end))) end += 2
80
+ if (text.codePointAt(at - 2) === 0x1f3f4 && text.codePointAt(end - 2) === 0xe007f && FLAGS.has(tagged(text, at, end - 2))) return end
81
+ }
82
+ return -1
83
+ }
84
+
85
+ // Those text is hidden in, as a file's Invisible chars label counts them
86
+ // (readability.js), where they show: variation selectors (a payload, a
87
+ // byte a selector), Hangul fillers (a name no one sees) and tags (ASCII no one
88
+ // sees). Not the format characters, a BOM or a zero-width space, which text
89
+ // has its uses for, nor the other marks that show as nothing (the combining
90
+ // grapheme joiner, the Khmer inherent vowels and the Mongolian free variation
91
+ // selectors), which tables of the characters a name may hold, as JavaScript
92
+ // parsers have, hold too; nor what of these hides nothing (benign).
93
+ export const INVISIBLE = /[\u115F\u1160\u3164\uFFA0\u{E0001}\u{E0020}-\u{E007F}]|[\uFE00-\uFE0F]|[\u{E0100}-\u{E01EF}]/u
94
+ // The code units they are in, to look for them by, faster than by code point:
95
+ // the high surrogate starting those past the Basic Multilingual Plane (tags,
96
+ // the selectors' supplement) too, told apart from its others once found. No
97
+ // `u`, which would read a pair as the one code point it spells.
98
+ // eslint-disable-next-line require-unicode-regexp
99
+ const INVISIBLE_UNITS = /[\uFE00-\uFE0F\u115F\u1160\u3164\uFFA0\uDB40]/g
100
+ // A table's code points, from its ranges in hex (`30 2018-2019`).
101
+ const codePoints = ranges => new Set(ranges.split(' ').flatMap(range => {
102
+ const [from, to = from] = range.split('-').map(digits => Number.parseInt(digits, 16))
103
+ return Array.from({ length: to - from + 1 }, (_, i) => from + i)
104
+ }))
105
+ // The variation sequences Unicode registers, which hide nothing, though Code
106
+ // shows their selectors after a letter or a digit, another name there: VS1 to
107
+ // VS14's on other than an ideograph (StandardizedVariants.txt, Unicode
108
+ // 18.0.0), each selector's bases, as an HTML entity table's math symbols, and
109
+ // the emoji with a text and an emoji presentation, VS15 and VS16 after each
110
+ // (emoji-variation-sequences.txt), as a heading's anchor keeps one (`#`).
111
+ const STANDARDIZED = new Map([
112
+ [0xfe00, '30 1000 1002 1004 1010-1011 1015 1019-101a 101c-101d 1022 1031 1075'
113
+ + ' 1078 107a 1080 2018-2019 201c-201d 210b 2110 2112 211b 212c 2130-2131'
114
+ + ' 2133 2205 2229-222a 223d 2242-2243 2248 2268-2269 2272-2273 228a-228b'
115
+ + ' 2293-2295 2297 229c 22cd 22da-22dd 29b7 2a3c-2a3d 2a6c 2a9d-2a9e'
116
+ + ' 2aac-2aad 2acb-2acc 3001-3002 31c0 31c6 31c9 31cf-31d2 31d4-31d5 31d7'
117
+ + ' 31db-31dd 31e5 a856 a85c a85e-a860 a868 aa60-aa66 aa6b-aa6c aa6f aa7a'
118
+ + ' ff01 ff0c ff0e ff10 ff1a-ff1b ff1f 10ac5-10ac6 10ad6-10ad7 10ae1 13091'
119
+ + ' 1310f 1311c 13121 13127 13139 131a0 131b1 131b8-131b9 131cb 131e0'
120
+ + ' 131f9-131fa 1327b 1327f 13285 1328c 132aa 132cb 132dc 132e7 13307'
121
+ + ' 1331b 13322 1333c 13377-13378 13399-1339a 133d3 133e4-133e5 133e7'
122
+ + ' 133ee 133f2 133f5-133f6 13416 13419-1341a 13423 13443-13446'
123
+ + ' 13be8-13bea 13f72 1d49c 1d49e-1d49f 1d4a2 1d4a5-1d4a6 1d4a9-1d4ac'
124
+ + ' 1d4ae-1d4b5 1db10'],
125
+ [0xfe01, '2018-2019 201c-201d 210b 2110 2112 211b 212c 2130-2131 2133 3001-3002'
126
+ + ' 31c6 31cf 31dd ff01 ff0c ff0e ff1a-ff1b ff1f 13093 13132 13139 13187'
127
+ + ' 131b1 131ee 131f8-131fa 13257 1327f 1328b 132a4 13308 13312-13314'
128
+ + ' 1331b 13321-13322 13331 133e8 13419 13f1f 14274 1d49c 1d49e-1d49f'
129
+ + ' 1d4a2 1d4a5-1d4a6 1d4a9-1d4ac 1d4ae-1d4b5'],
130
+ [0xfe02, '2018-2019 201c-201d 13117 13139 13183 131a0 131ba 131ee 13216 1327b'
131
+ + ' 132a4 132e7 132e9 132f8 132fd 13302-13303 13310-13314 1331c 13321'
132
+ + ' 13331 1334a 13361 13373 1337d 13385 133af-133b0 133bf 133db 133dd'
133
+ + ' 13419 1342c 1342e 14274 1d4cf'],
134
+ [0xfe03, '13012 130b8 130ba 1310f 1312f 13139 13184 1319c-1319d 1319f 131b1'
135
+ + ' 131db 13205 13296 13338 13419'],
136
+ [0xfe04, '13139 1340d'],
137
+ [0xfe05, '13139 14274'],
138
+ [0xfe06, '1312f 13139 13184 131db 131ee 13205 132a4 132e9 1332b 13338'
139
+ + ' 13370-13371 13419 14274'],
140
+ ].map(([selector, bases]) => [selector, codePoints(bases)]))
141
+ const EMOJI = codePoints('23 2a 30-39 a9 ae 203c 2049 2122 2139 2194-2199 21a9-21aa 231a-231b 2328'
142
+ + ' 23cf 23e9-23f3 23f8-23fa 24c2 25aa-25ab 25b6 25c0 25fb-25fe 2600-2604 260e'
143
+ + ' 2611 2614-2615 2618 261d 2620 2622-2623 2626 262a 262e-262f 2638-263a 2640'
144
+ + ' 2642 2648-2653 265f-2660 2663 2665-2666 2668 267b 267e-267f 2692-2697 2699'
145
+ + ' 269b-269c 26a0-26a1 26a7 26aa-26ab 26b0-26b1 26bd-26be 26c4-26c5 26c8'
146
+ + ' 26ce-26cf 26d1 26d3-26d4 26e9-26ea 26f0-26f5 26f7-26fa 26fd 2702 2705'
147
+ + ' 2708-270d 270f 2712 2714 2716 271d 2721 2728 2733-2734 2744 2747 274c 274e'
148
+ + ' 2753-2755 2757 2763-2764 2795-2797 27a1 27b0 27bf 2934-2935 2b05-2b07'
149
+ + ' 2b1b-2b1c 2b50 2b55 3030 303d 3297 3299 1f004 1f170-1f171 1f17e-1f17f'
150
+ + ' 1f202 1f21a 1f22f 1f237 1f30d-1f30f 1f315 1f31c 1f321 1f324-1f32c 1f336'
151
+ + ' 1f378 1f37d 1f393 1f396-1f397 1f399-1f39b 1f39e-1f39f 1f3a7 1f3ac-1f3ae'
152
+ + ' 1f3c2 1f3c4 1f3c6 1f3ca-1f3ce 1f3d4-1f3e0 1f3ed 1f3f3 1f3f5 1f3f7 1f408'
153
+ + ' 1f415 1f41f 1f426 1f43f 1f441-1f442 1f446-1f449 1f44d-1f44e 1f453 1f46a'
154
+ + ' 1f47d 1f4a3 1f4b0 1f4b3 1f4bb 1f4bf 1f4cb 1f4da 1f4df 1f4e4-1f4e6'
155
+ + ' 1f4ea-1f4ed 1f4f7 1f4f9-1f4fb 1f4fd 1f508 1f50d 1f512-1f513 1f549-1f54a'
156
+ + ' 1f550-1f567 1f56f-1f570 1f573-1f579 1f587 1f58a-1f58d 1f590 1f5a5 1f5a8'
157
+ + ' 1f5b1-1f5b2 1f5bc 1f5c2-1f5c4 1f5d1-1f5d3 1f5dc-1f5de 1f5e1 1f5e3 1f5e8'
158
+ + ' 1f5ef 1f5f3 1f5fa 1f610 1f687 1f68d 1f691 1f694 1f698 1f6ad 1f6b2'
159
+ + ' 1f6b9-1f6ba 1f6bc 1f6cb 1f6cd-1f6cf 1f6e0-1f6e5 1f6e9 1f6f0 1f6f3')
160
+ // The blocks of variation selectors, as those tables write them out as ranges.
161
+ const BLOCKS = [[0xfe00, 0xfe0f], [0xe0100, 0xe01ef]]
162
+ // The compatibility jamo but their filler.
163
+ const JAMO = [[0x3131, 0x3163], [0x3165, 0x318e]]
164
+
165
+ // The code point before `at` in `text`, a pair of surrogates read as one.
166
+ function codePointBefore(text, at) {
167
+ if (at === 0) return undefined
168
+ const pair = at >= 2 ? text.codePointAt(at - 2) : 0
169
+ return pair > 0xffff ? pair : text.codePointAt(at - 1)
170
+ }
171
+ const within = (code, ...ranges) => code !== undefined && ranges.some(([from, to]) => code >= from && code <= to)
172
+
173
+ // Whether the one shown as `code` at `at` hides nothing: a Hangul filler
174
+ // composing Hangul (the initial consonant's before a vowel, a syllable with
175
+ // none, or the vowel's after an initial consonant, one with none), or a
176
+ // compatibility or halfwidth jamo's among those jamo, as a codepage's table
177
+ // lists them, though not one after a syllable, a name that reads as it; a
178
+ // variation sequence Unicode registers; a block of selectors written out as a
179
+ // range in a table (`VS1-VS16`); or an emoji's presentation selector doubled,
180
+ // as copying text leaves it.
181
+ function benign(text, at, code) {
182
+ const end = at + (code > 0xffff ? 2 : 1)
183
+ const after = text.codePointAt(end), before = codePointBefore(text, at)
184
+ switch (code) {
185
+ case 0x115f: return within(after, [0x1161, 0x11a7], [0xd7b0, 0xd7c6])
186
+ case 0x1160: return within(before, [0x1100, 0x115e], [0xa960, 0xa97c])
187
+ case 0x3164: return within(before, ...JAMO) || within(after, ...JAMO)
188
+ case 0xffa0: return within(before, [0xffa1, 0xffdc]) || within(after, [0xffa1, 0xffdc])
189
+ default: return (code === 0xfe0e || code === 0xfe0f ? EMOJI.has(before) : STANDARDIZED.get(code)?.has(before))
190
+ || BLOCKS.some(([from, to]) => code === from && text[end] === '-' && text.codePointAt(end + 1) === to
191
+ || code === to && text[at - 1] === '-' && codePointBefore(text, at - 1) === from)
192
+ || (code === 0xfe0e || code === 0xfe0f) && before === code && PICTOGRAPH_BEFORE.test(text.slice(Math.max(0, at - 3), at - 1))
193
+ }
194
+ }
195
+
196
+ // How many of each a text holds, by code point, or null for none: each one
197
+ // a code viewer shows (passed), visited alone, not each character it shows. `from`:
198
+ // where to look from, as the first character past ASCII, since all of them are.
199
+ export function invisibleCharacters(text, from = 0) {
200
+ let found = null
201
+ INVISIBLE_UNITS.lastIndex = from
202
+ for (let match = INVISIBLE_UNITS.exec(text); match; match = INVISIBLE_UNITS.exec(text)) {
203
+ const at = match.index, code = text.codePointAt(at)
204
+ if (!INVISIBLE.test(String.fromCodePoint(code))) continue
205
+ const next = passed(text, at, code, false)
206
+ if (next !== -1) INVISIBLE_UNITS.lastIndex = next
207
+ else if (!benign(text, at, code)) {
208
+ found ??= new Map()
209
+ found.set(code, (found.get(code) ?? 0) + 1)
210
+ }
211
+ }
212
+ return found
213
+ }
214
+
215
+ // Letters out of place in a word of more than one script, as a look-alike
216
+ // spells a name or a host other than the one it reads as (`food` or
217
+ // `google.com` with a Cyrillic `o`, U+043E): a word a run of letters, marks,
218
+ // digits, `_` and `$`, those of Common and Inherited script of none, as are
219
+ // the default-ignorables (Invisible's fillers). As UTS #39's Highly
220
+ // Restrictive level has it, a word of one script is fine, as is one of Latin,
221
+ // Han and kana, of Latin, Han and Bopomofo, or of Latin, Han and Hangul. Not
222
+ // a word wholly of a script that reads as another (`ape` spelled in
223
+ // Cyrillic), as most of some scripts' words would be.
224
+ const WORD = String.raw`\p{L}\p{M}\p{Nd}_$`
225
+ const NONE = String.raw`\p{sc=Zyyy}\p{sc=Zinh}\p{Default_Ignorable_Code_Point}`
226
+ // A word's character of a script but Latin, which one of mixed scripts
227
+ // holds: past Latin-1, as all are, told first, which passes the rest faster.
228
+ const FOREIGN = new RegExp(String.raw`(?=[^\0-\xFF])[[${WORD}]--[\p{sc=Latn}${NONE}]]`, 'gv')
229
+ export const NON_LATIN = new RegExp(FOREIGN.source, 'v')
230
+ const NO_SCRIPT = new RegExp(`[${NONE}]`, 'uy')
231
+ const WORD_CHAR = new RegExp(`[${WORD}]`, 'uy')
232
+
233
+ // The scripts by their codes (Unicode 17.0.0), the most met first: those this
234
+ // engine knows, as one with older tables knows no letter of a newer script.
235
+ const SCRIPTS = ('Latn Cyrl Grek Hani Hira Kana Hang Bopo Arab Hebr Armn Geor Thai Deva Adlm Aghb Ahom Armi Avst Bali Bamu'
236
+ + ' Bass Batk Beng Berf Bhks Brah Brai Bugi Buhd Cakm Cans Cari Cham Cher Chrs Copt Cpmn Cprt Diak Dogr Dsrt'
237
+ + ' Dupl Egyp Elba Elym Ethi Gara Glag Gong Gonm Goth Gran Gujr Gukh Guru Hano Hatr Hluw Hmng Hmnp Hung Ital'
238
+ + ' Java Kali Kawi Khar Khmr Khoj Kits Knda Krai Kthi Lana Laoo Lepc Limb Lina Linb Lisu Lyci Lydi Mahj Maka'
239
+ + ' Mand Mani Marc Medf Mend Merc Mero Mlym Modi Mong Mroo Mtei Mult Mymr Nagm Nand Narb Nbat Newa Nkoo Nshu'
240
+ + ' Ogam Olck Onao Orkh Orya Osge Osma Ougr Palm Pauc Perm Phag Phli Phlp Phnx Plrd Prti Rjng Rohg Runr Samr'
241
+ + ' Sarb Saur Sgnw Shaw Shrd Sidd Sidt Sind Sinh Sogd Sogo Sora Soyo Sund Sunu Sylo Syrc Tagb Takr Tale Talu'
242
+ + ' Taml Tang Tavt Tayo Telu Tfng Tglg Thaa Tibt Tirh Tnsa Todr Tols Toto Tutg Ugar Vaii Vith Wara Wcho Xpeo'
243
+ + ' Xsux Yezi Yiii Zanb').split(' ').flatMap(code => {
244
+ try {
245
+ return [{ code, char: new RegExp(String.raw`\p{sc=${code}}`, 'uy') }]
246
+ } catch {
247
+ return []
248
+ }
249
+ })
250
+ const UNKNOWN = { code: 'Zzzz', char: /\p{sc=Zzzz}/uy }
251
+ const isOf = ({ char }, text, at) => {
252
+ char.lastIndex = at
253
+ return char.test(text)
254
+ }
255
+ // The script of the character at `at`, the last found tried first.
256
+ let last = UNKNOWN
257
+ function scriptAt(text, at) {
258
+ if (!isOf(last, text, at)) last = SCRIPTS.find(script => isOf(script, text, at)) ?? UNKNOWN
259
+ return last.code
260
+ }
261
+
262
+ // A script's name by its code, and the script a code point is of.
263
+ const SCRIPT_NAMES = new Intl.DisplayNames('en', { type: 'script' })
264
+ export const scriptName = code => SCRIPT_NAMES.of(code)
265
+ export const scriptOf = code => scriptAt(String.fromCodePoint(code), 0)
266
+
267
+ // A run read a stretch at a time, as a regular expression's loop over a
268
+ // megabyte past Latin-1 runs out of stack: where one from `at` stops.
269
+ const STRETCH = 4096
270
+ function runEnd(run, text, at) {
271
+ for (let from = at; ; from = run.lastIndex) {
272
+ run.lastIndex = from
273
+ run.test(text)
274
+ if (run.lastIndex - from < STRETCH) return run.lastIndex
275
+ }
276
+ }
277
+ // A pattern's loop over a run of `unit`s (a source, or what makes one where
278
+ // it holds such a loop) read so in one match, as one of alternatives runs
279
+ // out within Latin-1 too: whole stretches (a lookahead's, matched again by
280
+ // its name), then up to one more a unit at a time, at least one after any
281
+ // stretch, so each end is read one way, and what backtracks into it tries
282
+ // them in turn as the loop would. Its units each read one way, or another
283
+ // only to end the run (a string's `\` before CRLF), as a stretch short of
284
+ // its length tries every way. Each of its names its own.
285
+ let stretches = 0
286
+ export function stretched(unit) {
287
+ const name = `stretch${stretches++}`, source = typeof unit === 'function' ? unit : () => unit
288
+ return String.raw`(?:(?:(?=(?<${name}>(?:${source()}){${STRETCH}}))\k<${name}>)+(?:${source()}){1,${STRETCH}}|(?:${source()}){0,${STRETCH}})`
289
+ }
290
+ // A word; one of `scripts` or of no script; and a passage of such words and
291
+ // what lies between them.
292
+ const WORD_RUN = new RegExp(`[${WORD}]{0,${STRETCH}}`, 'uy')
293
+ const scriptsOf = scripts => `[${scripts.map(code => String.raw`\p{sc=${code}}`).join('')}${NONE}]`
294
+ const wordOf = scripts => new RegExp(String.raw`[[${WORD}]&&${scriptsOf(scripts)}]{0,${STRETCH}}`, 'vy')
295
+ const passageOf = scripts => new RegExp(String.raw`[^[${WORD}]--${scriptsOf(scripts)}]{0,${STRETCH}}`, 'vy')
296
+ // The words of the scripts UTS #39 allows together; and a script's word and
297
+ // passage, made once asked for, its passage of those it is allowed with.
298
+ const TOGETHER = [['Latn', 'Hani', 'Hira', 'Kana'], ['Latn', 'Hani', 'Bopo'], ['Latn', 'Hani', 'Hang']]
299
+ const ALLOWED = TOGETHER.map(wordOf)
300
+ const RUNS = new Map()
301
+ function runsOf(script) {
302
+ if (!RUNS.has(script)) RUNS.set(script, { word: wordOf([script]), passage: passageOf(TOGETHER.find(scripts => scripts.includes(script)) ?? [script]) })
303
+ return RUNS.get(script)
304
+ }
305
+ const covers = (word, text, start, end) => runEnd(word, text, start) === end
306
+
307
+ // Where the word holding `at` starts, from `floor` on.
308
+ function wordStart(text, at, floor) {
309
+ let start = at
310
+ while (start > floor) {
311
+ const back = start - (codePointBefore(text, start) > 0xffff ? 2 : 1)
312
+ WORD_CHAR.lastIndex = back
313
+ if (!WORD_CHAR.test(text)) break
314
+ start = back
315
+ }
316
+ return start
317
+ }
318
+
319
+ // Each letter of a word of mixed scripts but its main script's, the most of
320
+ // its letters' (Latin on a tie, else the first), to `found`: counted, then
321
+ // visited, none kept, as a word can be a megabyte long.
322
+ function misplaced(text, start, end, found) {
323
+ const letters = visit => {
324
+ for (let at = start; at < end; at += text.codePointAt(at) > 0xffff ? 2 : 1) {
325
+ NO_SCRIPT.lastIndex = at
326
+ if (!NO_SCRIPT.test(text)) visit(at, scriptAt(text, at))
327
+ }
328
+ }
329
+ const counts = new Map()
330
+ letters((at, script) => counts.set(script, (counts.get(script) ?? 0) + 1))
331
+ let home = 'Latn'
332
+ for (const [script, times] of counts) if (times > (counts.get(home) ?? 0)) home = script
333
+ letters((at, script) => {
334
+ if (script !== home) found(at, text.codePointAt(at), script, home)
335
+ })
336
+ }
337
+
338
+ // Each letter out of place in a text, in order, as `found(at, code point, its
339
+ // script, its word's)`, by their scripts' codes; `from`: where to look from,
340
+ // as the first character past ASCII. From a word holding a letter of a script
341
+ // but Latin, the passage of that script's words is read as one run; the word
342
+ // it stops at, holding a letter of another, is read whole, and on from it.
343
+ export function mixedScripts(text, found, from = 0) {
344
+ FOREIGN.lastIndex = from
345
+ for (let floor = 0; FOREIGN.test(text); FOREIGN.lastIndex = floor) {
346
+ const at = FOREIGN.lastIndex - (codePointBefore(text, FOREIGN.lastIndex) > 0xffff ? 2 : 1)
347
+ const stop = runEnd(runsOf(scriptAt(text, at)).passage, text, wordStart(text, at, floor))
348
+ if (stop === text.length) return
349
+ const start = wordStart(text, stop, floor)
350
+ const end = runEnd(WORD_RUN, text, start)
351
+ if (!covers(runsOf(scriptAt(text, stop)).word, text, start, end) && !ALLOWED.some(word => covers(word, text, start, end))) misplaced(text, start, end, found)
352
+ floor = end
353
+ }
354
+ }