@nitpicker/crawler 0.24.0 → 0.25.1

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 (744) hide show
  1. package/README.md +2 -2
  2. package/lib/beholder-type-mirror-parity.d.ts +96 -0
  3. package/lib/crawler/capture-custom-elements.d.ts +4 -4
  4. package/lib/crawler/capture-custom-elements.js +3 -3
  5. package/lib/crawler/capture-image-dom-paths.d.ts +3 -3
  6. package/lib/crawler/capture-image-dom-paths.js +2 -2
  7. package/lib/crawler/collect-custom-elements.d.ts +1 -1
  8. package/lib/crawler/collect-image-dom-paths.d.ts +2 -2
  9. package/lib/crawler/collect-image-dom-paths.js +1 -1
  10. package/lib/crawler/crawler.js +6 -6
  11. package/lib/crawler/dedupe/build-dedupe-cap-observation.d.ts +3 -3
  12. package/lib/crawler/dedupe/build-dedupe-cap-observation.js +3 -3
  13. package/lib/crawler/dedupe/resolve-og-url-mismatch.d.ts +1 -1
  14. package/lib/crawler/dedupe/resolve-og-url-mismatch.js +1 -1
  15. package/lib/crawler/derive-page-source.d.ts +1 -1
  16. package/lib/crawler/derive-resource-source.d.ts +1 -1
  17. package/lib/crawler/destination-cache.d.ts +1 -1
  18. package/lib/crawler/detect-pagination-pattern.js +1 -1
  19. package/lib/crawler/dns-burned-host-cache.d.ts +1 -1
  20. package/lib/crawler/evict-network-classified-destination-cache-entries.js +2 -2
  21. package/lib/crawler/evict-outage-tainted-dns-burns.d.ts +2 -2
  22. package/lib/crawler/evict-outage-tainted-dns-burns.js +1 -1
  23. package/lib/crawler/fetch-robots-txt.js +1 -3
  24. package/lib/crawler/generate-predicted-urls.js +2 -2
  25. package/lib/crawler/handle-scrape-end.js +1 -1
  26. package/lib/crawler/is-external-url.js +1 -1
  27. package/lib/crawler/is-puppeteer-fallback-candidate.js +1 -1
  28. package/lib/crawler/link-list.js +1 -1
  29. package/lib/crawler/network-outage-detector.js +1 -1
  30. package/lib/crawler/plan-sub-resource-emits.d.ts +1 -1
  31. package/lib/crawler/resource-to-page-data.js +1 -1
  32. package/lib/crawler/scan-js-resource-for-license-comment.d.ts +4 -3
  33. package/lib/crawler/scan-js-resource-for-license-comment.js +11 -23
  34. package/lib/crawler/scan-js-resources-for-technology-signals.d.ts +1 -1
  35. package/lib/crawler/scan-js-resources-for-technology-signals.js +1 -1
  36. package/lib/crawler/should-burn-host.d.ts +1 -1
  37. package/lib/crawler/should-get-fallback-on-head-failure.js +1 -1
  38. package/lib/crawler/types.d.ts +4 -18
  39. package/lib/crawler-orchestrator.d.ts +6 -9
  40. package/lib/crawler-orchestrator.js +27 -30
  41. package/lib/crawler.d.ts +5 -58
  42. package/lib/crawler.js +10 -73
  43. package/lib/resolve-output-path.js +1 -1
  44. package/lib/resource-row-to-lookup-result.d.ts +1 -1
  45. package/lib/resource-row-to-lookup-result.js +1 -1
  46. package/lib/types.d.ts +4 -53
  47. package/lib/utils/types/types.d.ts +0 -15
  48. package/package.json +11 -18
  49. package/lib/archive/archive-accessor.d.ts +0 -274
  50. package/lib/archive/archive-accessor.js +0 -505
  51. package/lib/archive/archive-lock.d.ts +0 -45
  52. package/lib/archive/archive-lock.js +0 -154
  53. package/lib/archive/archive.d.ts +0 -762
  54. package/lib/archive/archive.js +0 -1073
  55. package/lib/archive/body-hash/compute-body-hash.d.ts +0 -22
  56. package/lib/archive/body-hash/compute-body-hash.js +0 -31
  57. package/lib/archive/body-hash/extract-body.d.ts +0 -18
  58. package/lib/archive/body-hash/extract-body.js +0 -29
  59. package/lib/archive/body-hash/mask-dynamic-ids.d.ts +0 -33
  60. package/lib/archive/body-hash/mask-dynamic-ids.js +0 -44
  61. package/lib/archive/body-hash/normalize-url-like-strings.d.ts +0 -16
  62. package/lib/archive/body-hash/normalize-url-like-strings.js +0 -19
  63. package/lib/archive/cache/clear-archive-cache-entry.d.ts +0 -19
  64. package/lib/archive/cache/clear-archive-cache-entry.js +0 -25
  65. package/lib/archive/cache/clear-archive-cache-root.d.ts +0 -26
  66. package/lib/archive/cache/clear-archive-cache-root.js +0 -32
  67. package/lib/archive/cache/compute-archive-cache-key.d.ts +0 -39
  68. package/lib/archive/cache/compute-archive-cache-key.js +0 -95
  69. package/lib/archive/cache/extract-archive-to-cache.d.ts +0 -57
  70. package/lib/archive/cache/extract-archive-to-cache.js +0 -326
  71. package/lib/archive/cache/get-archive-cache-root.d.ts +0 -20
  72. package/lib/archive/cache/get-archive-cache-root.js +0 -53
  73. package/lib/archive/cache/is-archive-cache-disabled.d.ts +0 -24
  74. package/lib/archive/cache/is-archive-cache-disabled.js +0 -34
  75. package/lib/archive/cache/list-archive-cache-entries.d.ts +0 -23
  76. package/lib/archive/cache/list-archive-cache-entries.js +0 -125
  77. package/lib/archive/cache/path-exists.d.ts +0 -9
  78. package/lib/archive/cache/path-exists.js +0 -18
  79. package/lib/archive/cache/resolve-archive-cache-dir.d.ts +0 -26
  80. package/lib/archive/cache/resolve-archive-cache-dir.js +0 -32
  81. package/lib/archive/cache/types.d.ts +0 -33
  82. package/lib/archive/create-adjunct-tables.d.ts +0 -68
  83. package/lib/archive/create-adjunct-tables.js +0 -548
  84. package/lib/archive/create-entity-tables.d.ts +0 -191
  85. package/lib/archive/create-entity-tables.js +0 -387
  86. package/lib/archive/create-progress-reporter.d.ts +0 -30
  87. package/lib/archive/create-progress-reporter.js +0 -38
  88. package/lib/archive/create-ref-tables.d.ts +0 -35
  89. package/lib/archive/create-ref-tables.js +0 -188
  90. package/lib/archive/create-template-tables.d.ts +0 -30
  91. package/lib/archive/create-template-tables.js +0 -95
  92. package/lib/archive/database.d.ts +0 -560
  93. package/lib/archive/database.js +0 -805
  94. package/lib/archive/db-ops/_shared/clear-write-ref-caches.d.ts +0 -27
  95. package/lib/archive/db-ops/_shared/clear-write-ref-caches.js +0 -35
  96. package/lib/archive/db-ops/_shared/compress-payload.d.ts +0 -26
  97. package/lib/archive/db-ops/_shared/compress-payload.js +0 -30
  98. package/lib/archive/db-ops/_shared/create-write-ref-caches.d.ts +0 -17
  99. package/lib/archive/db-ops/_shared/create-write-ref-caches.js +0 -27
  100. package/lib/archive/db-ops/_shared/decode-json-ref.d.ts +0 -17
  101. package/lib/archive/db-ops/_shared/decode-json-ref.js +0 -31
  102. package/lib/archive/db-ops/_shared/keyset-paginate-by-id.d.ts +0 -49
  103. package/lib/archive/db-ops/_shared/keyset-paginate-by-id.js +0 -69
  104. package/lib/archive/db-ops/_shared/load-response-headers-by-set-ids.d.ts +0 -20
  105. package/lib/archive/db-ops/_shared/load-response-headers-by-set-ids.js +0 -53
  106. package/lib/archive/db-ops/_shared/resolve-content-item-id.d.ts +0 -62
  107. package/lib/archive/db-ops/_shared/resolve-content-item-id.js +0 -143
  108. package/lib/archive/db-ops/_shared/resolve-url-or-blob.d.ts +0 -23
  109. package/lib/archive/db-ops/_shared/resolve-url-or-blob.js +0 -29
  110. package/lib/archive/db-ops/_shared/retry-setting.d.ts +0 -16
  111. package/lib/archive/db-ops/_shared/retry-setting.js +0 -18
  112. package/lib/archive/db-ops/_shared/safe-parse-json.d.ts +0 -11
  113. package/lib/archive/db-ops/_shared/safe-parse-json.js +0 -18
  114. package/lib/archive/db-ops/_shared/types.d.ts +0 -94
  115. package/lib/archive/db-ops/_shared/types.js +0 -1
  116. package/lib/archive/db-ops/_shared/upsert-blob-ref.d.ts +0 -25
  117. package/lib/archive/db-ops/_shared/upsert-blob-ref.js +0 -48
  118. package/lib/archive/db-ops/_shared/upsert-content-type-ref.d.ts +0 -30
  119. package/lib/archive/db-ops/_shared/upsert-content-type-ref.js +0 -45
  120. package/lib/archive/db-ops/_shared/upsert-json-ref.d.ts +0 -22
  121. package/lib/archive/db-ops/_shared/upsert-json-ref.js +0 -41
  122. package/lib/archive/db-ops/_shared/upsert-response-headers.d.ts +0 -35
  123. package/lib/archive/db-ops/_shared/upsert-response-headers.js +0 -49
  124. package/lib/archive/db-ops/_shared/upsert-url-ref.d.ts +0 -39
  125. package/lib/archive/db-ops/_shared/upsert-url-ref.js +0 -62
  126. package/lib/archive/db-ops/analysis/replace-analysis-violations.d.ts +0 -28
  127. package/lib/archive/db-ops/analysis/replace-analysis-violations.js +0 -155
  128. package/lib/archive/db-ops/anchors/get-anchors-on-page.d.ts +0 -10
  129. package/lib/archive/db-ops/anchors/get-anchors-on-page.js +0 -21
  130. package/lib/archive/db-ops/config/get-base-url.d.ts +0 -8
  131. package/lib/archive/db-ops/config/get-base-url.js +0 -14
  132. package/lib/archive/db-ops/config/get-config.d.ts +0 -10
  133. package/lib/archive/db-ops/config/get-config.js +0 -29
  134. package/lib/archive/db-ops/config/get-created-cwd.d.ts +0 -11
  135. package/lib/archive/db-ops/config/get-created-cwd.js +0 -13
  136. package/lib/archive/db-ops/config/get-name.d.ts +0 -8
  137. package/lib/archive/db-ops/config/get-name.js +0 -14
  138. package/lib/archive/db-ops/config/info-column-allowlist.d.ts +0 -7
  139. package/lib/archive/db-ops/config/info-column-allowlist.js +0 -29
  140. package/lib/archive/db-ops/config/info-json-columns.d.ts +0 -5
  141. package/lib/archive/db-ops/config/info-json-columns.js +0 -11
  142. package/lib/archive/db-ops/config/set-config.d.ts +0 -12
  143. package/lib/archive/db-ops/config/set-config.js +0 -21
  144. package/lib/archive/db-ops/config/update-config.d.ts +0 -17
  145. package/lib/archive/db-ops/config/update-config.js +0 -36
  146. package/lib/archive/db-ops/console-logs/compute-console-log-hash.d.ts +0 -19
  147. package/lib/archive/db-ops/console-logs/compute-console-log-hash.js +0 -30
  148. package/lib/archive/db-ops/console-logs/replace-console-logs.d.ts +0 -34
  149. package/lib/archive/db-ops/console-logs/replace-console-logs.js +0 -123
  150. package/lib/archive/db-ops/console-logs/stringify-console-log-args.d.ts +0 -16
  151. package/lib/archive/db-ops/console-logs/stringify-console-log-args.js +0 -26
  152. package/lib/archive/db-ops/console-logs/types.d.ts +0 -38
  153. package/lib/archive/db-ops/console-logs/types.js +0 -1
  154. package/lib/archive/db-ops/console-logs/upsert-console-log-item.d.ts +0 -29
  155. package/lib/archive/db-ops/console-logs/upsert-console-log-item.js +0 -52
  156. package/lib/archive/db-ops/dedupe-cap/accumulate-dedupe-cap-rejected-count.d.ts +0 -18
  157. package/lib/archive/db-ops/dedupe-cap/accumulate-dedupe-cap-rejected-count.js +0 -23
  158. package/lib/archive/db-ops/dedupe-cap/finalize-dedupe-cap-event.d.ts +0 -12
  159. package/lib/archive/db-ops/dedupe-cap/finalize-dedupe-cap-event.js +0 -15
  160. package/lib/archive/db-ops/dedupe-cap/insert-dedupe-cap-event.d.ts +0 -14
  161. package/lib/archive/db-ops/dedupe-cap/insert-dedupe-cap-event.js +0 -30
  162. package/lib/archive/db-ops/dedupe-cap/list-dedupe-cap-observations.d.ts +0 -57
  163. package/lib/archive/db-ops/dedupe-cap/list-dedupe-cap-observations.js +0 -87
  164. package/lib/archive/db-ops/dedupe-cap/list-dedupe-cap-shape-keys.d.ts +0 -21
  165. package/lib/archive/db-ops/dedupe-cap/list-dedupe-cap-shape-keys.js +0 -27
  166. package/lib/archive/db-ops/errors/insert-crawl-error.d.ts +0 -15
  167. package/lib/archive/db-ops/errors/insert-crawl-error.js +0 -21
  168. package/lib/archive/db-ops/errors/insert-page-error.d.ts +0 -21
  169. package/lib/archive/db-ops/errors/insert-page-error.js +0 -30
  170. package/lib/archive/db-ops/errors/list-dns-burned-host-candidates.d.ts +0 -33
  171. package/lib/archive/db-ops/errors/list-dns-burned-host-candidates.js +0 -158
  172. package/lib/archive/db-ops/html/get-html-of-page-by-id.d.ts +0 -18
  173. package/lib/archive/db-ops/html/get-html-of-page-by-id.js +0 -29
  174. package/lib/archive/db-ops/lifecycle/checkpoint.d.ts +0 -8
  175. package/lib/archive/db-ops/lifecycle/checkpoint.js +0 -9
  176. package/lib/archive/db-ops/lifecycle/destroy.d.ts +0 -6
  177. package/lib/archive/db-ops/lifecycle/destroy.js +0 -7
  178. package/lib/archive/db-ops/lifecycle/init.d.ts +0 -58
  179. package/lib/archive/db-ops/lifecycle/init.js +0 -121
  180. package/lib/archive/db-ops/list-reconcile/record-list-reconcile-run.d.ts +0 -22
  181. package/lib/archive/db-ops/list-reconcile/record-list-reconcile-run.js +0 -41
  182. package/lib/archive/db-ops/meta/get-audios-of-page.d.ts +0 -11
  183. package/lib/archive/db-ops/meta/get-audios-of-page.js +0 -15
  184. package/lib/archive/db-ops/meta/get-buttons-of-page.d.ts +0 -11
  185. package/lib/archive/db-ops/meta/get-buttons-of-page.js +0 -15
  186. package/lib/archive/db-ops/meta/get-canvases-of-page.d.ts +0 -11
  187. package/lib/archive/db-ops/meta/get-canvases-of-page.js +0 -15
  188. package/lib/archive/db-ops/meta/get-custom-elements-of-page.d.ts +0 -11
  189. package/lib/archive/db-ops/meta/get-custom-elements-of-page.js +0 -15
  190. package/lib/archive/db-ops/meta/get-headings-of-page.d.ts +0 -11
  191. package/lib/archive/db-ops/meta/get-headings-of-page.js +0 -15
  192. package/lib/archive/db-ops/meta/get-iframes-of-page.d.ts +0 -11
  193. package/lib/archive/db-ops/meta/get-iframes-of-page.js +0 -15
  194. package/lib/archive/db-ops/meta/get-jsonld-of-page.d.ts +0 -13
  195. package/lib/archive/db-ops/meta/get-jsonld-of-page.js +0 -27
  196. package/lib/archive/db-ops/meta/get-main-content-images-of-page.d.ts +0 -11
  197. package/lib/archive/db-ops/meta/get-main-content-images-of-page.js +0 -15
  198. package/lib/archive/db-ops/meta/get-main-content-tables-of-page.d.ts +0 -11
  199. package/lib/archive/db-ops/meta/get-main-content-tables-of-page.js +0 -15
  200. package/lib/archive/db-ops/meta/get-page-technologies-of-page.d.ts +0 -11
  201. package/lib/archive/db-ops/meta/get-page-technologies-of-page.js +0 -15
  202. package/lib/archive/db-ops/meta/get-technology-signals-of-page.d.ts +0 -11
  203. package/lib/archive/db-ops/meta/get-technology-signals-of-page.js +0 -15
  204. package/lib/archive/db-ops/meta/get-videos-of-page.d.ts +0 -11
  205. package/lib/archive/db-ops/meta/get-videos-of-page.js +0 -15
  206. package/lib/archive/db-ops/outages/close-network-outage.d.ts +0 -12
  207. package/lib/archive/db-ops/outages/close-network-outage.js +0 -15
  208. package/lib/archive/db-ops/outages/close-stale-open-network-outages.d.ts +0 -26
  209. package/lib/archive/db-ops/outages/close-stale-open-network-outages.js +0 -42
  210. package/lib/archive/db-ops/outages/compute-outage-clamp-timestamp.d.ts +0 -26
  211. package/lib/archive/db-ops/outages/compute-outage-clamp-timestamp.js +0 -31
  212. package/lib/archive/db-ops/outages/insert-network-outage.d.ts +0 -14
  213. package/lib/archive/db-ops/outages/insert-network-outage.js +0 -29
  214. package/lib/archive/db-ops/outages/list-network-outages.d.ts +0 -28
  215. package/lib/archive/db-ops/outages/list-network-outages.js +0 -42
  216. package/lib/archive/db-ops/pages/order/set-url-order.d.ts +0 -13
  217. package/lib/archive/db-ops/pages/order/set-url-order.js +0 -38
  218. package/lib/archive/db-ops/pages/read/build-page-query.d.ts +0 -18
  219. package/lib/archive/db-ops/pages/read/build-page-query.js +0 -40
  220. package/lib/archive/db-ops/pages/read/get-crawling-state.d.ts +0 -117
  221. package/lib/archive/db-ops/pages/read/get-crawling-state.js +0 -161
  222. package/lib/archive/db-ops/pages/read/get-existing-page-urls.d.ts +0 -15
  223. package/lib/archive/db-ops/pages/read/get-existing-page-urls.js +0 -30
  224. package/lib/archive/db-ops/pages/read/get-page-count.d.ts +0 -12
  225. package/lib/archive/db-ops/pages/read/get-page-count.js +0 -21
  226. package/lib/archive/db-ops/pages/read/get-page-source-by-url.d.ts +0 -24
  227. package/lib/archive/db-ops/pages/read/get-page-source-by-url.js +0 -28
  228. package/lib/archive/db-ops/pages/read/get-pages-with-rels.d.ts +0 -38
  229. package/lib/archive/db-ops/pages/read/get-pages-with-rels.js +0 -107
  230. package/lib/archive/db-ops/pages/read/get-pages.d.ts +0 -11
  231. package/lib/archive/db-ops/pages/read/get-pages.js +0 -51
  232. package/lib/archive/db-ops/pages/read/get-scraped-html-page-count.d.ts +0 -18
  233. package/lib/archive/db-ops/pages/read/get-scraped-html-page-count.js +0 -25
  234. package/lib/archive/db-ops/pages/read/reconstruct-page-rows.d.ts +0 -31
  235. package/lib/archive/db-ops/pages/read/reconstruct-page-rows.js +0 -32
  236. package/lib/archive/db-ops/pages/reset/clear-page-derived-rows.d.ts +0 -20
  237. package/lib/archive/db-ops/pages/reset/clear-page-derived-rows.js +0 -37
  238. package/lib/archive/db-ops/pages/reset/repromote-external-pages.d.ts +0 -30
  239. package/lib/archive/db-ops/pages/reset/repromote-external-pages.js +0 -91
  240. package/lib/archive/db-ops/pages/reset/reset-failed-pages.d.ts +0 -88
  241. package/lib/archive/db-ops/pages/reset/reset-failed-pages.js +0 -216
  242. package/lib/archive/db-ops/pages/reset/reset-pages-by-urls.d.ts +0 -78
  243. package/lib/archive/db-ops/pages/reset/reset-pages-by-urls.js +0 -146
  244. package/lib/archive/db-ops/pages/reset/retryable-image-scan-codes.d.ts +0 -24
  245. package/lib/archive/db-ops/pages/reset/retryable-image-scan-codes.js +0 -24
  246. package/lib/archive/db-ops/pages/write/insert-audios.d.ts +0 -14
  247. package/lib/archive/db-ops/pages/write/insert-audios.js +0 -25
  248. package/lib/archive/db-ops/pages/write/insert-buttons.d.ts +0 -14
  249. package/lib/archive/db-ops/pages/write/insert-buttons.js +0 -29
  250. package/lib/archive/db-ops/pages/write/insert-canvases.d.ts +0 -14
  251. package/lib/archive/db-ops/pages/write/insert-canvases.js +0 -26
  252. package/lib/archive/db-ops/pages/write/insert-custom-elements.d.ts +0 -27
  253. package/lib/archive/db-ops/pages/write/insert-custom-elements.js +0 -40
  254. package/lib/archive/db-ops/pages/write/insert-headings.d.ts +0 -15
  255. package/lib/archive/db-ops/pages/write/insert-headings.js +0 -27
  256. package/lib/archive/db-ops/pages/write/insert-iframes.d.ts +0 -14
  257. package/lib/archive/db-ops/pages/write/insert-iframes.js +0 -28
  258. package/lib/archive/db-ops/pages/write/insert-inventory-content-items.d.ts +0 -38
  259. package/lib/archive/db-ops/pages/write/insert-inventory-content-items.js +0 -60
  260. package/lib/archive/db-ops/pages/write/insert-inventory-seeds.d.ts +0 -36
  261. package/lib/archive/db-ops/pages/write/insert-inventory-seeds.js +0 -48
  262. package/lib/archive/db-ops/pages/write/insert-inventory-skipped-pages.d.ts +0 -42
  263. package/lib/archive/db-ops/pages/write/insert-inventory-skipped-pages.js +0 -56
  264. package/lib/archive/db-ops/pages/write/insert-jsonld.d.ts +0 -17
  265. package/lib/archive/db-ops/pages/write/insert-jsonld.js +0 -49
  266. package/lib/archive/db-ops/pages/write/insert-main-content-images.d.ts +0 -20
  267. package/lib/archive/db-ops/pages/write/insert-main-content-images.js +0 -32
  268. package/lib/archive/db-ops/pages/write/insert-main-content-tables.d.ts +0 -14
  269. package/lib/archive/db-ops/pages/write/insert-main-content-tables.js +0 -29
  270. package/lib/archive/db-ops/pages/write/insert-page.d.ts +0 -56
  271. package/lib/archive/db-ops/pages/write/insert-page.js +0 -259
  272. package/lib/archive/db-ops/pages/write/insert-technologies.d.ts +0 -25
  273. package/lib/archive/db-ops/pages/write/insert-technologies.js +0 -45
  274. package/lib/archive/db-ops/pages/write/insert-videos.d.ts +0 -14
  275. package/lib/archive/db-ops/pages/write/insert-videos.js +0 -28
  276. package/lib/archive/db-ops/pages/write/link-redirect-sources.d.ts +0 -42
  277. package/lib/archive/db-ops/pages/write/link-redirect-sources.js +0 -101
  278. package/lib/archive/db-ops/pages/write/record-redirect.d.ts +0 -35
  279. package/lib/archive/db-ops/pages/write/record-redirect.js +0 -100
  280. package/lib/archive/db-ops/pages/write/set-skipped-page.d.ts +0 -13
  281. package/lib/archive/db-ops/pages/write/set-skipped-page.js +0 -24
  282. package/lib/archive/db-ops/pages/write/update-page.d.ts +0 -40
  283. package/lib/archive/db-ops/pages/write/update-page.js +0 -419
  284. package/lib/archive/db-ops/pages/write/write-page-html-blob.d.ts +0 -19
  285. package/lib/archive/db-ops/pages/write/write-page-html-blob.js +0 -41
  286. package/lib/archive/db-ops/referrers/get-redirects-for-pages.d.ts +0 -9
  287. package/lib/archive/db-ops/referrers/get-redirects-for-pages.js +0 -15
  288. package/lib/archive/db-ops/referrers/get-referrers-of-page.d.ts +0 -17
  289. package/lib/archive/db-ops/referrers/get-referrers-of-page.js +0 -32
  290. package/lib/archive/db-ops/referrers/get-referrers-of-resource.d.ts +0 -8
  291. package/lib/archive/db-ops/referrers/get-referrers-of-resource.js +0 -15
  292. package/lib/archive/db-ops/resources/build-resource-query.d.ts +0 -25
  293. package/lib/archive/db-ops/resources/build-resource-query.js +0 -29
  294. package/lib/archive/db-ops/resources/get-existing-resource-urls.d.ts +0 -9
  295. package/lib/archive/db-ops/resources/get-existing-resource-urls.js +0 -24
  296. package/lib/archive/db-ops/resources/get-resource-by-url.d.ts +0 -13
  297. package/lib/archive/db-ops/resources/get-resource-by-url.js +0 -22
  298. package/lib/archive/db-ops/resources/get-resource-url-list.d.ts +0 -17
  299. package/lib/archive/db-ops/resources/get-resource-url-list.js +0 -26
  300. package/lib/archive/db-ops/resources/get-resources.d.ts +0 -8
  301. package/lib/archive/db-ops/resources/get-resources.js +0 -11
  302. package/lib/archive/db-ops/resources/insert-inventory-resources.d.ts +0 -24
  303. package/lib/archive/db-ops/resources/insert-inventory-resources.js +0 -64
  304. package/lib/archive/db-ops/resources/insert-resource-referrers.d.ts +0 -15
  305. package/lib/archive/db-ops/resources/insert-resource-referrers.js +0 -54
  306. package/lib/archive/db-ops/resources/insert-resource.d.ts +0 -34
  307. package/lib/archive/db-ops/resources/insert-resource.js +0 -73
  308. package/lib/archive/db-ops/resources/reconstruct-resource-rows.d.ts +0 -26
  309. package/lib/archive/db-ops/resources/reconstruct-resource-rows.js +0 -30
  310. package/lib/archive/db-ops/templates/assign-template-labels.d.ts +0 -60
  311. package/lib/archive/db-ops/templates/assign-template-labels.js +0 -187
  312. package/lib/archive/db-ops/templates/replace-page-templates.d.ts +0 -45
  313. package/lib/archive/db-ops/templates/replace-page-templates.js +0 -174
  314. package/lib/archive/db-ops/templates/types.d.ts +0 -99
  315. package/lib/archive/db-ops/templates/types.js +0 -1
  316. package/lib/archive/debug.d.ts +0 -8
  317. package/lib/archive/debug.js +0 -9
  318. package/lib/archive/decode-html-blob.d.ts +0 -18
  319. package/lib/archive/decode-html-blob.js +0 -31
  320. package/lib/archive/derive-lineage-from-parent.d.ts +0 -37
  321. package/lib/archive/derive-lineage-from-parent.js +0 -42
  322. package/lib/archive/drop-legacy-tables.d.ts +0 -45
  323. package/lib/archive/drop-legacy-tables.js +0 -56
  324. package/lib/archive/filesystem/append-text.d.ts +0 -9
  325. package/lib/archive/filesystem/append-text.js +0 -14
  326. package/lib/archive/filesystem/copy-dir-sync.d.ts +0 -6
  327. package/lib/archive/filesystem/copy-dir-sync.js +0 -9
  328. package/lib/archive/filesystem/copy-dir.d.ts +0 -7
  329. package/lib/archive/filesystem/copy-dir.js +0 -13
  330. package/lib/archive/filesystem/copy-file-with-progress.d.ts +0 -20
  331. package/lib/archive/filesystem/copy-file-with-progress.js +0 -34
  332. package/lib/archive/filesystem/exists.d.ts +0 -6
  333. package/lib/archive/filesystem/exists.js +0 -9
  334. package/lib/archive/filesystem/get-file-list.d.ts +0 -8
  335. package/lib/archive/filesystem/get-file-list.js +0 -12
  336. package/lib/archive/filesystem/is-dir.d.ts +0 -6
  337. package/lib/archive/filesystem/is-dir.js +0 -10
  338. package/lib/archive/filesystem/mkdir.d.ts +0 -8
  339. package/lib/archive/filesystem/mkdir.js +0 -15
  340. package/lib/archive/filesystem/output-binary.d.ts +0 -12
  341. package/lib/archive/filesystem/output-binary.js +0 -17
  342. package/lib/archive/filesystem/output-json.d.ts +0 -9
  343. package/lib/archive/filesystem/output-json.js +0 -14
  344. package/lib/archive/filesystem/output-text.d.ts +0 -11
  345. package/lib/archive/filesystem/output-text.js +0 -32
  346. package/lib/archive/filesystem/parse-pax-path.d.ts +0 -18
  347. package/lib/archive/filesystem/parse-pax-path.js +0 -47
  348. package/lib/archive/filesystem/parse-tar-size-field.d.ts +0 -13
  349. package/lib/archive/filesystem/parse-tar-size-field.js +0 -40
  350. package/lib/archive/filesystem/peek-tar-top-dir.d.ts +0 -35
  351. package/lib/archive/filesystem/peek-tar-top-dir.js +0 -215
  352. package/lib/archive/filesystem/read-json.d.ts +0 -7
  353. package/lib/archive/filesystem/read-json.js +0 -11
  354. package/lib/archive/filesystem/read-text.d.ts +0 -6
  355. package/lib/archive/filesystem/read-text.js +0 -10
  356. package/lib/archive/filesystem/readline.d.ts +0 -11
  357. package/lib/archive/filesystem/readline.js +0 -26
  358. package/lib/archive/filesystem/remove.d.ts +0 -5
  359. package/lib/archive/filesystem/remove.js +0 -10
  360. package/lib/archive/filesystem/rename.d.ts +0 -16
  361. package/lib/archive/filesystem/rename.js +0 -48
  362. package/lib/archive/filesystem/tar.d.ts +0 -23
  363. package/lib/archive/filesystem/tar.js +0 -78
  364. package/lib/archive/filesystem/untar.d.ts +0 -33
  365. package/lib/archive/filesystem/untar.js +0 -84
  366. package/lib/archive/get-failed-page-messages.d.ts +0 -56
  367. package/lib/archive/get-failed-page-messages.js +0 -146
  368. package/lib/archive/get-json.d.ts +0 -10
  369. package/lib/archive/get-json.js +0 -25
  370. package/lib/archive/init-schema.d.ts +0 -59
  371. package/lib/archive/init-schema.js +0 -158
  372. package/lib/archive/is-inventory-source.d.ts +0 -21
  373. package/lib/archive/is-inventory-source.js +0 -22
  374. package/lib/archive/libsql-dialect.d.ts +0 -25
  375. package/lib/archive/libsql-dialect.js +0 -28
  376. package/lib/archive/limited-page-ids.d.ts +0 -9
  377. package/lib/archive/limited-page-ids.js +0 -18
  378. package/lib/archive/meta/assert-compatible-version.d.ts +0 -60
  379. package/lib/archive/meta/assert-compatible-version.js +0 -93
  380. package/lib/archive/meta/classify-jsonld-type.d.ts +0 -23
  381. package/lib/archive/meta/classify-jsonld-type.js +0 -43
  382. package/lib/archive/meta/compare-semver.d.ts +0 -23
  383. package/lib/archive/meta/compare-semver.js +0 -51
  384. package/lib/archive/meta/compute-main-contents-denormalized.d.ts +0 -41
  385. package/lib/archive/meta/compute-main-contents-denormalized.js +0 -88
  386. package/lib/archive/meta/compute-page-denormalized.d.ts +0 -21
  387. package/lib/archive/meta/compute-page-denormalized.js +0 -35
  388. package/lib/archive/meta/derive-flat-from-meta.d.ts +0 -35
  389. package/lib/archive/meta/derive-flat-from-meta.js +0 -158
  390. package/lib/archive/meta/derive-meta-extras.d.ts +0 -20
  391. package/lib/archive/meta/derive-meta-extras.js +0 -23
  392. package/lib/archive/meta/extract-tags-for-archive.d.ts +0 -18
  393. package/lib/archive/meta/extract-tags-for-archive.js +0 -36
  394. package/lib/archive/meta/summarize-jsonld.d.ts +0 -17
  395. package/lib/archive/meta/summarize-jsonld.js +0 -29
  396. package/lib/archive/meta/technologies/combine-technology-confidence.d.ts +0 -46
  397. package/lib/archive/meta/technologies/combine-technology-confidence.js +0 -93
  398. package/lib/archive/meta/technologies/convert-legacy-page-tags-to-inserts.d.ts +0 -45
  399. package/lib/archive/meta/technologies/convert-legacy-page-tags-to-inserts.js +0 -53
  400. package/lib/archive/meta/technologies/convert-tag-row-to-wappalyzer-signal.d.ts +0 -33
  401. package/lib/archive/meta/technologies/convert-tag-row-to-wappalyzer-signal.js +0 -46
  402. package/lib/archive/meta/technologies/extract-technologies-for-archive.d.ts +0 -30
  403. package/lib/archive/meta/technologies/extract-technologies-for-archive.js +0 -27
  404. package/lib/archive/meta/technologies/match-structural-technology-signals.d.ts +0 -13
  405. package/lib/archive/meta/technologies/match-structural-technology-signals.js +0 -44
  406. package/lib/archive/meta/technologies/normalize-wappalyzer-entries.d.ts +0 -25
  407. package/lib/archive/meta/technologies/normalize-wappalyzer-entries.js +0 -35
  408. package/lib/archive/meta/technologies/technology-signal-definitions.d.ts +0 -43
  409. package/lib/archive/meta/technologies/technology-signal-definitions.js +0 -193
  410. package/lib/archive/meta/technologies/types.d.ts +0 -68
  411. package/lib/archive/meta/technologies/types.js +0 -13
  412. package/lib/archive/meta/types.d.ts +0 -647
  413. package/lib/archive/meta/types.js +0 -65
  414. package/lib/archive/migrate-content-items-alias-of-id.d.ts +0 -52
  415. package/lib/archive/migrate-content-items-alias-of-id.js +0 -69
  416. package/lib/archive/migrate-content-items-dedupe-cap-event-id.d.ts +0 -46
  417. package/lib/archive/migrate-content-items-dedupe-cap-event-id.js +0 -62
  418. package/lib/archive/migrate-content-items-is-metadata-only.d.ts +0 -44
  419. package/lib/archive/migrate-content-items-is-metadata-only.js +0 -60
  420. package/lib/archive/migrate-entity-tables.d.ts +0 -55
  421. package/lib/archive/migrate-entity-tables.js +0 -66
  422. package/lib/archive/migrate-info-created-cwd.d.ts +0 -17
  423. package/lib/archive/migrate-info-created-cwd.js +0 -36
  424. package/lib/archive/migrate-info-main-content-selector.d.ts +0 -16
  425. package/lib/archive/migrate-info-main-content-selector.js +0 -35
  426. package/lib/archive/migrate-info-request-header-names.d.ts +0 -16
  427. package/lib/archive/migrate-info-request-header-names.js +0 -35
  428. package/lib/archive/migrate-info-roots.d.ts +0 -20
  429. package/lib/archive/migrate-info-roots.js +0 -52
  430. package/lib/archive/migrate-inventory-runs-to-list-reconcile-runs.d.ts +0 -34
  431. package/lib/archive/migrate-inventory-runs-to-list-reconcile-runs.js +0 -51
  432. package/lib/archive/migrate-list-reconcile-runs-exclude-skipped.d.ts +0 -25
  433. package/lib/archive/migrate-list-reconcile-runs-exclude-skipped.js +0 -44
  434. package/lib/archive/migrate-list-reconcile-runs-invalid-skipped.d.ts +0 -16
  435. package/lib/archive/migrate-list-reconcile-runs-invalid-skipped.js +0 -35
  436. package/lib/archive/migrate-main-contents-columns.d.ts +0 -26
  437. package/lib/archive/migrate-main-contents-columns.js +0 -61
  438. package/lib/archive/migrate-page-meta-body-hash.d.ts +0 -44
  439. package/lib/archive/migrate-page-meta-body-hash.js +0 -63
  440. package/lib/archive/migrate-page-meta-console-error-count.d.ts +0 -27
  441. package/lib/archive/migrate-page-meta-console-error-count.js +0 -45
  442. package/lib/archive/migrate-page-meta-custom-element-count.d.ts +0 -33
  443. package/lib/archive/migrate-page-meta-custom-element-count.js +0 -51
  444. package/lib/archive/migrate-page-meta-image-scan.d.ts +0 -27
  445. package/lib/archive/migrate-page-meta-image-scan.js +0 -52
  446. package/lib/archive/migrate-page-tags-to-page-technologies.d.ts +0 -39
  447. package/lib/archive/migrate-page-tags-to-page-technologies.js +0 -79
  448. package/lib/archive/migrate-ref-tables.d.ts +0 -25
  449. package/lib/archive/migrate-ref-tables.js +0 -38
  450. package/lib/archive/page-meta-column-maps.d.ts +0 -32
  451. package/lib/archive/page-meta-column-maps.js +0 -43
  452. package/lib/archive/page.d.ts +0 -532
  453. package/lib/archive/page.js +0 -750
  454. package/lib/archive/peek-archive-lock.d.ts +0 -40
  455. package/lib/archive/peek-archive-lock.js +0 -62
  456. package/lib/archive/populate-entity-tables/collapse-anchor-rows.d.ts +0 -41
  457. package/lib/archive/populate-entity-tables/collapse-anchor-rows.js +0 -87
  458. package/lib/archive/populate-entity-tables/derive-dom-path.d.ts +0 -35
  459. package/lib/archive/populate-entity-tables/derive-dom-path.js +0 -72
  460. package/lib/archive/populate-entity-tables/is-blob-ref-value.d.ts +0 -16
  461. package/lib/archive/populate-entity-tables/is-blob-ref-value.js +0 -19
  462. package/lib/archive/populate-entity-tables/match-images-to-dom-paths.d.ts +0 -66
  463. package/lib/archive/populate-entity-tables/match-images-to-dom-paths.js +0 -96
  464. package/lib/archive/populate-entity-tables/populate-anchor-edges.d.ts +0 -33
  465. package/lib/archive/populate-entity-tables/populate-anchor-edges.js +0 -153
  466. package/lib/archive/populate-entity-tables/populate-content-items.d.ts +0 -40
  467. package/lib/archive/populate-entity-tables/populate-content-items.js +0 -141
  468. package/lib/archive/populate-entity-tables/populate-entities.d.ts +0 -81
  469. package/lib/archive/populate-entity-tables/populate-entities.js +0 -111
  470. package/lib/archive/populate-entity-tables/populate-image-items.d.ts +0 -91
  471. package/lib/archive/populate-entity-tables/populate-image-items.js +0 -223
  472. package/lib/archive/populate-entity-tables/populate-page-meta.d.ts +0 -33
  473. package/lib/archive/populate-entity-tables/populate-page-meta.js +0 -267
  474. package/lib/archive/populate-entity-tables/populate-resource-items.d.ts +0 -22
  475. package/lib/archive/populate-entity-tables/populate-resource-items.js +0 -114
  476. package/lib/archive/populate-entity-tables/populate-resource-ref-edges.d.ts +0 -31
  477. package/lib/archive/populate-entity-tables/populate-resource-ref-edges.js +0 -33
  478. package/lib/archive/populate-entity-tables/resolve-blob-refs.d.ts +0 -31
  479. package/lib/archive/populate-entity-tables/resolve-blob-refs.js +0 -100
  480. package/lib/archive/populate-entity-tables/resolve-content-type-refs.d.ts +0 -22
  481. package/lib/archive/populate-entity-tables/resolve-content-type-refs.js +0 -27
  482. package/lib/archive/populate-entity-tables/resolve-header-sets.d.ts +0 -49
  483. package/lib/archive/populate-entity-tables/resolve-header-sets.js +0 -122
  484. package/lib/archive/populate-entity-tables/resolve-json-refs.d.ts +0 -25
  485. package/lib/archive/populate-entity-tables/resolve-json-refs.js +0 -67
  486. package/lib/archive/populate-entity-tables/resolve-text-refs.d.ts +0 -30
  487. package/lib/archive/populate-entity-tables/resolve-text-refs.js +0 -61
  488. package/lib/archive/populate-entity-tables/resolve-url-or-blob-from-maps.d.ts +0 -21
  489. package/lib/archive/populate-entity-tables/resolve-url-or-blob-from-maps.js +0 -27
  490. package/lib/archive/populate-entity-tables/resolve-url-refs.d.ts +0 -33
  491. package/lib/archive/populate-entity-tables/resolve-url-refs.js +0 -60
  492. package/lib/archive/populate-entity-tables/test-utils/count-rows.d.ts +0 -17
  493. package/lib/archive/populate-entity-tables/test-utils/count-rows.js +0 -20
  494. package/lib/archive/populate-entity-tables/test-utils/seed-content-items.d.ts +0 -25
  495. package/lib/archive/populate-entity-tables/test-utils/seed-content-items.js +0 -42
  496. package/lib/archive/populate-entity-tables/test-utils/setup-entities-db.d.ts +0 -30
  497. package/lib/archive/populate-entity-tables/test-utils/setup-entities-db.js +0 -187
  498. package/lib/archive/populate-entity-tables/types.d.ts +0 -157
  499. package/lib/archive/populate-entity-tables/types.js +0 -12
  500. package/lib/archive/populate-entity-tables/upsert-text-refs.d.ts +0 -38
  501. package/lib/archive/populate-entity-tables/upsert-text-refs.js +0 -78
  502. package/lib/archive/populate-ref-tables/classify-content-type.d.ts +0 -16
  503. package/lib/archive/populate-ref-tables/classify-content-type.js +0 -52
  504. package/lib/archive/populate-ref-tables/compute-content-hash.d.ts +0 -22
  505. package/lib/archive/populate-ref-tables/compute-content-hash.js +0 -26
  506. package/lib/archive/populate-ref-tables/compute-header-flags.d.ts +0 -16
  507. package/lib/archive/populate-ref-tables/compute-header-flags.js +0 -70
  508. package/lib/archive/populate-ref-tables/content-type-rules.d.ts +0 -38
  509. package/lib/archive/populate-ref-tables/content-type-rules.js +0 -133
  510. package/lib/archive/populate-ref-tables/create-header-table-caches.d.ts +0 -25
  511. package/lib/archive/populate-ref-tables/create-header-table-caches.js +0 -49
  512. package/lib/archive/populate-ref-tables/data-uri-url-refs-limit.d.ts +0 -15
  513. package/lib/archive/populate-ref-tables/data-uri-url-refs-limit.js +0 -15
  514. package/lib/archive/populate-ref-tables/decode-data-uri.d.ts +0 -21
  515. package/lib/archive/populate-ref-tables/decode-data-uri.js +0 -126
  516. package/lib/archive/populate-ref-tables/decompose-header-set.d.ts +0 -29
  517. package/lib/archive/populate-ref-tables/decompose-header-set.js +0 -157
  518. package/lib/archive/populate-ref-tables/decompose-url.d.ts +0 -25
  519. package/lib/archive/populate-ref-tables/decompose-url.js +0 -70
  520. package/lib/archive/populate-ref-tables/header-stability.d.ts +0 -19
  521. package/lib/archive/populate-ref-tables/header-stability.js +0 -22
  522. package/lib/archive/populate-ref-tables/header-value-cache-key.d.ts +0 -17
  523. package/lib/archive/populate-ref-tables/header-value-cache-key.js +0 -19
  524. package/lib/archive/populate-ref-tables/normalize-mime.d.ts +0 -24
  525. package/lib/archive/populate-ref-tables/normalize-mime.js +0 -36
  526. package/lib/archive/populate-ref-tables/populate-blob-refs.d.ts +0 -38
  527. package/lib/archive/populate-ref-tables/populate-blob-refs.js +0 -134
  528. package/lib/archive/populate-ref-tables/populate-content-type-refs.d.ts +0 -27
  529. package/lib/archive/populate-ref-tables/populate-content-type-refs.js +0 -70
  530. package/lib/archive/populate-ref-tables/populate-header-tables.d.ts +0 -35
  531. package/lib/archive/populate-ref-tables/populate-header-tables.js +0 -80
  532. package/lib/archive/populate-ref-tables/populate-json-refs.d.ts +0 -29
  533. package/lib/archive/populate-ref-tables/populate-json-refs.js +0 -101
  534. package/lib/archive/populate-ref-tables/populate-refs.d.ts +0 -51
  535. package/lib/archive/populate-ref-tables/populate-refs.js +0 -62
  536. package/lib/archive/populate-ref-tables/populate-text-refs.d.ts +0 -32
  537. package/lib/archive/populate-ref-tables/populate-text-refs.js +0 -133
  538. package/lib/archive/populate-ref-tables/populate-url-refs.d.ts +0 -28
  539. package/lib/archive/populate-ref-tables/populate-url-refs.js +0 -148
  540. package/lib/archive/populate-ref-tables/test-utils/count-rows.d.ts +0 -15
  541. package/lib/archive/populate-ref-tables/test-utils/count-rows.js +0 -17
  542. package/lib/archive/populate-ref-tables/types.d.ts +0 -197
  543. package/lib/archive/populate-ref-tables/types.js +0 -7
  544. package/lib/archive/populate-ref-tables/upsert-one-header-set.d.ts +0 -34
  545. package/lib/archive/populate-ref-tables/upsert-one-header-set.js +0 -208
  546. package/lib/archive/populate-ref-tables/volatile-header-names.d.ts +0 -20
  547. package/lib/archive/populate-ref-tables/volatile-header-names.js +0 -33
  548. package/lib/archive/redirect-table.d.ts +0 -9
  549. package/lib/archive/redirect-table.js +0 -28
  550. package/lib/archive/resolve-redirect-chain.d.ts +0 -33
  551. package/lib/archive/resolve-redirect-chain.js +0 -27
  552. package/lib/archive/resource.d.ts +0 -46
  553. package/lib/archive/resource.js +0 -62
  554. package/lib/archive/retarget-legacy-fk-tables.d.ts +0 -60
  555. package/lib/archive/retarget-legacy-fk-tables.js +0 -153
  556. package/lib/archive/safe-path.d.ts +0 -9
  557. package/lib/archive/safe-path.js +0 -17
  558. package/lib/archive/test-utils/build-full-schema-test-db.d.ts +0 -34
  559. package/lib/archive/test-utils/build-full-schema-test-db.js +0 -74
  560. package/lib/archive/test-utils/fk-parent-tables.d.ts +0 -15
  561. package/lib/archive/test-utils/fk-parent-tables.js +0 -19
  562. package/lib/archive/test-utils/seed-content-item.d.ts +0 -35
  563. package/lib/archive/test-utils/seed-content-item.js +0 -42
  564. package/lib/archive/test-utils/setup-legacy-fk-db.d.ts +0 -33
  565. package/lib/archive/test-utils/setup-legacy-fk-db.js +0 -270
  566. package/lib/archive/transfer/attach-source-database.d.ts +0 -31
  567. package/lib/archive/transfer/attach-source-database.js +0 -40
  568. package/lib/archive/transfer/build-split-config.d.ts +0 -30
  569. package/lib/archive/transfer/build-split-config.js +0 -42
  570. package/lib/archive/transfer/clear-replaced-page-rows.d.ts +0 -20
  571. package/lib/archive/transfer/clear-replaced-page-rows.js +0 -57
  572. package/lib/archive/transfer/concat-archives.d.ts +0 -55
  573. package/lib/archive/transfer/concat-archives.js +0 -95
  574. package/lib/archive/transfer/content-item-rank-sql.d.ts +0 -21
  575. package/lib/archive/transfer/content-item-rank-sql.js +0 -23
  576. package/lib/archive/transfer/copy-analysis-violations.d.ts +0 -19
  577. package/lib/archive/transfer/copy-analysis-violations.js +0 -43
  578. package/lib/archive/transfer/copy-anchor-edges.d.ts +0 -28
  579. package/lib/archive/transfer/copy-anchor-edges.js +0 -42
  580. package/lib/archive/transfer/copy-dictionaries-for-concat.d.ts +0 -39
  581. package/lib/archive/transfer/copy-dictionaries-for-concat.js +0 -81
  582. package/lib/archive/transfer/copy-dictionaries-for-split.d.ts +0 -29
  583. package/lib/archive/transfer/copy-dictionaries-for-split.js +0 -235
  584. package/lib/archive/transfer/copy-header-set-children.d.ts +0 -27
  585. package/lib/archive/transfer/copy-header-set-children.js +0 -51
  586. package/lib/archive/transfer/copy-image-items.d.ts +0 -21
  587. package/lib/archive/transfer/copy-image-items.js +0 -62
  588. package/lib/archive/transfer/copy-inventory-source-lists.d.ts +0 -30
  589. package/lib/archive/transfer/copy-inventory-source-lists.js +0 -61
  590. package/lib/archive/transfer/copy-journal-tables.d.ts +0 -30
  591. package/lib/archive/transfer/copy-journal-tables.js +0 -56
  592. package/lib/archive/transfer/copy-page-console-logs.d.ts +0 -16
  593. package/lib/archive/transfer/copy-page-console-logs.js +0 -27
  594. package/lib/archive/transfer/copy-page-html-blobs.d.ts +0 -31
  595. package/lib/archive/transfer/copy-page-html-blobs.js +0 -43
  596. package/lib/archive/transfer/copy-page-meta.d.ts +0 -27
  597. package/lib/archive/transfer/copy-page-meta.js +0 -68
  598. package/lib/archive/transfer/copy-page-template-clusters.d.ts +0 -31
  599. package/lib/archive/transfer/copy-page-template-clusters.js +0 -56
  600. package/lib/archive/transfer/copy-page-template-labels.d.ts +0 -34
  601. package/lib/archive/transfer/copy-page-template-labels.js +0 -88
  602. package/lib/archive/transfer/copy-resource-items.d.ts +0 -29
  603. package/lib/archive/transfer/copy-resource-items.js +0 -89
  604. package/lib/archive/transfer/copy-resource-ref-edges.d.ts +0 -20
  605. package/lib/archive/transfer/copy-resource-ref-edges.js +0 -33
  606. package/lib/archive/transfer/copy-simple-page-scoped-tables.d.ts +0 -15
  607. package/lib/archive/transfer/copy-simple-page-scoped-tables.js +0 -34
  608. package/lib/archive/transfer/count-external-pages-in-scope.d.ts +0 -26
  609. package/lib/archive/transfer/count-external-pages-in-scope.js +0 -40
  610. package/lib/archive/transfer/create-transfer-temp-tables.d.ts +0 -30
  611. package/lib/archive/transfer/create-transfer-temp-tables.js +0 -59
  612. package/lib/archive/transfer/dictionary-copy-specs.d.ts +0 -32
  613. package/lib/archive/transfer/dictionary-copy-specs.js +0 -29
  614. package/lib/archive/transfer/drop-transfer-temp-tables.d.ts +0 -9
  615. package/lib/archive/transfer/drop-transfer-temp-tables.js +0 -18
  616. package/lib/archive/transfer/flatten-redirect-chains.d.ts +0 -44
  617. package/lib/archive/transfer/flatten-redirect-chains.js +0 -74
  618. package/lib/archive/transfer/insert-content-items.d.ts +0 -35
  619. package/lib/archive/transfer/insert-content-items.js +0 -116
  620. package/lib/archive/transfer/list-transfer-columns.d.ts +0 -35
  621. package/lib/archive/transfer/list-transfer-columns.js +0 -45
  622. package/lib/archive/transfer/mark-in-scope-content-items.d.ts +0 -31
  623. package/lib/archive/transfer/mark-in-scope-content-items.js +0 -54
  624. package/lib/archive/transfer/merge-archive-configs.d.ts +0 -51
  625. package/lib/archive/transfer/merge-archive-configs.js +0 -85
  626. package/lib/archive/transfer/plan-content-items-for-concat.d.ts +0 -33
  627. package/lib/archive/transfer/plan-content-items-for-concat.js +0 -51
  628. package/lib/archive/transfer/plan-content-items-for-split.d.ts +0 -42
  629. package/lib/archive/transfer/plan-content-items-for-split.js +0 -83
  630. package/lib/archive/transfer/plan-resource-items.d.ts +0 -40
  631. package/lib/archive/transfer/plan-resource-items.js +0 -69
  632. package/lib/archive/transfer/quote-transfer-identifier.d.ts +0 -18
  633. package/lib/archive/transfer/quote-transfer-identifier.js +0 -20
  634. package/lib/archive/transfer/reclassify-resource-externality.d.ts +0 -37
  635. package/lib/archive/transfer/reclassify-resource-externality.js +0 -66
  636. package/lib/archive/transfer/remap-redirect-dest-ids.d.ts +0 -34
  637. package/lib/archive/transfer/remap-redirect-dest-ids.js +0 -51
  638. package/lib/archive/transfer/replace-content-items.d.ts +0 -39
  639. package/lib/archive/transfer/replace-content-items.js +0 -83
  640. package/lib/archive/transfer/simple-page-scoped-tables.d.ts +0 -25
  641. package/lib/archive/transfer/simple-page-scoped-tables.js +0 -38
  642. package/lib/archive/transfer/split-archive.d.ts +0 -55
  643. package/lib/archive/transfer/split-archive.js +0 -98
  644. package/lib/archive/transfer/transfer-action.d.ts +0 -34
  645. package/lib/archive/transfer/transfer-action.js +0 -32
  646. package/lib/archive/transfer/transfer-archive-rows.d.ts +0 -65
  647. package/lib/archive/transfer/transfer-archive-rows.js +0 -158
  648. package/lib/archive/transfer/transfer-dictionary-tables.d.ts +0 -12
  649. package/lib/archive/transfer/transfer-dictionary-tables.js +0 -23
  650. package/lib/archive/transfer/transfer-source-alias.d.ts +0 -9
  651. package/lib/archive/transfer/transfer-source-alias.js +0 -9
  652. package/lib/archive/transfer/types.d.ts +0 -111
  653. package/lib/archive/transfer/types.js +0 -35
  654. package/lib/archive/types.d.ts +0 -755
  655. package/lib/archive/types.js +0 -1
  656. package/lib/archive/url-alias/compute-tier-a-alias-key.d.ts +0 -31
  657. package/lib/archive/url-alias/compute-tier-a-alias-key.js +0 -36
  658. package/lib/archive/url-alias/compute-tier-b-alias-key.d.ts +0 -19
  659. package/lib/archive/url-alias/compute-tier-b-alias-key.js +0 -30
  660. package/lib/archive/url-alias/format-alias-key.d.ts +0 -13
  661. package/lib/archive/url-alias/format-alias-key.js +0 -14
  662. package/lib/archive/url-alias/parse-alias-key-parts.d.ts +0 -15
  663. package/lib/archive/url-alias/parse-alias-key-parts.js +0 -40
  664. package/lib/archive/url-alias/types.d.ts +0 -7
  665. package/lib/archive/url-alias/types.js +0 -1
  666. package/lib/archive/verify-migration/capture-rejection.d.ts +0 -24
  667. package/lib/archive/verify-migration/capture-rejection.js +0 -31
  668. package/lib/archive/verify-migration/check-anchor-edges-count.d.ts +0 -34
  669. package/lib/archive/verify-migration/check-anchor-edges-count.js +0 -72
  670. package/lib/archive/verify-migration/check-anchor-edges-sum.d.ts +0 -13
  671. package/lib/archive/verify-migration/check-anchor-edges-sum.js +0 -27
  672. package/lib/archive/verify-migration/check-content-items-count.d.ts +0 -16
  673. package/lib/archive/verify-migration/check-content-items-count.js +0 -30
  674. package/lib/archive/verify-migration/check-content-type-preservation.d.ts +0 -22
  675. package/lib/archive/verify-migration/check-content-type-preservation.js +0 -40
  676. package/lib/archive/verify-migration/check-foreign-key-integrity.d.ts +0 -31
  677. package/lib/archive/verify-migration/check-foreign-key-integrity.js +0 -47
  678. package/lib/archive/verify-migration/check-image-items-count.d.ts +0 -12
  679. package/lib/archive/verify-migration/check-image-items-count.js +0 -26
  680. package/lib/archive/verify-migration/check-page-meta-count.d.ts +0 -15
  681. package/lib/archive/verify-migration/check-page-meta-count.js +0 -31
  682. package/lib/archive/verify-migration/check-reader-parity.d.ts +0 -23
  683. package/lib/archive/verify-migration/check-reader-parity.js +0 -211
  684. package/lib/archive/verify-migration/check-resource-items-count.d.ts +0 -17
  685. package/lib/archive/verify-migration/check-resource-items-count.js +0 -33
  686. package/lib/archive/verify-migration/check-url-round-trip.d.ts +0 -43
  687. package/lib/archive/verify-migration/check-url-round-trip.js +0 -112
  688. package/lib/archive/verify-migration/types.d.ts +0 -70
  689. package/lib/archive/verify-migration/types.js +0 -63
  690. package/lib/archive/verify-migration/verify-migration.d.ts +0 -41
  691. package/lib/archive/verify-migration/verify-migration.js +0 -120
  692. package/lib/classify-error-kind.d.ts +0 -20
  693. package/lib/classify-error-kind.js +0 -136
  694. package/lib/concat-source-transfer-phases.d.ts +0 -10
  695. package/lib/concat-source-transfer-phases.js +0 -17
  696. package/lib/crawler/build-scope-map.d.ts +0 -21
  697. package/lib/crawler/build-scope-map.js +0 -32
  698. package/lib/crawler/decompose-url.d.ts +0 -25
  699. package/lib/crawler/decompose-url.js +0 -71
  700. package/lib/crawler/dedupe/compute-shape-key.d.ts +0 -57
  701. package/lib/crawler/dedupe/compute-shape-key.js +0 -128
  702. package/lib/crawler/find-scope-entry.d.ts +0 -25
  703. package/lib/crawler/find-scope-entry.js +0 -45
  704. package/lib/crawler/is-html-content-type.d.ts +0 -17
  705. package/lib/crawler/is-html-content-type.js +0 -19
  706. package/lib/crawler/normalize-content-type.d.ts +0 -14
  707. package/lib/crawler/normalize-content-type.js +0 -20
  708. package/lib/crawler/reconstruct-url.d.ts +0 -10
  709. package/lib/crawler/reconstruct-url.js +0 -28
  710. package/lib/is-within-outage-window.d.ts +0 -49
  711. package/lib/is-within-outage-window.js +0 -33
  712. package/lib/network-related-error-kinds.d.ts +0 -23
  713. package/lib/network-related-error-kinds.js +0 -28
  714. package/lib/permanent-error-kinds.d.ts +0 -48
  715. package/lib/permanent-error-kinds.js +0 -54
  716. package/lib/split-source-transfer-phases.d.ts +0 -11
  717. package/lib/split-source-transfer-phases.js +0 -18
  718. package/lib/template-classification/classify-archive-page-templates.d.ts +0 -41
  719. package/lib/template-classification/classify-archive-page-templates.js +0 -79
  720. package/lib/template-classification/classify-page-templates.d.ts +0 -37
  721. package/lib/template-classification/classify-page-templates.js +0 -69
  722. package/lib/template-classification/collect-page-stylesheet-urls.d.ts +0 -32
  723. package/lib/template-classification/collect-page-stylesheet-urls.js +0 -130
  724. package/lib/template-classification/create-content-root-hint.d.ts +0 -36
  725. package/lib/template-classification/create-content-root-hint.js +0 -47
  726. package/lib/template-classification/create-page-cluster-factory.d.ts +0 -60
  727. package/lib/template-classification/create-page-cluster-factory.js +0 -98
  728. package/lib/template-classification/types.d.ts +0 -108
  729. package/lib/template-classification/types.js +0 -1
  730. package/lib/transfer-post-phases.d.ts +0 -10
  731. package/lib/transfer-post-phases.js +0 -13
  732. package/lib/utils/array/each-splitted.d.ts +0 -10
  733. package/lib/utils/array/each-splitted.js +0 -14
  734. package/lib/utils/error/emit-error-with-retry.d.ts +0 -40
  735. package/lib/utils/error/emit-error-with-retry.js +0 -44
  736. package/lib/utils/error/emit-error.d.ts +0 -39
  737. package/lib/utils/error/emit-error.js +0 -41
  738. package/lib/utils/object/parse-response-headers.d.ts +0 -12
  739. package/lib/utils/object/parse-response-headers.js +0 -26
  740. package/lib/utils/object/redact-request-headers.d.ts +0 -15
  741. package/lib/utils/object/redact-request-headers.js +0 -27
  742. package/lib/write-queue.d.ts +0 -32
  743. package/lib/write-queue.js +0 -55
  744. /package/lib/{archive/cache/types.js → beholder-type-mirror-parity.js} +0 -0
@@ -1,1073 +0,0 @@
1
- import path from 'node:path';
2
- import { redactRequestHeaders } from '../utils/object/redact-request-headers.js';
3
- import { ArchiveAccessor } from './archive-accessor.js';
4
- import { acquireArchiveLock } from './archive-lock.js';
5
- import { computeArchiveCacheKey } from './cache/compute-archive-cache-key.js';
6
- import { extractArchiveToCache } from './cache/extract-archive-to-cache.js';
7
- import { getArchiveCacheRoot } from './cache/get-archive-cache-root.js';
8
- import { resolveArchiveCacheDir } from './cache/resolve-archive-cache-dir.js';
9
- import { Database } from './database.js';
10
- import { dbLog, log, saveLog } from './debug.js';
11
- import { appendText } from './filesystem/append-text.js';
12
- import { exists } from './filesystem/exists.js';
13
- import { isDir } from './filesystem/is-dir.js';
14
- import { outputBinary } from './filesystem/output-binary.js';
15
- import { peekTarTopDir } from './filesystem/peek-tar-top-dir.js';
16
- import { remove } from './filesystem/remove.js';
17
- import { rename } from './filesystem/rename.js';
18
- import { tar } from './filesystem/tar.js';
19
- import { untar } from './filesystem/untar.js';
20
- import { safePath } from './safe-path.js';
21
- /**
22
- * Main archive class for creating, opening, resuming, and writing Nitpicker
23
- * archive files (`.nitpicker`).
24
- *
25
- * An Archive wraps a SQLite database into a tar archive. HTML bodies live
26
- * inside the same DB as zstd-compressed BLOBs (see #75), so `db.sqlite` is
27
- * normally the tar's only entry — but it is not the only entry the format
28
- * allows: {@link ArchiveAccessor.setData} (namespace-scoped analyze output)
29
- * and {@link Archive.saveInventorySourceList} (a saved `--inventory`
30
- * source list) add plain files alongside it. It extends
31
- * {@link ArchiveAccessor} to provide read access to stored data.
32
- *
33
- * Use the static factory methods ({@link Archive.create}, {@link Archive.open},
34
- * {@link Archive.resume}, {@link Archive.connect}) to obtain instances.
35
- * The constructor is private. Implements `Symbol.asyncDispose` (inherited
36
- * from {@link ArchiveAccessor}) so callers can use `await using` instead of
37
- * a manual `try`/`finally` around {@link close}.
38
- * @example
39
- * await using archive = await Archive.create({ filePath: '/path/to/site.nitpicker' });
40
- * await archive.setConfig(config);
41
- * const pageId = await archive.setPage(pageData);
42
- * // Writes the `.nitpicker` tar (if absent), removes tmpDir, releases the
43
- * // lock — all on scope exit, whether by fallthrough or thrown error.
44
- */
45
- export default class Archive extends ArchiveAccessor {
46
- /**
47
- * Promise tracking an in-progress {@link Archive.close} (or
48
- * {@link Archive.releaseHandle}). Acts as the override's idempotency
49
- * guard so a second call — e.g. from a signal handler racing the
50
- * primary teardown — does not re-enter the destructive prologue
51
- * (write/remove) on a half-mutated state.
52
- */
53
- #closeOnce = null;
54
- /** The SQLite database instance for reading and writing crawl data. */
55
- #db;
56
- /** Absolute path to the output `.nitpicker` archive file. */
57
- #filePath;
58
- /** Lock release function held while the writer owns the archive. */
59
- #releaseLock;
60
- /** Absolute path to the temporary working directory containing the SQLite DB. */
61
- #tmpDir;
62
- /**
63
- * The absolute file path of the archive (`.nitpicker` file).
64
- */
65
- get filePath() {
66
- return this.#filePath;
67
- }
68
- /**
69
- * The intermediate directory `Archive.write()` produces by renaming
70
- * `tmpDir` before tarring (`{cwd}/{archiveName}`). Exposed so the
71
- * manager can include it in its cleanup-on-failure path: if `tar()`
72
- * fails after the rename, this directory is orphaned and would
73
- * otherwise be invisible to a `rmSync(tmpDir)` recovery.
74
- */
75
- get renamedDir() {
76
- return path.resolve(path.dirname(this.#filePath), path.basename(this.#filePath, path.extname(this.#filePath)));
77
- }
78
- // eslint-disable-next-line no-restricted-syntax
79
- constructor(filePath, tmpDir, db, releaseLock) {
80
- super(tmpDir, db, '');
81
- this.#filePath = filePath;
82
- this.#tmpDir = tmpDir;
83
- this.#db = db;
84
- this.#releaseLock = releaseLock;
85
- log('create instance: %O', {
86
- filePath,
87
- tmpDir,
88
- });
89
- this.#db.on('error', (e) => {
90
- void this.emit('error', e);
91
- });
92
- }
93
- /**
94
- * @deprecated This method is no longer functional.
95
- */
96
- abort() { }
97
- /**
98
- * Adds onto the `rejected_count` of a shape's `dedupe_cap_events` row,
99
- * looked up by `shape_key` rather than `id` — used for a shape that
100
- * capped in an earlier session (preloaded into `DedupeCapTracker`'s
101
- * sticky set) and so has no event id from the current session.
102
- *
103
- * Thin facade over {@link Database.accumulateDedupeCapRejectedCount}.
104
- * @param shapeKey - The capped shape whose rejection count to accumulate.
105
- * @param rejectedCount - Additional anchors rejected for this shape in the current session.
106
- */
107
- async accumulateDedupeCapRejectedCount(shapeKey, rejectedCount) {
108
- dbLog('Accumulate dedupe cap rejected count shapeKey=%s rejectedCount=%d', shapeKey, rejectedCount);
109
- return await this.#db.accumulateDedupeCapRejectedCount(shapeKey, rejectedCount);
110
- }
111
- /**
112
- * Records a crawler-level error to both the human-readable `error.log` (full
113
- * stack, for debugging) and the structured `crawl_errors` table (queryable,
114
- * for the `error-kinds` analysis). The cause is not classified here — it is
115
- * derived on read. `error.log` keeps the full stack while `crawl_errors`
116
- * stores `error.message`; both normally carry the same cause token (e.g.
117
- * `ENOTFOUND`), so classification agrees across the two — only an error whose
118
- * cause lives solely in deeper stack frames could differ.
119
- * @param error - The crawler error object containing process and URL information.
120
- */
121
- async addError(error) {
122
- const logFile = path.resolve(this.#tmpDir, 'error.log');
123
- await appendText(logFile, `[${error.pid}(${error.isMainProcess ? 'main' : 'sub'})] ${error.url} ${error.error.stack ?? error.error}`);
124
- await this.#db.insertCrawlError(error.url, error.error.message, error.isExternal);
125
- }
126
- /**
127
- * Records a partial scrape failure against the page identified by `url`.
128
- *
129
- * The corresponding `pages` row is created on demand (or matched if it
130
- * already exists), so the call works even if the page's normal data has
131
- * not been written yet.
132
- * @param url - URL of the affected page.
133
- * @param phase - Scrape phase name (typically `'retryExhausted'`).
134
- * @param message - Human-readable failure message.
135
- * @param isExternal - Whether the URL is external. Defaults to `false`.
136
- */
137
- async addPageError(url, phase, message, isExternal = false) {
138
- dbLog('Add page error: %s [%s]', url, phase);
139
- await this.#db.insertPageError(url, phase, message, isExternal);
140
- }
141
- /**
142
- * Closes an outage row by stamping `ended_at` — a no-op if already closed.
143
- *
144
- * Thin facade over {@link Database.closeNetworkOutage}.
145
- * @param id - The `network_outages.id` to close.
146
- * @param endedAt - Epoch ms the outage is considered to have ended.
147
- */
148
- async closeNetworkOutage(id, endedAt) {
149
- dbLog('Close network outage id=%d endedAt=%d', id, endedAt);
150
- return await this.#db.closeNetworkOutage(id, endedAt);
151
- }
152
- /**
153
- * Finalizes a `dedupe_cap_events` row by stamping `rejected_count` — a
154
- * no-op if already finalized.
155
- *
156
- * Thin facade over {@link Database.finalizeDedupeCapEvent}.
157
- * @param id - The `dedupe_cap_events.id` to finalize.
158
- * @param rejectedCount - Number of anchors rejected for this shape after it capped.
159
- */
160
- async finalizeDedupeCapEvent(id, rejectedCount) {
161
- dbLog('Finalize dedupe cap event id=%d rejectedCount=%d', id, rejectedCount);
162
- return await this.#db.finalizeDedupeCapEvent(id, rejectedCount);
163
- }
164
- /**
165
- * Retrieves the current crawling state, including lists of scraped and pending URLs.
166
- * @returns An object with `scraped`, `pending`, and `pendingMetadataOnly` URL arrays.
167
- */
168
- async getCrawlingState() {
169
- return this.#db.getCrawlingState();
170
- }
171
- /**
172
- * Retrieves the `info.createdCwd` value stamped when this stub was
173
- * created — see {@link Archive.resume} for how it is used.
174
- * @returns The recorded cwd, or `null` if never stamped.
175
- */
176
- async getCreatedCwd() {
177
- return this.#db.getCreatedCwd();
178
- }
179
- /**
180
- * Return the subset of `urls` that already exist as `pages.url`. Used by
181
- * `CrawlerOrchestrator.inventory` to filter the user-supplied URL list
182
- * down to "URLs that are NOT yet in the archive" — only those reach the
183
- * HEAD / scrape pipeline. Existing URLs are skipped to keep the second
184
- * (and N-th) `--inventory` pass non-destructive.
185
- * @param urls - Candidate URLs in `withoutHashAndAuth` form.
186
- * @returns URLs already present in `pages`.
187
- */
188
- async getExistingPageUrls(urls) {
189
- return this.#db.getExistingPageUrls(urls);
190
- }
191
- /**
192
- * Return the subset of `urls` that already exist as `resources.url`. See
193
- * {@link Archive.getExistingPageUrls} — the resource-side counterpart used
194
- * by inventory mode to skip URLs that are already tracked as
195
- * sub-resources.
196
- * @param urls - Candidate URLs.
197
- * @returns URLs already present in `resources`.
198
- */
199
- async getExistingResourceUrls(urls) {
200
- return this.#db.getExistingResourceUrls(urls);
201
- }
202
- /**
203
- * Look up the `source` column of a single page row by its URL key. Thin
204
- * facade over {@link Database.getPageSourceByUrl} — exposes the lookup
205
- * to the orchestrator so it can inject a `PageSourceLookup` into the
206
- * Crawler for sub-resource lineage propagation on `--resume` /
207
- * `--retry-failed` sessions.
208
- * @param url - URL key in `url.withoutHashAndAuth` form.
209
- * @returns The recorded `source`, or `undefined` when no row exists.
210
- */
211
- async getPageSourceByUrl(url) {
212
- return this.#db.getPageSourceByUrl(url);
213
- }
214
- /**
215
- * Retrieves a single recorded sub-resource by its URL.
216
- * @param urls - URL candidates to match against the stored resource URL.
217
- * @returns The raw resource row, or `null` if none match.
218
- */
219
- async getResourceByUrl(urls) {
220
- return this.#db.getResourceByUrl(urls);
221
- }
222
- /**
223
- * Counts the number of pages already scraped as crawl targets in the archive.
224
- *
225
- * Lets the crawler initialize its session-progress counter on resume so the
226
- * displayed HTML-page count accounts for previously-rendered pages.
227
- * @returns The count of pages with `isTarget = 1` and `scraped = 1`.
228
- */
229
- async getScrapedHtmlPageCount() {
230
- return this.#db.getScrapedHtmlPageCount();
231
- }
232
- /**
233
- * Retrieves the base URL of the crawl session from the archive database.
234
- * @returns The base URL string.
235
- */
236
- async getUrl() {
237
- return this.#db.getBaseUrl();
238
- }
239
- /**
240
- * Appends one row (`rejected_count = NULL`) to the `dedupe_cap_events`
241
- * journal.
242
- *
243
- * Thin facade over {@link Database.insertDedupeCapEvent}.
244
- * @param params - The newly-capped shape's fields to record.
245
- * @returns The autoincremented `id` of the inserted row.
246
- */
247
- async insertDedupeCapEvent(params) {
248
- dbLog('Insert dedupe cap event: shapeKey=%s', params.shapeKey);
249
- return await this.#db.insertDedupeCapEvent(params);
250
- }
251
- /**
252
- * Pre-insert inventory non-HTML URLs as `source='inventory-seed'`
253
- * placeholders in the `resources` table — the non-HTML counterpart of
254
- * {@link Archive.insertInventorySeeds}. Rows are committed in chunked
255
- * bulk inserts (500 per round-trip) rather than per-URL awaits — a
256
- * per-URL loop would keep a 50k-URL inventory list inside the `.bak`
257
- * window for minutes instead of seconds.
258
- *
259
- * Thin facade over {@link Database.insertInventoryResources}.
260
- * `ExURL.href` is the storage key for `resources.url` (matches what
261
- * `insertResource` writes for the per-URL path); we normalise here so
262
- * the orchestrator stays decoupled from the storage form.
263
- * @param urls - Non-HTML inventory URLs to record. No-op when empty.
264
- */
265
- async insertInventoryResources(urls) {
266
- if (urls.length === 0) {
267
- return;
268
- }
269
- dbLog('Insert inventory resources: %d URL(s)', urls.length);
270
- await this.#db.insertInventoryResources(urls.map((u) => u.href));
271
- }
272
- /**
273
- * Pre-insert inventory HTML seeds as `scraped=0`, `source='inventory-seed'`
274
- * placeholder pages so the URL is durably tracked in the archive **before**
275
- * the scrape phase starts. Thin facade over
276
- * {@link Database.insertInventorySeeds} — see that method's JSDoc for the
277
- * Ctrl+C-tolerance rationale and the `getCrawlingState` interaction.
278
- *
279
- * `ExURL` inputs are normalised to `withoutHashAndAuth` here so the storage
280
- * key matches what `resolveContentItemId` writes for crawled rows, keeping the
281
- * crawled-wins downgrade and the existing-URL filter (`getExistingPageUrls`)
282
- * lookups consistent.
283
- * @param urls - HTML seed URLs to pre-insert. No-op when empty.
284
- */
285
- async insertInventorySeeds(urls) {
286
- if (urls.length === 0) {
287
- return;
288
- }
289
- dbLog('Insert inventory seeds: %d URL(s)', urls.length);
290
- await this.#db.insertInventorySeeds(urls.map((u) => u.withoutHashAndAuth));
291
- }
292
- /**
293
- * Records exclude-matched inventory URLs as terminal skipped pages —
294
- * the same `is_skipped=1, skip_reason='excluded'` state the normal
295
- * crawl's fetch-time gate writes for link-discovered excluded URLs,
296
- * labelled `source='inventory-seed'`. Thin facade over
297
- * {@link Database.insertInventorySkippedPages} — see the underlying
298
- * op's JSDoc for the parity rationale and crawled-wins safety.
299
- *
300
- * `ExURL` inputs are normalised to `withoutHashAndAuth` here for the
301
- * same storage-key consistency reason as {@link insertInventorySeeds}.
302
- * @param urls - Exclude-matched URLs to record. No-op when empty.
303
- */
304
- async insertInventorySkippedPages(urls) {
305
- if (urls.length === 0) {
306
- return;
307
- }
308
- dbLog('Insert inventory skipped pages: %d URL(s)', urls.length);
309
- await this.#db.insertInventorySkippedPages(urls.map((u) => u.withoutHashAndAuth));
310
- }
311
- /**
312
- * Appends one open row to the `network_outages` journal.
313
- *
314
- * Thin facade over {@link Database.insertNetworkOutage} — see
315
- * {@link recordListReconcileRun}'s docstring for why this indirection exists.
316
- * @param params - The confirmed-outage fields to record.
317
- * @returns The autoincremented `id` of the inserted row.
318
- */
319
- async insertNetworkOutage(params) {
320
- dbLog('Insert network outage: startedAt=%d probeHost=%s', params.startedAt, params.probeHost);
321
- return await this.#db.insertNetworkOutage(params);
322
- }
323
- /**
324
- * Every previously-scraped internal page's raw fields, in the shape
325
- * `buildDedupeCapObservation` needs to replay this archive's prior
326
- * `DedupeCapTracker` observations (not just its confirmed-capped
327
- * shapes — see {@link listDedupeCapShapeKeys}) into a fresh tracker
328
- * instance on `--resume` / `--append` / `--retry-failed` /
329
- * `--inventory` / `--recrawl`. Without this, every not-yet-capped
330
- * shape's Misra-Gries counter restarts at 0 each session, even one
331
- * that was one observation away from confirming a trap.
332
- * @param onProgress - Called after each internal chunk read, with the
333
- * highest `content_items.id` scanned so far and the max id in the
334
- * table. Omit for no reporting.
335
- * @returns Every qualifying page's raw fields, in discovery order.
336
- */
337
- async listDedupeCapObservations(onProgress) {
338
- return this.#db.listDedupeCapObservations(onProgress);
339
- }
340
- /**
341
- * Every distinct `dedupe_cap_events.shape_key` recorded in this archive.
342
- * Consumed by `CrawlerOrchestrator` to preload `DedupeCapTracker`'s
343
- * sticky set on `--resume` / `--append` / `--retry-failed` /
344
- * `--inventory`, mirroring {@link listDnsBurnedHostCandidates}'s
345
- * writer-only exposure.
346
- * @returns Distinct shape keys already confirmed capped.
347
- */
348
- async listDedupeCapShapeKeys() {
349
- return this.#db.listDedupeCapShapeKeys();
350
- }
351
- /**
352
- * Hostnames whose `crawl_errors` history is consistently DNS failures and
353
- * for which no recent 2xx/3xx page or resource is recorded. Consumed by
354
- * `CrawlerOrchestrator.#preloadDnsBurnedHostCache` to seed the DNS-burned
355
- * host cache at re-open (append / inventory / retryFailed / resume), so
356
- * the next crawl skips HEAD pre-flight on hosts the previous crawl
357
- * already proved unreachable.
358
- *
359
- * Deliberately exposed only on `Archive` (writer-side) — read-only
360
- * `ArchiveAccessor` (stub viewer) does not see this method so the
361
- * stub's no-migration contract is preserved.
362
- * @returns Lower-cased hostnames safe to short-circuit.
363
- */
364
- async listDnsBurnedHostCandidates() {
365
- return this.#db.listDnsBurnedHostCandidates();
366
- }
367
- /**
368
- * Lists every recorded outage as a resolved {@link OutageWindow}.
369
- *
370
- * Thin facade over {@link Database.listNetworkOutages}.
371
- * @returns Resolved outage windows, or `[]` if none have been recorded.
372
- */
373
- async listNetworkOutages() {
374
- return await this.#db.listNetworkOutages();
375
- }
376
- /**
377
- * Appends one row to the `list_reconcile_runs` audit log.
378
- *
379
- * Thin facade over {@link Database.recordListReconcileRun} — keeps the
380
- * orchestrator decoupled from the knex layer and gives a single
381
- * write entry point that future Archive-level concerns (locking,
382
- * mirror sync, etc.) can hook into without touching every caller.
383
- * @param meta - The run metadata. Only `ran_at` is required.
384
- * @returns The autoincremented `id` of the inserted row.
385
- */
386
- async recordListReconcileRun(meta) {
387
- dbLog('Record list reconcile run: %s', meta.list_label ?? meta.ran_at);
388
- return await this.#db.recordListReconcileRun(meta);
389
- }
390
- /**
391
- * Releases the SQLite handle and the advisory lock **without** writing
392
- * the archive or removing `tmpDir`.
393
- *
394
- * Use this when you need to detach from a freshly-created `Archive`
395
- * without finalising it — fixtures producing a stub state for tests,
396
- * tooling that wants to leave the tmpDir alive for `crawl --resume`,
397
- * or any non-orchestrator caller that owns the lifecycle externally.
398
- * Shares the same idempotency guard as {@link close}, so the two paths
399
- * are mutually exclusive (the first one called wins).
400
- */
401
- async releaseHandle() {
402
- if (this.#closeOnce) {
403
- return this.#closeOnce;
404
- }
405
- this.#closeOnce = this.#runReleaseHandle();
406
- return this.#closeOnce;
407
- }
408
- /**
409
- * Replaces the archive's analysis violations with a fresh SQL-backed set.
410
- *
411
- * Thin facade over {@link Database.replaceAnalysisViolations}; kept on
412
- * `Archive` so the analyze pipeline can persist violations without
413
- * reaching into the low-level database class directly.
414
- * @param violations - Flat analyze violations.
415
- */
416
- async replaceAnalysisViolations(violations) {
417
- await this.#db.replaceAnalysisViolations(violations);
418
- }
419
- /**
420
- * Replaces the archive's DOM-structure template classification
421
- * with a fresh SQL-backed set.
422
- *
423
- * Thin facade over {@link Database.replacePageTemplates}; kept on
424
- * `Archive` so the crawl-end classification step
425
- * (`classifyArchivePageTemplates`) can persist template keys without
426
- * reaching into the low-level database class directly.
427
- * @param templateKeysByUrl - Page URL → template key, as produced by
428
- * `classifyPageTemplates`.
429
- * @param clusterReasonsByTemplateKey - Template key → cluster-selection
430
- * evidence, if the caller captured it. Omitting this always clears the
431
- * previously-stored reasons too — "no reason" means "not captured for
432
- * this run", never "carry over the previous run's reasons".
433
- */
434
- async replacePageTemplates(templateKeysByUrl, clusterReasonsByTemplateKey) {
435
- await this.#db.replacePageTemplates(templateKeysByUrl, clusterReasonsByTemplateKey);
436
- }
437
- /**
438
- * Promote previously-external pages that now fall under the (possibly extended)
439
- * scope back to a pending state so that the crawler re-scrapes them as fully
440
- * internal pages on the next pass.
441
- * @param scopes - Hostname-indexed scope map representing the new scope.
442
- * @param options - URL parsing options forwarded to the scope-entry lookup.
443
- * @param onProgress - Forwarded to {@link Database.repromoteExternalPages}
444
- * — see that method's docs.
445
- * @returns The URLs that were repromoted.
446
- */
447
- async repromoteExternalPages(scopes, options, onProgress) {
448
- dbLog('Repromote external pages with %d hostnames in scope', scopes.size);
449
- return this.#db.repromoteExternalPages(scopes, options, onProgress);
450
- }
451
- /**
452
- * Reset previously-failed pages back to pending so a follow-up crawl re-fetches them.
453
- *
454
- * Delegates to {@link Database.resetFailedPages}. See that method for the
455
- * exact failure criteria (missing status / content type, or a 5xx status).
456
- * @param onProgress - Forwarded to {@link Database.resetFailedPages} —
457
- * see that method's docs.
458
- * @returns The URLs of the pages that were reset to pending.
459
- */
460
- async resetFailedPages(onProgress) {
461
- dbLog('Reset failed pages back to pending');
462
- return this.#db.resetFailedPages(onProgress);
463
- }
464
- /**
465
- * Reset pages matching an operator-supplied URL list back to pending so a
466
- * follow-up crawl re-fetches them from scratch.
467
- *
468
- * Delegates to {@link Database.resetPagesByUrls}. See that method for the
469
- * conservative exclusion rules (redirect sources / intentionally-skipped /
470
- * external pages are matched but not reset).
471
- * @param urls - URL strings to match, already in `withoutHashAndAuth` form.
472
- * @param onProgress - Forwarded to {@link Database.resetPagesByUrls} — see
473
- * that method's docs.
474
- * @returns The reset URLs plus the excluded URLs grouped by reason.
475
- */
476
- async resetPagesByUrls(urls, onProgress) {
477
- dbLog('Reset %d URL-list-matched page(s) back to pending', urls.length);
478
- return this.#db.resetPagesByUrls(urls, onProgress);
479
- }
480
- /**
481
- * Persists the raw bytes of an `--inventory` source URL list into the
482
- * archive's tar payload, at `inventory/<sha256>.txt`.
483
- *
484
- * The file name is the content hash rather than the original file name:
485
- * re-applying the same list is then a no-op write (`fs.writeFile`
486
- * overwrites identical bytes), and the original name — which may embed a
487
- * client/project identifier — is never retained (the archive already
488
- * omits the source file's absolute path for the same reason; see
489
- * `CrawlerOrchestrator.inventory`'s `source` param).
490
- *
491
- * This bypasses the namespace-scoped {@link ArchiveAccessor.setData} API
492
- * (that one is reserved for analyze plugins and requires a namespace) —
493
- * this always lands under the fixed `inventory/` prefix regardless of
494
- * how this accessor was constructed. Callers that need to read the
495
- * saved list back can use the inherited `getData(`inventory/${sha256}`,
496
- * 'txt')`, since it resolves to the same path when no namespace is set.
497
- *
498
- * No entry is ever removed here — same accepted gap as `page_html_blobs`
499
- * (a future #23 GC pass will sweep unreachable hashes across both). A
500
- * source list that differs byte-for-byte on every run (e.g. a
501
- * regenerated doc-root export with fresh timestamps) adds one entry per
502
- * run with no pruning of superseded ones.
503
- * @param sha256 - Lower-case hex SHA-256 digest of `bytes` (used as the file name).
504
- * @param bytes - The exact bytes of the source list file, written verbatim.
505
- */
506
- async saveInventorySourceList(sha256, bytes) {
507
- const filePath = safePath(this.tmpDir, 'inventory', `${sha256}.txt`);
508
- await outputBinary(filePath, bytes);
509
- }
510
- /**
511
- * Stores the crawl configuration into the archive database.
512
- * @param config - The configuration object to store.
513
- */
514
- async setConfig(config) {
515
- dbLog('Set config: %O', redactRequestHeaders(config));
516
- return this.#db.setConfig(config);
517
- }
518
- /**
519
- * Replaces one page's captured console messages / page errors in the
520
- * archive database.
521
- * @param pageUrl - The originally-requested URL, normalised (`withoutHashAndAuth` form).
522
- * @param redirectPaths - The redirect chain hops captured during fetch, in order.
523
- * @param entries - The console log entries to persist.
524
- */
525
- async setConsoleLogs(pageUrl, redirectPaths, entries) {
526
- dbLog('Set console logs: %d entries on %s', entries.length, pageUrl);
527
- await this.#db.replaceConsoleLogs(pageUrl, redirectPaths, entries);
528
- }
529
- /**
530
- * Stores an external page's data in the archive database without storing
531
- * an HTML snapshot. External-page rows carry only metadata (status, title,
532
- * content-type), never a rendered body.
533
- * @param pageInfo - The page data to store.
534
- * @param source - Provenance label for new rows. `undefined` leaves the DB DEFAULT (`'crawled'`).
535
- * @param recursive - The crawl session's `recursive` option, forwarded so
536
- * `is_metadata_only` on any newly-discovered anchor is computed
537
- * correctly (#369). Defaults to `true` (never persist an anchor as
538
- * metadata-only) since an external page's `anchorList` is always
539
- * empty — this only matters for callers that pass one anyway.
540
- * @example
541
- * await archive.setExternalPage(externalPageData, undefined, options.recursive);
542
- */
543
- async setExternalPage(pageInfo, source, recursive) {
544
- dbLog('Set external page: %s', pageInfo.url.href);
545
- await this.#db.updatePage(pageInfo, false, false, source, undefined, recursive);
546
- }
547
- /**
548
- * Stores a crawled page's data in the archive database, persisting the
549
- * rendered HTML body as a zstd-compressed BLOB inside the same SQLite
550
- * transaction. Storage is content-addressable: identical bodies across
551
- * pages share a single `page_html_blobs` row.
552
- * @param pageInfo - The page data to store.
553
- * @param source - Provenance label for new rows. `undefined` leaves the DB DEFAULT (`'crawled'`).
554
- * @param bodyHash - Precomputed body hash for the page's HTML (see
555
- * `CrawlerEventTypes.page.bodyHash`). `undefined`/`null` falls back to
556
- * computing it from the HTML instead.
557
- * @param recursive - The crawl session's `recursive` option, forwarded so
558
- * any anchor discovered on this page gets the correct
559
- * `is_metadata_only` value (#369). Defaults to `true` (never persist
560
- * an anchor as metadata-only) for callers that do not track the
561
- * option.
562
- * @returns The database ID of the stored page.
563
- * @example
564
- * const pageId = await archive.setPage(pageData, undefined, undefined, options.recursive);
565
- */
566
- async setPage(pageInfo, source, bodyHash, recursive) {
567
- dbLog('Set page: %s', pageInfo.url.href);
568
- return await this.#db.updatePage(pageInfo, true, pageInfo.isTarget, source, bodyHash, recursive);
569
- }
570
- /**
571
- * Records a redirect edge without re-storing the destination's content.
572
- *
573
- * The crawler calls this (instead of {@link setPage}) when a URL redirects to
574
- * a destination that has already been rendered (#73): only the source →
575
- * destination edge is written, leaving the destination's stored title / meta /
576
- * anchors / images untouched.
577
- * @param pageInfo - The HEAD-resolved page data carrying the redirect chain.
578
- * @param source - Inventory provenance for a brand-new destination row.
579
- * Forwarded to `recordRedirect` so the destination's `source` (and the
580
- * chain-intermediate `source` derived from it) lands on the inventory
581
- * label instead of the DB DEFAULT `'crawled'` when the orchestrator is
582
- * running an inventory pass. `undefined` keeps the DB DEFAULT.
583
- */
584
- async setRedirect(pageInfo, source) {
585
- dbLog('Set redirect: %s', pageInfo.url.href);
586
- await this.#db.recordRedirect(pageInfo, source);
587
- }
588
- /**
589
- * Stores a sub-resource (CSS, JS, image, etc.) in the archive database.
590
- * @param resource - The resource data to store.
591
- * @param source - Provenance label for new rows. `undefined` leaves the DB DEFAULT (`'crawled'`).
592
- */
593
- async setResources(resource, source) {
594
- dbLog('Set resource: %s', resource.url.href);
595
- await this.#db.insertResource(resource, source);
596
- }
597
- /**
598
- * Stores the referrer relationship between a resource and the page that references it.
599
- * @param params - An object containing `url` (the page URL) and `src` (the resource URL).
600
- * @param params.url
601
- * @param params.src
602
- */
603
- async setResourcesReferrers({ url, src }) {
604
- dbLog("Set resource's referrers: %s on %s", src, url);
605
- await this.#db.insertResourceReferrers(src, url);
606
- }
607
- /**
608
- * Marks a page as skipped in the archive database with the given reason.
609
- * @param url - The URL of the page to mark as skipped.
610
- * @param reason - The reason the page was skipped.
611
- * @param isExternal - Whether the page is on an external domain. Defaults to `false`.
612
- */
613
- async setSkippedPage(url, reason, isExternal = false) {
614
- dbLog('Set skipped page: %s', url);
615
- await this.#db.setSkippedPage(url, reason, isExternal);
616
- }
617
- /**
618
- * Assigns natural URL sort order values to all pages in the database
619
- * that do not yet have an `order` field set.
620
- * @param onProgress - Forwarded to {@link Database.setUrlOrder} — see that
621
- * method's docs.
622
- */
623
- async setUrlOrder(onProgress) {
624
- dbLog("Pages didn't have `order` field. So set URL order.");
625
- await this.#db.setUrlOrder(onProgress);
626
- }
627
- /**
628
- * Updates a subset of fields on the archive's `info` row. Used by the append
629
- * flow to extend `roots` / `scope` without rewriting the entire config.
630
- * @param patch - Partial {@link Config} fields to overwrite. `undefined` values are ignored.
631
- */
632
- async updateConfig(patch) {
633
- dbLog('Update config: %O', redactRequestHeaders(patch));
634
- await this.#db.updateConfig(patch);
635
- }
636
- /**
637
- * Writes the archive to disk as a `.nitpicker` tar file.
638
- *
639
- * Checkpoints the SQLite WAL so the database is self-contained inside
640
- * `db.sqlite`, renames the temporary working directory to the archive's
641
- * basename, and tars the **entire tmpDir**. `db.sqlite` is normally the
642
- * only entry (HTML lives as BLOBs in the DB, not a `snapshot-html.zip`),
643
- * but a namespace-scoped `setData` write (analyze output) or
644
- * `saveInventorySourceList` (a saved `--inventory` source list) adds
645
- * extra files under tmpDir that get tarred right alongside it.
646
- *
647
- * This is why every writer path that reaches `write()` must open with
648
- * `openPluginData: true` — `Archive.open`'s default extracts only
649
- * `db.sqlite`, so a re-crawl (`append` / `inventory` / `retryFailed`)
650
- * opened without it would tar back a tmpDir missing those extra files,
651
- * silently dropping them from the rewritten archive.
652
- * @param options - Optional write settings.
653
- * @param options.onTarProgress - Called as archive bytes are written
654
- * during the tar step, with the bytes written so far and the estimated
655
- * total (issue #294: tarring a large archive takes minutes, and
656
- * without this the CLI shows nothing until `write` returns). Omit for
657
- * a silent write (the default).
658
- * @param options.onStep - Called once at the start of each of this
659
- * method's four steps (issue #294): `checkpoint` (WAL fold-back —
660
- * single synchronous PRAGMA, no countable progress) and `remove`
661
- * (deleting the tarred-away tmpDir) have no progress signal of their
662
- * own, so without this a large archive's write looks frozen between
663
- * the `tar` step's byte updates and completion. `rename` is nearly
664
- * instant (same-filesystem directory move) but included for
665
- * completeness — a caller displaying phase labels shouldn't have a
666
- * gap where the operation is silently between named steps.
667
- */
668
- async write(options) {
669
- saveLog('Starts: %s', this.#filePath);
670
- // `.nitpicker` files are routinely shared between users — scrub the
671
- // stub-local `createdCwd` (see `Config.createdCwd`'s JSDoc) before it
672
- // gets folded into `db.sqlite` and tarred, so a packaged archive never
673
- // carries another user's local absolute path. Bundled into the
674
- // `checkpoint` step below (a single UPDATE ahead of the WAL fold-back)
675
- // rather than its own `onStep` phase — both are near-instant and
676
- // reporting them separately would add a phase label for no visible
677
- // wait.
678
- await this.#db.updateConfig({ createdCwd: null });
679
- options?.onStep?.('checkpoint');
680
- await this.#db.checkpoint();
681
- const filePathWithoutExt = path.resolve(path.dirname(this.#filePath), path.basename(this.#filePath, path.extname(this.#filePath)));
682
- saveLog('Rename temporary dir: %s to %s', this.#tmpDir, filePathWithoutExt);
683
- options?.onStep?.('rename');
684
- await rename(this.#tmpDir, filePathWithoutExt, true);
685
- saveLog('Tar temporary dir to file: %s to %s', filePathWithoutExt, this.#filePath);
686
- options?.onStep?.('tar');
687
- await tar(filePathWithoutExt, this.#filePath, options?.onTarProgress);
688
- saveLog('Remove temporary dir: %s', filePathWithoutExt);
689
- options?.onStep?.('remove');
690
- await remove(filePathWithoutExt);
691
- saveLog('Done: %s', this.#filePath);
692
- }
693
- /**
694
- * Worker for {@link close}. Performs the destructive prologue
695
- * (write or remove), drops the DB handle via the base class, then
696
- * releases the lock in a `finally` so the lock never leaks even on
697
- * partial failure.
698
- * @param options - See {@link close}.
699
- * @param options.timeoutMs
700
- * @param options.onRecoveryStart
701
- * @param options.onTarProgress
702
- * @param options.onStep
703
- */
704
- async #runFullClose(options) {
705
- log('Closing');
706
- try {
707
- if (!exists(this.#filePath)) {
708
- log("Save the file because it doesn't exist");
709
- options?.onRecoveryStart?.();
710
- await this.write(options);
711
- }
712
- else if (exists(this.#tmpDir)) {
713
- log('Remove temporary dir');
714
- await remove(this.#tmpDir);
715
- }
716
- await super.close({ timeoutMs: options?.timeoutMs });
717
- }
718
- finally {
719
- await this.#releaseLock();
720
- }
721
- log('Closing done');
722
- }
723
- /**
724
- * Worker for {@link releaseHandle}. Drops the SQLite handle and the
725
- * advisory lock with no filesystem mutation.
726
- */
727
- async #runReleaseHandle() {
728
- log('Releasing handle (no write, no remove)');
729
- try {
730
- await super.close();
731
- }
732
- finally {
733
- await this.#releaseLock();
734
- }
735
- }
736
- /** The file extension for Nitpicker archive files (without the leading dot). */
737
- static FILE_EXTENSION = 'nitpicker';
738
- /** The filename of the SQLite database within the archive. */
739
- static SQLITE_DB_FILE_NAME = 'db.sqlite';
740
- /** The prefix used for temporary working directories during archive operations. */
741
- static TMP_DIR_PREFIX = '._nitpicker-';
742
- /**
743
- * Opens a connection to an existing archive's database, defaulting to
744
- * read-only.
745
- *
746
- * Returns an {@link ArchiveAccessor} that provides query methods. In the
747
- * default read-only mode, no schema migrations run and the connection
748
- * refuses to resurrect a missing parent directory or db file (so a
749
- * TOCTOU window between source classification and this call cannot
750
- * silently produce an empty phantom tmpDir); the returned accessor is
751
- * also marked read-only so consumer-facing helpers (e.g.
752
- * {@link ArchiveAccessor.getHtmlOfPage}) avoid any filesystem mutation
753
- * on the user's tmpDir.
754
- *
755
- * `options.readOnly: false` is a narrow escape hatch for opening a
756
- * second, writable connection to a `tmpDir` the caller's own process
757
- * already owns and extracted itself. The one production caller is the
758
- * viewer-read-model worker thread (`@nitpicker/query`'s
759
- * `viewer-read-model-worker-entry.ts`, issue #294): the parent thread
760
- * holds the archive via `Archive.open` (lock included — worker threads
761
- * share the parent's PID, so the PID-based `acquireArchiveLock` guard
762
- * stays valid), sits idle awaiting the worker, and re-tars the tmpDir
763
- * afterward. What this hatch must NEVER target is a live/interrupted
764
- * crawl tmpDir owned by a *different* process (the stub-mode
765
- * `ArchiveManager.open` path attaches to exactly such directories, and
766
- * must stay read-only): writable connects run the self-healing
767
- * migrations, and mutating a directory out from under its owner is how
768
- * archives corrupt. A read-only open (`Archive.openCached`/
769
- * `ArchiveManager.open`) must never take this path itself — blocking or
770
- * writing during what must be a read-only open is forbidden (issue
771
- * #177). Any new caller is responsible for its own coordination with
772
- * the tmpDir's owner (see `acquireArchiveLock` for the cross-process
773
- * case) — this method does not acquire any lock itself.
774
- * @param tmpDir - The path to the temporary directory containing the database.
775
- * @param namespace - An optional namespace for scoping data access within the archive.
776
- * @param options - Connection options.
777
- * @param options.readOnly - Defaults to `true`. Pass `false` to obtain a
778
- * writable accessor against a tmpDir the calling process itself owns.
779
- * @returns An ArchiveAccessor instance for querying the archive data.
780
- * @example
781
- * // Default (read-only) — safe for stub mode and cache reads:
782
- * const accessor = await Archive.connect(tmpDir);
783
- * @example
784
- * // Writable escape hatch — only against a tmpDir this process owns
785
- * // (e.g. the viewer-read-model worker thread reconnecting to the
786
- * // parent's Archive.open extraction):
787
- * const writable = await Archive.connect(ownTmpDir, null, { readOnly: false });
788
- */
789
- static async connect(tmpDir, namespace = null, options = {}) {
790
- const readOnly = options.readOnly ?? true;
791
- const db = await Archive.#connectDB(tmpDir, { readOnly });
792
- const archive = new ArchiveAccessor(tmpDir, db, namespace, { readOnly });
793
- return archive;
794
- }
795
- /**
796
- * Open a `.nitpicker` archive through the read-only tar cache.
797
- *
798
- * This is the fast path for read-only consumers (viewer, MCP, query
799
- * CLI). It diverges from {@link Archive.open} in two important ways:
800
- *
801
- * 1. The extracted contents land in an OS-temp-scoped cache directory
802
- * keyed by the archive's `size + mtime_ns + ctime_ns` (see
803
- * {@link computeArchiveCacheKey}). Subsequent opens of the same
804
- * unchanged archive skip the untar entirely. A fresh 10 GB archive
805
- * pays the ~10 s untar cost once; reopens are instant.
806
- * 2. The returned value is an {@link ArchiveAccessor} (read-only), not
807
- * an `Archive` (writer). Closing it tears down the DB handle but
808
- * leaves the cache directory in place for the next reader. The
809
- * OS's own temp-directory cleanup (macOS reboot, Linux
810
- * `systemd-tmpfiles`, Windows Disk Cleanup) reclaims stale
811
- * entries — we do not own eviction.
812
- *
813
- * Migrations: the writer-side migration stack
814
- * (`initSchema` / `migrate*`) runs once at cache-miss extraction, so
815
- * the cache directory always lands on the current schema before the
816
- * read-only re-open. Cache hits then skip migrations entirely.
817
- *
818
- * Override the cache location with `NITPICKER_TAR_CACHE_DIR`. The
819
- * disable switch (`NITPICKER_DISABLE_TAR_CACHE=1`) is honoured by
820
- * the caller (`ArchiveManager.open` falls back to {@link Archive.open}
821
- * in that case); this function itself always goes through the cache.
822
- *
823
- * Writer entry points (`crawl --append`, `crawl --retry-failed`) must
824
- * NOT use this path — they need the lock + write-back semantics of
825
- * {@link Archive.open}.
826
- * @param filePath - Absolute path to the `.nitpicker` file.
827
- * @param namespace - Optional namespace forwarded to {@link ArchiveAccessor}.
828
- * @param onExtractProgress - Forwarded to {@link extractArchiveToCache} —
829
- * see that function's docs for the cache-hit/miss contract.
830
- * @param onLog - Forwarded to the cache-miss migration pass (issue #294)
831
- * — a legacy archive's self-healing schema migrations otherwise fall
832
- * back to a bare `console.error`, which can print mid-redraw of a
833
- * caller's `Lanes`/`TaskList` display. Omit for that fallback
834
- * (existing callers — the viewer, MCP, query CLI — do not pass this;
835
- * only callers driving a `TaskList` row for the extraction, like
836
- * `concat`/`split`, need to).
837
- * @returns A read-only {@link ArchiveAccessor} backed by the cache directory.
838
- * @example
839
- * ```ts
840
- * await using accessor = await Archive.openCached('/path/to/site.nitpicker');
841
- * const summary = await getSummary(accessor);
842
- * // tears down DB handle on scope exit; cacheDir persists.
843
- * ```
844
- */
845
- static async openCached(filePath, namespace = null, onExtractProgress, onLog) {
846
- const cacheRoot = getArchiveCacheRoot();
847
- const cacheKey = await computeArchiveCacheKey(filePath);
848
- const cacheDir = resolveArchiveCacheDir(cacheRoot, cacheKey, filePath);
849
- log('Open cached: %s (cacheDir=%s)', filePath, cacheDir);
850
- await extractArchiveToCache(filePath, cacheRoot, cacheDir, cacheKey, onExtractProgress, onLog);
851
- return await Archive.connect(cacheDir, namespace);
852
- }
853
- /**
854
- * Creates a new archive at the specified file path.
855
- * Initializes a temporary working directory and a fresh SQLite database.
856
- * @param options - Options including the file path and optional working directory.
857
- * @returns A new Archive instance ready for writing crawl data.
858
- */
859
- static async create(options) {
860
- const { filePath } = options;
861
- const cwd = options.cwd ?? process.cwd();
862
- log('Create: %O', {
863
- filePath,
864
- cwd,
865
- });
866
- const fileName = path.basename(filePath, path.extname(filePath));
867
- const tmpDir = path.resolve(cwd, Archive.TMP_DIR_PREFIX + fileName);
868
- const releaseLock = await acquireArchiveLock(tmpDir);
869
- try {
870
- return await Archive.#init(filePath, tmpDir, releaseLock);
871
- }
872
- catch (error) {
873
- await releaseLock();
874
- throw error;
875
- }
876
- }
877
- /**
878
- * Joins path segments into an absolute path.
879
- * @param pathes - The path segments to join.
880
- * @returns The resolved absolute path.
881
- */
882
- static joinPath(...pathes) {
883
- return path.resolve(...pathes);
884
- }
885
- /**
886
- * Opens an existing archive file (`.nitpicker`) by extracting it to a temporary directory.
887
- * @param options - Options including the file path, optional working directory,
888
- * and whether to extract plugin data.
889
- * @returns An Archive instance with the extracted data loaded.
890
- */
891
- static async open(options) {
892
- const { filePath, openPluginData, onExtractProgress, onLog } = options;
893
- const cwd = options.cwd ?? process.cwd();
894
- log('Open: %O', {
895
- filePath,
896
- cwd,
897
- openPluginData,
898
- });
899
- // Read the tar's actual top-level directory name instead of deriving
900
- // it from the outer file's basename. `.nitpicker` files are plain
901
- // tar archives and users routinely rename them (`mv X.nitpicker
902
- // Y.nitpicker`) — that operation must not break `open`. The inner
903
- // directory keeps whatever name `Archive.write()` baked in at write
904
- // time, and `tmpDir` mirrors the OUTER basename (so concurrent
905
- // crawls on differently-named copies of the same archive don't
906
- // collide on the lockfile).
907
- const outerBasename = path.basename(filePath, path.extname(filePath));
908
- const innerDirName = await peekTarTopDir(filePath);
909
- const tmpDir = path.resolve(cwd, Archive.TMP_DIR_PREFIX + outerBasename);
910
- const releaseLock = await acquireArchiveLock(tmpDir);
911
- try {
912
- const openFiles = [];
913
- if (!openPluginData) {
914
- const relDdPath = path.join(innerDirName, Archive.SQLITE_DB_FILE_NAME);
915
- openFiles.push(relDdPath);
916
- }
917
- log('Unzip file: %s (%O)', filePath, openFiles);
918
- await untar(filePath, {
919
- cwd,
920
- fileList: openFiles.length > 0 ? openFiles : undefined,
921
- onProgress: onExtractProgress,
922
- });
923
- const extractedDir = path.resolve(cwd, innerDirName);
924
- log('Move directory: %s to %s', extractedDir, tmpDir);
925
- await rename(extractedDir, tmpDir, true);
926
- return await Archive.#init(filePath, tmpDir, releaseLock, onLog);
927
- }
928
- catch (error) {
929
- await releaseLock();
930
- throw error;
931
- }
932
- }
933
- /**
934
- * Resumes an archive from an existing temporary directory
935
- * (e.g., after an interrupted crawl session).
936
- * @param targetPath - The path to the temporary directory to resume from.
937
- * @param onLog - Forwarded to {@link Database.connect} — see
938
- * {@link ArchiveOpenOptions.onLog}'s docs (this writable reconnect
939
- * runs the same self-healing migrations `Archive.open` does).
940
- * @returns An Archive instance reconnected to the existing data.
941
- * @throws {Error} If the specified path is not a directory.
942
- */
943
- static async resume(targetPath, onLog) {
944
- log('Resume: %s', targetPath);
945
- if (await isDir(targetPath)) {
946
- const tmpDir = targetPath;
947
- const releaseLock = await acquireArchiveLock(tmpDir);
948
- try {
949
- const db = await Archive.#connectDB(tmpDir, { onLog });
950
- const name = (await db.getName()) ||
951
- path.basename(targetPath).replace(Archive.TMP_DIR_PREFIX, '');
952
- // Reconstruct the output path from the cwd the interrupted
953
- // session was originally started from (see `Config.createdCwd`),
954
- // not this invocation's own `process.cwd()` — `crawl --resume
955
- // <stub>` is routinely run from a different directory than the
956
- // original `crawl`/`--append`/etc. call. Falls back to this
957
- // invocation's cwd for a stub that predates this column.
958
- const createdCwd = await db.getCreatedCwd();
959
- const filePath = path.resolve(createdCwd ?? process.cwd(), name + '.' + Archive.FILE_EXTENSION);
960
- return new Archive(filePath, tmpDir, db, releaseLock);
961
- }
962
- catch (error) {
963
- await releaseLock();
964
- throw error;
965
- }
966
- }
967
- throw new Error('The specified path is not a directory. Please ensure the path points to a valid directory.');
968
- }
969
- /**
970
- * Generates a timestamp string in the format `YYYYMMDDHHmmssSSS`
971
- * suitable for use in file names.
972
- * @returns A formatted timestamp string.
973
- */
974
- static timestamp() {
975
- const now = new Date();
976
- const year = now.getFullYear().toString();
977
- const month = (now.getMonth() + 1).toLocaleString('en-US', {
978
- minimumIntegerDigits: 2,
979
- });
980
- const date = now.getDate().toLocaleString('en-US', { minimumIntegerDigits: 2 });
981
- const hours = now.getHours().toLocaleString('en-US', { minimumIntegerDigits: 2 });
982
- const minutes = now.getMinutes().toLocaleString('en-US', { minimumIntegerDigits: 2 });
983
- const seconds = now.getSeconds().toLocaleString('en-US', { minimumIntegerDigits: 2 });
984
- const ms = now.getMilliseconds().toLocaleString('en-US', { minimumIntegerDigits: 3 });
985
- return year + month + date + hours + minutes + seconds + ms;
986
- }
987
- /**
988
- * Connects to (or creates) the SQLite database in the given directory.
989
- * @param tmpDir - Directory containing `db.sqlite`
990
- * @param options - Optional connection flags forwarded to
991
- * {@link Database.connect}. Used by {@link Archive.connect} to pass
992
- * `readOnly: true` so no migrations run and a missing tmpDir is not
993
- * resurrected.
994
- * @param options.readOnly
995
- * @param options.onLog
996
- */
997
- static async #connectDB(tmpDir, options) {
998
- const dbPath = path.resolve(tmpDir, Archive.SQLITE_DB_FILE_NAME);
999
- dbLog('connects database: %s (readOnly=%s)', dbPath, options?.readOnly ?? false);
1000
- return await Database.connect({
1001
- filename: dbPath,
1002
- readOnly: options?.readOnly,
1003
- onLog: options?.onLog,
1004
- });
1005
- }
1006
- /**
1007
- * Initializes an Archive instance by connecting to the database.
1008
- *
1009
- * The advisory lock must already be acquired by the caller; this helper just
1010
- * threads the release function through to the resulting `Archive` so that
1011
- * {@link Archive.close} can drop the lock when work is done.
1012
- * @param filePath - Output `.nitpicker` file path
1013
- * @param tmpDir - Temporary working directory path
1014
- * @param releaseLock - Function returned by {@link acquireArchiveLock}.
1015
- * @param onLog - Forwarded to {@link Database.connect} — see
1016
- * {@link ArchiveOpenOptions.onLog}'s docs.
1017
- */
1018
- static async #init(filePath, tmpDir, releaseLock, onLog) {
1019
- const db = await Archive.#connectDB(tmpDir, { onLog });
1020
- const archive = new Archive(filePath, tmpDir, db, releaseLock);
1021
- return archive;
1022
- }
1023
- /**
1024
- * Closes the archive. If the archive file does not yet exist on disk,
1025
- * it writes the archive first. If the temporary directory still exists,
1026
- * it is removed. The database connection is then closed via
1027
- * {@link ArchiveAccessor.close} (the base class owns the SQLite handle),
1028
- * and finally the archive's advisory lock is released.
1029
- *
1030
- * **Idempotent**: the first invocation captures the close promise;
1031
- * subsequent invocations (signal handlers, parallel teardowns, retried
1032
- * orchestrator paths) await the same promise instead of re-entering
1033
- * the destructive prologue on a half-mutated state. If the first
1034
- * close fails (e.g. ENOSPC during tar), the rejection propagates to
1035
- * all awaiters and the archive stays latched closed — there is no
1036
- * safe way to retry `write()` once `tmpDir` has been renamed.
1037
- *
1038
- * **Read-only consumers must not reach this override.** Anything that
1039
- * obtains an archive view via {@link Archive.connect} receives an
1040
- * {@link ArchiveAccessor} (not an `Archive`), so `close()` resolves to
1041
- * the safe base implementation — no `write()`, no `remove()`, no lock
1042
- * release — leaving the tmpDir intact for the live crawler.
1043
- * @param options - Optional close settings. `timeoutMs` is accepted for
1044
- * compatibility with {@link ArchiveAccessor.close}'s signature (forwarded
1045
- * to the base `super.close()` call below); the rest are progress
1046
- * callbacks (issue #294) forwarded to {@link write} when this call ends
1047
- * up taking the recovery-write branch (the archive file doesn't exist
1048
- * yet).
1049
- * @param options.timeoutMs - See {@link ArchiveAccessor.close}.
1050
- * @param options.onRecoveryStart - Called once, only when this `close()`
1051
- * is about to write the archive because the file doesn't exist on
1052
- * disk yet — e.g. a caller's own explicit `write()` threw before
1053
- * finishing, or was never called at all. Without this, a listener
1054
- * that already tore down its display after that earlier failure has
1055
- * no way to know a second, recovery write is happening.
1056
- * @param options.onTarProgress - See {@link write}.
1057
- * @param options.onStep - See {@link write}.
1058
- */
1059
- async close(options) {
1060
- if (this.#closeOnce) {
1061
- return this.#closeOnce;
1062
- }
1063
- this.#closeOnce = this.#runFullClose(options);
1064
- return this.#closeOnce;
1065
- }
1066
- /**
1067
- * Retrieves the crawl configuration stored in the archive database.
1068
- * @returns The configuration object.
1069
- */
1070
- async getConfig() {
1071
- return this.#db.getConfig();
1072
- }
1073
- }