@nitpicker/crawler 0.23.0 → 0.25.0

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