@jant/core 0.7.0 → 0.8.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 (331) hide show
  1. package/bin/commands/assets/prepare.js +3 -3
  2. package/bin/commands/db/export.js +115 -2
  3. package/bin/commands/deploy.js +11 -3
  4. package/bin/commands/{search-reindex.js → search/reindex.js} +5 -5
  5. package/bin/commands/setup.js +136 -0
  6. package/bin/commands/site/export.js +117 -68
  7. package/bin/commands/site/import.js +3074 -2
  8. package/bin/commands/site/pull-media.js +2 -6
  9. package/bin/commands/site/snapshot/export.js +18 -60
  10. package/bin/commands/site/snapshot/import.js +24 -23
  11. package/bin/commands/telegram/register-webhooks.js +48 -23
  12. package/bin/jant.js +16 -11
  13. package/bin/lib/command-registry.js +120 -0
  14. package/bin/lib/d1-query.js +87 -2
  15. package/bin/lib/hugo-markdown.js +4 -0
  16. package/bin/lib/migration-artifacts.js +19 -0
  17. package/bin/lib/renamed-arguments.js +56 -0
  18. package/bin/lib/site-pull-media.js +21 -28
  19. package/bin/lib/site-selection.js +10 -1
  20. package/bin/lib/site-snapshot.js +421 -4
  21. package/bin/lib/sql-export.js +68 -5
  22. package/bin/lib/wrangler-cli.js +9 -0
  23. package/bin/lib/zip-archive.js +187 -0
  24. package/dist/{app-K_Aa1MMn.js → app-CFsmRVJN.js} +8629 -697
  25. package/dist/client/.vite/manifest.json +20 -20
  26. package/dist/client/_assets/chunks/{create-editor-CD3FhrOB.js → create-editor-B-m7X7S5.js} +50 -46
  27. package/dist/client/_assets/chunks/{sortable-list-CgaL2jCs.js → sortable-list-BJyd-LXE.js} +1 -1
  28. package/dist/client/_assets/chunks/{unsafe-svg-0QCkP0vZ.js → unsafe-svg-BkscJx69.js} +2 -2
  29. package/dist/client/_assets/{client-GiYENVw8.css → client-BCumu1-D.css} +1 -1
  30. package/dist/client/_assets/{client-VnFxJN7G.js → client-DTLBOHqD.js} +1 -1
  31. package/dist/client/_assets/{client-auth-k8gJ6QJj.js → client-auth-D6Ix6SmE.js} +1 -1
  32. package/dist/client/_assets/{client-compose-B_kDtWkW.js → client-compose-D6rExKVK.js} +1 -1
  33. package/dist/client/_assets/{client-manage-M90aSTOk.js → client-manage-sVOkqVbH.js} +1 -1
  34. package/dist/client/_assets/{client-settings-DfYs9n1F.js → client-settings-CGR_nZ78.js} +7 -7
  35. package/dist/index.js +2 -3
  36. package/dist/node.js +8 -5
  37. package/dist/url-CKlGzvdN.js +428 -0
  38. package/package.json +13 -7
  39. package/src/__tests__/cli-commands.test.ts +144 -0
  40. package/src/__tests__/config-docs.test.ts +148 -0
  41. package/src/__tests__/dev-scripts.test.ts +203 -0
  42. package/src/__tests__/export-collection-order.test.ts +276 -0
  43. package/src/__tests__/export-feed-ids.test.ts +184 -0
  44. package/src/__tests__/export-feed-order.test.ts +294 -0
  45. package/src/__tests__/export-hugo-build.test.ts +130 -0
  46. package/src/__tests__/export-import-roundtrip.test.ts +95 -1
  47. package/src/__tests__/export-service.test.ts +611 -28
  48. package/src/__tests__/export-smart-collection.test.ts +329 -0
  49. package/src/__tests__/feed-docs.test.ts +36 -0
  50. package/src/__tests__/fixtures/releases/0.7.0/site-export/README.md +89 -0
  51. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/41q27/0x4nv/index.md +16 -0
  52. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/41q27/_index.md +41 -0
  53. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/41q27/faqyt/index.md +28 -0
  54. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/41q27/the-potting-mix-guide-i-keep-rereading/index.md +18 -0
  55. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/_index.md +4 -0
  56. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/a-night-heron-field-guide-for-my-walk-folder/_index.md +27 -0
  57. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/a-quiet-saturday-after-a-busy-week/_index.md +32 -0
  58. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/archive/_index.md +7 -0
  59. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/are-na-is-the-only-bookmark-pile-i-still-revisit/_index.md +27 -0
  60. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/bought-too-many-lemons-again/_index.md +34 -0
  61. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/city-walks/_index.md +11 -0
  62. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/collections/_index.md +4 -0
  63. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/current-tea-rotation/_index.md +31 -0
  64. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/derek-sivers-still-writes-the-kind-of-internet-i-want-more-of/_index.md +27 -0
  65. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/desk-but-better/_index.md +22 -0
  66. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/e0kcg/_index.md +19 -0
  67. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/featured/_index.md +7 -0
  68. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/from-basho/_index.md +22 -0
  69. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/from-epictetus/_index.md +22 -0
  70. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/from-marcus-aurelius/_index.md +22 -0
  71. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/from-seneca/_index.md +22 -0
  72. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/from-thoreau/_index.md +22 -0
  73. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/gkbvv/2cl6d/index.md +16 -0
  74. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/gkbvv/3zqv7/index.md +28 -0
  75. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/gkbvv/5oxsv/index.md +16 -0
  76. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/gkbvv/_index.md +36 -0
  77. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/home-cooking/_index.md +11 -0
  78. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/k5vh8/_index.md +29 -0
  79. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/k5vh8/a-reading-log-idea-i-might-steal/index.md +18 -0
  80. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/k5vh8/a83qu/index.md +16 -0
  81. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/k5vh8/from-seneca-5hibo/index.md +19 -0
  82. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/mynoise-for-rainy-afternoons/_index.md +27 -0
  83. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/nts-archives-are-good-cleaning-music/_index.md +27 -0
  84. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/qgfcu/_index.md +29 -0
  85. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/qgfcu/c91j0/index.md +16 -0
  86. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/qgfcu/qyucy/index.md +16 -0
  87. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/qgfcu/wsgck/index.md +16 -0
  88. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/rain-makes-my-neighborhood-look-better/_index.md +43 -0
  89. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/reading-notes/_index.md +11 -0
  90. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/serious-eats-on-tomato-and-egg-soup/_index.md +27 -0
  91. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/te812/_index.md +41 -0
  92. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/te812/cxiu6/index.md +16 -0
  93. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/te812/t77ms/index.md +16 -0
  94. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/te812/the-soup-trick-i-always-forget/index.md +18 -0
  95. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/telk3/_index.md +27 -0
  96. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/telk3/from-thoreau-pawt2/index.md +17 -0
  97. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/the-five-minute-reset-is-still-the-best-habit-i-have/_index.md +32 -0
  98. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/the-hallway-light-took-12-minutes-and-3-months/_index.md +29 -0
  99. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/the-recurse-center-manual-is-weirdly-calming/_index.md +27 -0
  100. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/tiny-projects/_index.md +11 -0
  101. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/useful-links/_index.md +11 -0
  102. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/weekend-notes/_index.md +11 -0
  103. package/src/__tests__/fixtures/releases/0.7.0/site-export/content/what-i-actually-use-my-notebook-for/_index.md +49 -0
  104. package/src/__tests__/fixtures/releases/0.7.0/site-export/data/jant.toml +119 -0
  105. package/src/__tests__/fixtures/releases/0.7.0/site-export/hugo.toml +43 -0
  106. package/src/__tests__/fixtures/releases/0.7.0/site-export/static/media/021801c20ab3-med_01kn8jw26cenf98vc7k0ppz5k8.webp +0 -0
  107. package/src/__tests__/fixtures/releases/0.7.0/site-export/static/media/0f868ce9ac84-med_01kn8jtx8qenf98tm9ahxr48sw.webp +0 -0
  108. package/src/__tests__/fixtures/releases/0.7.0/site-export/static/media/50c2ad911bad-med_01kn8jvb16enf98txp7p0pf5ge.webp +0 -0
  109. package/src/__tests__/fixtures/releases/0.7.0/site-export/static/media/7a91f0960491-med_01kn8jvq58enf98v538w5vsqp4.webp +0 -0
  110. package/src/__tests__/fixtures/releases/0.7.0/site-export/static/media/8714116d3c8e-med_01kn8jve5nenf98tzap11gpxzr.webp +0 -0
  111. package/src/__tests__/fixtures/releases/0.7.0/site-export/static/media/8a0b4277443f-med_01kn8jv0jdenf98tp6qr9zgjjc.webp +0 -0
  112. package/src/__tests__/fixtures/releases/0.7.0/site-export/static/media/a7d1c8a1afd9-med_01kn8jv452enf98trbkwrvhvgd.webp +0 -0
  113. package/src/__tests__/fixtures/releases/0.7.0/site-export/static/media/e25570b405f5-med_01kn8jvsaeenf98v6ct4gjzppc.webp +0 -0
  114. package/src/__tests__/fixtures/releases/0.7.0/site-export/static/media/e89ea4eabf01-med_01kn8jtq3penf98tfq4gzmh9g9.png +0 -0
  115. package/src/__tests__/fixtures/releases/0.7.0/site-export/themes/jant/static/apple-touch-icon.png +0 -0
  116. package/src/__tests__/fixtures/releases/0.7.0/site-export/themes/jant/static/custom.css +0 -0
  117. package/src/__tests__/fixtures/releases/0.7.0/site-export/themes/jant/static/favicon.ico +0 -0
  118. package/src/__tests__/fixtures/releases/0.7.0/snapshot/db.sql +218 -0
  119. package/src/__tests__/fixtures/releases/0.7.0/snapshot/meta.json +9 -0
  120. package/src/__tests__/fixtures/releases/0.7.1/site-export/README.md +89 -0
  121. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/41q27/0x4nv/index.md +16 -0
  122. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/41q27/_index.md +41 -0
  123. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/41q27/faqyt/index.md +28 -0
  124. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/41q27/the-potting-mix-guide-i-keep-rereading/index.md +18 -0
  125. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/_index.md +4 -0
  126. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/a-night-heron-field-guide-for-my-walk-folder/_index.md +27 -0
  127. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/a-quiet-saturday-after-a-busy-week/_index.md +32 -0
  128. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/archive/_index.md +7 -0
  129. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/are-na-is-the-only-bookmark-pile-i-still-revisit/_index.md +27 -0
  130. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/bought-too-many-lemons-again/_index.md +34 -0
  131. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/city-walks/_index.md +11 -0
  132. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/collections/_index.md +4 -0
  133. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/current-tea-rotation/_index.md +31 -0
  134. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/derek-sivers-still-writes-the-kind-of-internet-i-want-more-of/_index.md +27 -0
  135. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/desk-but-better/_index.md +22 -0
  136. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/e0kcg/_index.md +19 -0
  137. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/featured/_index.md +7 -0
  138. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/from-basho/_index.md +22 -0
  139. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/from-epictetus/_index.md +22 -0
  140. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/from-marcus-aurelius/_index.md +22 -0
  141. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/from-seneca/_index.md +22 -0
  142. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/from-thoreau/_index.md +22 -0
  143. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/gkbvv/2cl6d/index.md +16 -0
  144. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/gkbvv/3zqv7/index.md +28 -0
  145. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/gkbvv/5oxsv/index.md +16 -0
  146. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/gkbvv/_index.md +36 -0
  147. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/home-cooking/_index.md +11 -0
  148. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/k5vh8/_index.md +29 -0
  149. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/k5vh8/a-reading-log-idea-i-might-steal/index.md +18 -0
  150. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/k5vh8/a83qu/index.md +16 -0
  151. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/k5vh8/from-seneca-5hibo/index.md +19 -0
  152. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/mynoise-for-rainy-afternoons/_index.md +27 -0
  153. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/nts-archives-are-good-cleaning-music/_index.md +27 -0
  154. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/qgfcu/_index.md +29 -0
  155. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/qgfcu/c91j0/index.md +16 -0
  156. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/qgfcu/qyucy/index.md +16 -0
  157. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/qgfcu/wsgck/index.md +16 -0
  158. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/rain-makes-my-neighborhood-look-better/_index.md +43 -0
  159. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/reading-notes/_index.md +11 -0
  160. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/serious-eats-on-tomato-and-egg-soup/_index.md +27 -0
  161. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/te812/_index.md +41 -0
  162. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/te812/cxiu6/index.md +16 -0
  163. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/te812/t77ms/index.md +16 -0
  164. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/te812/the-soup-trick-i-always-forget/index.md +18 -0
  165. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/telk3/_index.md +27 -0
  166. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/telk3/from-thoreau-pawt2/index.md +17 -0
  167. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/the-five-minute-reset-is-still-the-best-habit-i-have/_index.md +32 -0
  168. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/the-hallway-light-took-12-minutes-and-3-months/_index.md +29 -0
  169. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/the-recurse-center-manual-is-weirdly-calming/_index.md +27 -0
  170. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/tiny-projects/_index.md +11 -0
  171. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/useful-links/_index.md +11 -0
  172. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/weekend-notes/_index.md +11 -0
  173. package/src/__tests__/fixtures/releases/0.7.1/site-export/content/what-i-actually-use-my-notebook-for/_index.md +49 -0
  174. package/src/__tests__/fixtures/releases/0.7.1/site-export/data/jant.toml +119 -0
  175. package/src/__tests__/fixtures/releases/0.7.1/site-export/hugo.toml +43 -0
  176. package/src/__tests__/fixtures/releases/0.7.1/site-export/static/media/021801c20ab3-med_01kn8jw26cenf98vc7k0ppz5k8.webp +0 -0
  177. package/src/__tests__/fixtures/releases/0.7.1/site-export/static/media/0f868ce9ac84-med_01kn8jtx8qenf98tm9ahxr48sw.webp +0 -0
  178. package/src/__tests__/fixtures/releases/0.7.1/site-export/static/media/50c2ad911bad-med_01kn8jvb16enf98txp7p0pf5ge.webp +0 -0
  179. package/src/__tests__/fixtures/releases/0.7.1/site-export/static/media/7a91f0960491-med_01kn8jvq58enf98v538w5vsqp4.webp +0 -0
  180. package/src/__tests__/fixtures/releases/0.7.1/site-export/static/media/8714116d3c8e-med_01kn8jve5nenf98tzap11gpxzr.webp +0 -0
  181. package/src/__tests__/fixtures/releases/0.7.1/site-export/static/media/8a0b4277443f-med_01kn8jv0jdenf98tp6qr9zgjjc.webp +0 -0
  182. package/src/__tests__/fixtures/releases/0.7.1/site-export/static/media/a7d1c8a1afd9-med_01kn8jv452enf98trbkwrvhvgd.webp +0 -0
  183. package/src/__tests__/fixtures/releases/0.7.1/site-export/static/media/e25570b405f5-med_01kn8jvsaeenf98v6ct4gjzppc.webp +0 -0
  184. package/src/__tests__/fixtures/releases/0.7.1/site-export/static/media/e89ea4eabf01-med_01kn8jtq3penf98tfq4gzmh9g9.png +0 -0
  185. package/src/__tests__/fixtures/releases/0.7.1/site-export/themes/jant/static/apple-touch-icon.png +0 -0
  186. package/src/__tests__/fixtures/releases/0.7.1/site-export/themes/jant/static/custom.css +0 -0
  187. package/src/__tests__/fixtures/releases/0.7.1/site-export/themes/jant/static/favicon.ico +0 -0
  188. package/src/__tests__/fixtures/releases/0.7.1/snapshot/db.sql +322 -0
  189. package/src/__tests__/fixtures/releases/0.7.1/snapshot/meta.json +9 -0
  190. package/src/__tests__/helpers/hugo-site.ts +146 -0
  191. package/src/__tests__/helpers/site-export-import.ts +97 -0
  192. package/src/__tests__/import-site-command.test.ts +514 -2
  193. package/src/__tests__/mise-config.test.ts +75 -4
  194. package/src/__tests__/node-dev-tasks.test.ts +264 -0
  195. package/src/__tests__/release-fixtures.test.ts +132 -0
  196. package/src/__tests__/site-export-canonical-import.test.ts +113 -0
  197. package/src/__tests__/snapshot-canonical-replay.test.ts +179 -0
  198. package/src/__tests__/snapshot-settings.test.ts +97 -0
  199. package/src/__tests__/snapshot-tables.test.ts +219 -0
  200. package/src/__tests__/sql-export.test.ts +173 -0
  201. package/src/__tests__/theme-docs.test.ts +109 -0
  202. package/src/__tests__/zip-archive.test.ts +106 -0
  203. package/src/app.tsx +16 -11
  204. package/src/client/components/__tests__/jant-settings-avatar.test.ts +1 -1
  205. package/src/client/components/__tests__/jant-settings-general.test.ts +21 -1
  206. package/src/client/components/jant-repo-picker-types.ts +6 -1
  207. package/src/client/components/jant-repo-picker.ts +4 -7
  208. package/src/client/components/jant-settings-general.ts +17 -12
  209. package/src/client/tiptap/__tests__/list-editing.test.ts +224 -86
  210. package/src/client/tiptap/__tests__/mark-exit.test.ts +1 -2
  211. package/src/client/tiptap/__tests__/markdown-clipboard.test.ts +26 -0
  212. package/src/client/tiptap/extensions.ts +0 -3
  213. package/src/client/tiptap/structural-keymap.ts +158 -47
  214. package/src/db/__tests__/d1-query.test.ts +56 -1
  215. package/src/db/rehearsal-fixtures/pg-demo-current.json +55 -0
  216. package/src/db/rehearsal-fixtures/pg-demo-current.sql +431 -0
  217. package/src/i18n/locales/public/en.po +0 -2
  218. package/src/i18n/locales/public/zh-Hans.po +0 -2
  219. package/src/i18n/locales/public/zh-Hant.po +0 -2
  220. package/src/i18n/locales/settings/en.po +8 -8
  221. package/src/i18n/locales/settings/en.ts +1 -1
  222. package/src/i18n/locales/settings/zh-Hans.po +8 -8
  223. package/src/i18n/locales/settings/zh-Hans.ts +1 -1
  224. package/src/i18n/locales/settings/zh-Hant.po +8 -8
  225. package/src/i18n/locales/settings/zh-Hant.ts +1 -1
  226. package/src/index.ts +6 -77
  227. package/src/lib/__tests__/github-sync-repo-name.test.ts +40 -0
  228. package/src/lib/__tests__/image.test.ts +27 -1
  229. package/src/lib/__tests__/markdown-to-tiptap.test.ts +105 -0
  230. package/src/lib/__tests__/markdown.test.ts +10 -0
  231. package/src/lib/__tests__/resolve-config.test.ts +67 -0
  232. package/src/lib/__tests__/schemas.test.ts +27 -1
  233. package/src/lib/__tests__/timeline.test.ts +87 -0
  234. package/src/lib/__tests__/tiptap-to-markdown.test.ts +172 -4
  235. package/src/lib/__tests__/view.test.ts +0 -46
  236. package/src/lib/discover.ts +3 -1
  237. package/src/lib/feed.ts +0 -6
  238. package/src/lib/github-sync-repo-name.ts +45 -0
  239. package/src/lib/hugo-markdown.ts +46 -0
  240. package/src/lib/image.ts +17 -4
  241. package/src/lib/markdown-manager.ts +392 -2
  242. package/src/lib/post-body-html.ts +11 -4
  243. package/src/lib/resolve-config.ts +58 -1
  244. package/src/lib/schemas.ts +50 -5
  245. package/src/lib/thread-fold.ts +3 -3
  246. package/src/lib/timeline.ts +1 -1
  247. package/src/lib/tiptap-to-markdown.ts +13 -7
  248. package/src/lib/url.ts +20 -0
  249. package/src/lib/view.ts +2 -29
  250. package/src/node/__tests__/cli-export.test.ts +2 -2
  251. package/src/node/__tests__/cli-setup.test.ts +163 -0
  252. package/src/node/__tests__/cli-site-snapshot.test.ts +73 -0
  253. package/src/node/__tests__/cli-site-token-env.test.ts +4 -1
  254. package/src/node/__tests__/cli-snapshot-meta.test.ts +84 -0
  255. package/src/node/__tests__/runtime.test.ts +38 -0
  256. package/src/node/index.ts +2 -0
  257. package/src/node/request-handler.ts +3 -1
  258. package/src/routes/api/__tests__/posts.test.ts +24 -0
  259. package/src/routes/api/__tests__/upload.test.ts +34 -0
  260. package/src/routes/api/export.ts +3 -3
  261. package/src/routes/api/internal/search-reindex.ts +1 -1
  262. package/src/routes/api/internal/sites.ts +0 -1
  263. package/src/routes/api/posts.ts +2 -0
  264. package/src/routes/api/public/posts.ts +21 -1
  265. package/src/routes/api/upload.ts +10 -3
  266. package/src/routes/compose.tsx +4 -0
  267. package/src/routes/dash/__tests__/github-sync-app.test.ts +365 -0
  268. package/src/routes/dash/settings.tsx +212 -70
  269. package/src/routes/pages/__tests__/post-page-round-trips.test.ts +211 -0
  270. package/src/routes/pages/__tests__/thread-order.test.ts +179 -0
  271. package/src/routes/pages/archive.tsx +17 -11
  272. package/src/routes/pages/featured.tsx +11 -5
  273. package/src/routes/pages/page.tsx +53 -31
  274. package/src/routes/pages/search.tsx +4 -2
  275. package/src/runtime/__tests__/readiness.test.ts +23 -0
  276. package/src/runtime/node.ts +49 -0
  277. package/src/runtime/readiness.ts +15 -0
  278. package/src/services/__tests__/bootstrap-setup-instance.test.ts +230 -0
  279. package/src/services/__tests__/custom-url.test.ts +34 -0
  280. package/src/services/__tests__/github-app-installations.test.ts +153 -0
  281. package/src/services/__tests__/github-sync-push.test.ts +46 -0
  282. package/src/services/__tests__/media.test.ts +31 -271
  283. package/src/services/__tests__/path.test.ts +56 -0
  284. package/src/services/__tests__/post-timeline.test.ts +127 -0
  285. package/src/services/__tests__/post.test.ts +74 -0
  286. package/src/services/bootstrap.ts +263 -44
  287. package/src/services/custom-url.ts +2 -2
  288. package/src/services/export-theme/layouts/_default/alias.html +27 -1
  289. package/src/services/export-theme/layouts/_default/list.html +2 -63
  290. package/src/services/export-theme/layouts/_default/rss.xml +27 -38
  291. package/src/services/export-theme/layouts/collections/list.html +3 -3
  292. package/src/services/export-theme/layouts/featured/list.html +1 -4
  293. package/src/services/export-theme/layouts/index.html +40 -26
  294. package/src/services/export-theme/layouts/partials/collection-members.html +100 -0
  295. package/src/services/export-theme/layouts/partials/collection-threads.html +33 -0
  296. package/src/services/export-theme/layouts/partials/featured-members.html +35 -0
  297. package/src/services/export-theme/layouts/partials/featured-thread.html +1 -1
  298. package/src/services/export-theme/layouts/partials/footer.html +1 -1
  299. package/src/services/export-theme/layouts/partials/head.html +1 -1
  300. package/src/services/export-theme/layouts/partials/header.html +5 -3
  301. package/src/services/export-theme/layouts/partials/jant-data.html +23 -0
  302. package/src/services/export-theme/layouts/partials/latest-members.html +48 -0
  303. package/src/services/export-theme/layouts/partials/smart-collection-members.html +129 -0
  304. package/src/services/export-theme/layouts/partials/thread-preview.html +1 -1
  305. package/src/services/export-theme/layouts/post/list.html +1 -1
  306. package/src/services/export-theme/layouts/smart_collection/list.html +24 -0
  307. package/src/services/export-theme/styles/main.css +0 -1
  308. package/src/services/export-theme/theme.toml +1 -1
  309. package/src/services/export.ts +630 -73
  310. package/src/services/github-app-installations.ts +171 -4
  311. package/src/services/github-sync.ts +69 -15
  312. package/src/services/mcp.ts +19 -1
  313. package/src/services/media.ts +9 -220
  314. package/src/services/path.ts +34 -1
  315. package/src/services/post.ts +214 -39
  316. package/src/services/site-admin.ts +3 -7
  317. package/src/services/site.ts +83 -31
  318. package/src/styles/ui.css +7 -119
  319. package/src/types/app-context.ts +16 -0
  320. package/src/types/bindings.ts +5 -0
  321. package/src/types/operations.ts +10 -0
  322. package/src/ui/dash/settings/GeneralContent.tsx +10 -8
  323. package/bin/commands/export.js +0 -118
  324. package/bin/commands/import-site.js +0 -2561
  325. package/bin/commands/migrate-text-attachments.js +0 -181
  326. package/dist/github-sync-BPAvT999.js +0 -7709
  327. package/src/client/multipart-upload.ts +0 -206
  328. package/src/client/tiptap/exitable-marks.ts +0 -73
  329. package/src/routes/api/__tests__/upload-multipart.test.ts +0 -739
  330. package/src/routes/api/internal/text-attachments.ts +0 -60
  331. package/src/routes/api/upload-multipart.ts +0 -366
@@ -1,35 +1,110 @@
1
+ import { readFileSync } from "node:fs";
1
2
  import { readdir } from "node:fs/promises";
2
3
  import { join, relative } from "node:path";
4
+ import {
5
+ listSchemaMigrationFiles,
6
+ resolveBundledSchemaMigrationsDir,
7
+ } from "./migration-artifacts.js";
3
8
 
4
9
  export const SNAPSHOT_FORMAT = "jant-site-snapshot";
5
10
  export const SNAPSHOT_VERSION = 2;
6
11
  export const SUPPORTED_SNAPSHOT_VERSIONS = [1, SNAPSHOT_VERSION];
7
12
 
13
+ /**
14
+ * Site content, in the order rows are inserted on import.
15
+ *
16
+ * Membership is what this list decides: a table absent from it is never read,
17
+ * so its rows leave no trace in the snapshot and `--replace` cannot clear them.
18
+ *
19
+ * The order here is kept as a foreign-key topological sort for readability, but
20
+ * it is not what an export follows — `sortExportTables` re-sorts by
21
+ * `TABLE_EXPORT_ORDER` in `sql-export.js`, and that is the list to change when
22
+ * the dump order has to change. `src/__tests__/snapshot-tables.test.ts` checks
23
+ * the sorted result for that reason.
24
+ */
8
25
  export const SNAPSHOT_TABLES = [
9
26
  "site_setting",
10
27
  "collection",
11
- "nav_item",
12
- "collection_directory_item",
28
+ "smart_collection",
13
29
  "post",
14
30
  "thread_collection",
31
+ "nav_item",
32
+ "collection_directory_item",
15
33
  "path_registry",
16
34
  "media",
17
35
  ];
18
36
 
37
+ /**
38
+ * The same content, in the order `--replace` deletes it: children first, so no
39
+ * delete depends on a cascade to clean up after it. `site_setting` is absent on
40
+ * purpose — `buildReplaceSql` clears it by key, because a site's settings hold
41
+ * more than the snapshot carries.
42
+ */
19
43
  export const SNAPSHOT_CLEAR_TABLES = [
20
- "thread_collection",
21
44
  "media",
22
45
  "path_registry",
23
46
  "collection_directory_item",
24
47
  "nav_item",
48
+ "thread_collection",
25
49
  "post",
50
+ "smart_collection",
26
51
  "collection",
27
52
  ];
28
53
 
54
+ /**
55
+ * Site-scoped tables the snapshot deliberately leaves alone.
56
+ *
57
+ * Every table carrying a `site_id` has to appear here or in `SNAPSHOT_TABLES`
58
+ * — `src/__tests__/snapshot-tables.test.ts` fails the build otherwise, so a new
59
+ * table forces a decision rather than being silently dropped. The reasons fall
60
+ * into three groups: auth and routing shell that a content restore must
61
+ * preserve, credentials and external integration bindings that do not travel
62
+ * with content, and transient runtime bookkeeping.
63
+ */
64
+ export const SNAPSHOT_EXCLUDED_TABLES = [
65
+ // Auth and routing shell. `--replace` restores content into an existing
66
+ // site; its members and domains belong to the deployment, not the content.
67
+ "site_member",
68
+ "site_domain",
69
+ // Credentials. Reissued per deployment, never copied between sites. The demo
70
+ // rebuild clears these through the internal admin route instead.
71
+ "api_token",
72
+ // External integration bindings. They point at an installation or a chat on
73
+ // someone else's service, so restoring them into another site would aim that
74
+ // site at a binding it does not own.
75
+ "github_app_installation",
76
+ "telegram_binding",
77
+ "telegram_pending_binding",
78
+ "telegram_media_group_item",
79
+ // Transient runtime bookkeeping, rebuilt by the runtime as it goes:
80
+ // in-flight uploads, and the recycle-window ledger for deleted objects.
81
+ "upload_session",
82
+ "storage_purge",
83
+ ];
84
+
85
+ /**
86
+ * Settings the snapshot carries: the site's published identity and appearance.
87
+ *
88
+ * `site_setting` holds more than a site's content — deployment wiring, secrets,
89
+ * integration bindings, local UI state — so both the export and `--replace`
90
+ * work through this allowlist rather than the whole table. Membership is what
91
+ * it decides: a key absent from it is neither exported nor cleared on import.
92
+ *
93
+ * Every DB-backed key in `CONFIG_FIELDS` has to appear here or in
94
+ * `SNAPSHOT_EXCLUDED_SETTING_KEYS`, and
95
+ * `src/__tests__/snapshot-settings.test.ts` fails the build otherwise, so a new
96
+ * setting forces a decision instead of being silently dropped.
97
+ */
29
98
  export const SNAPSHOT_SETTING_KEYS = [
30
99
  "SITE_NAME",
31
100
  "SITE_DESCRIPTION",
101
+ // The language trio travels together. `post.language` and
102
+ // `post.translation_group_id` are already carried by the whole-row `post`
103
+ // dump, so leaving the switch behind restored a site whose posts were
104
+ // stamped per language while every per-language view was gone.
32
105
  "SITE_LANGUAGE",
106
+ "MULTILINGUAL_ENABLED",
107
+ "ADDITIONAL_LANGUAGES",
33
108
  "MAIN_RSS_FEED",
34
109
  "PUBLIC_API_ENABLED",
35
110
  "RSS_FEEDS_ENABLED",
@@ -48,6 +123,68 @@ export const SNAPSHOT_SETTING_KEYS = [
48
123
  "NOINDEX",
49
124
  ];
50
125
 
126
+ /**
127
+ * DB-backed settings the snapshot deliberately leaves alone.
128
+ *
129
+ * `envOnly` keys are absent from both lists on purpose: they never reach
130
+ * `site_setting`, so there is no row to carry or clear.
131
+ */
132
+ export const SNAPSHOT_EXCLUDED_SETTING_KEYS = [
133
+ // The operator's own dashboard locale, not the site's published language.
134
+ // A content restore should not relabel the dashboard of whoever runs the
135
+ // target site.
136
+ "DASHBOARD_LANGUAGE",
137
+ // Sizing and pacing knobs. They describe how much the target deployment
138
+ // serves at a time, not what it publishes, and they carry env defaults the
139
+ // deployment picked.
140
+ "ARCHIVE_DEFAULT_LAYOUT",
141
+ "PAGE_SIZE",
142
+ "SEARCH_PAGE_SIZE",
143
+ "ARCHIVE_PAGE_SIZE",
144
+ "SUMMARY_MAX_PARAGRAPHS",
145
+ "SUMMARY_MAX_CHARS",
146
+ "RSS_FEED_LIMIT",
147
+ "RSS_PUBLISH_DELAY_SECONDS",
148
+ // Code injection. `CUSTOM_CSS` is declarative and travels; these two are
149
+ // executable markup, and importing an archive must not be a way to run
150
+ // script on the importing site.
151
+ "CUSTOM_HEAD_HTML",
152
+ "CUSTOM_BODY_END_HTML",
153
+ // Being listed in the Jant Discover directory is the site owner's consent,
154
+ // and the announcement state below it belongs to the announcing instance.
155
+ "DISCOVER",
156
+ "DISCOVER_ANNOUNCE_STATE",
157
+ // Local UI state: which affordances this author has already been shown, and
158
+ // how far setup got.
159
+ "DISCOVERY_COMPOSE_OPEN_SHORTCUT_AT",
160
+ "DISCOVERY_SLASH_COMMAND_AT",
161
+ "ONBOARDING_STATUS",
162
+ // Credential. Reissued per deployment, never copied between sites.
163
+ "PASSWORD_RESET_TOKEN",
164
+ // External integration bindings, their secrets, and their sync bookkeeping.
165
+ // They point at a repo, an installation, or a chat on someone else's
166
+ // service, so restoring them would aim the target site at a binding it does
167
+ // not own — the same reason `github_app_installation` and `telegram_binding`
168
+ // are excluded tables.
169
+ "GITHUB_SYNC_ENABLED",
170
+ "GITHUB_SYNC_REPO",
171
+ "GITHUB_SYNC_TOKEN",
172
+ "GITHUB_SYNC_WEBHOOK_SECRET",
173
+ "GITHUB_SYNC_WEBHOOK_ID",
174
+ "GITHUB_SYNC_LAST_PUSH_SHA",
175
+ "GITHUB_SYNC_LAST_PUSH_AT",
176
+ "GITHUB_SYNC_PENDING",
177
+ "GITHUB_SYNC_PENDING_AT",
178
+ "GITHUB_SYNC_DIRTY",
179
+ "GITHUB_SYNC_LAST_ERROR",
180
+ "GITHUB_SYNC_AUTH_MODE",
181
+ "GITHUB_SYNC_APP_INSTALLATION_ID",
182
+ "TELEGRAM_BOT_TOKEN",
183
+ "TELEGRAM_BOT_ID",
184
+ "TELEGRAM_BOT_USERNAME",
185
+ "TELEGRAM_BOT_WEBHOOK_SECRET",
186
+ ];
187
+
51
188
  function escapeSqlString(value) {
52
189
  return String(value).replaceAll("'", "''");
53
190
  }
@@ -78,6 +215,12 @@ const SELECT_SQL_BY_TABLE = {
78
215
  WHERE "site_id" = ?1
79
216
  ORDER BY "position", "id"
80
217
  `,
218
+ smart_collection: `
219
+ SELECT *
220
+ FROM "smart_collection"
221
+ WHERE "site_id" = ?1
222
+ ORDER BY "created_at", "id"
223
+ `,
81
224
  post: `
82
225
  SELECT *
83
226
  FROM "post"
@@ -118,6 +261,14 @@ export function getSnapshotSelectSql(tableName, siteId) {
118
261
  return statement.trim().replaceAll("?1", `'${escapeSqlString(siteId)}'`);
119
262
  }
120
263
 
264
+ /**
265
+ * SQL listing a site's stored media objects: originals and video posters.
266
+ *
267
+ * @param {string} siteId Site whose media rows to read
268
+ * @returns {string} A query returning `key` and `contentType` columns
269
+ * @example
270
+ * collectSnapshotObjects(await query(buildSnapshotStorageQuery(site.id)))
271
+ */
121
272
  export function buildSnapshotStorageQuery(siteId) {
122
273
  return `
123
274
  SELECT "key", "contentType"
@@ -146,6 +297,27 @@ export function buildSnapshotStorageQuery(siteId) {
146
297
  `.trim();
147
298
  }
148
299
 
300
+ /**
301
+ * A storage object a snapshot carries.
302
+ *
303
+ * @typedef {object} SnapshotObject
304
+ * @property {string} key Storage key
305
+ * @property {string} contentType MIME type, or `""` when neither the row nor
306
+ * the key's extension gives one
307
+ */
308
+
309
+ /**
310
+ * Deduplicate the rows of `buildSnapshotStorageQuery` into storage objects.
311
+ *
312
+ * Rows with a blank key are skipped. A row without a content type takes one
313
+ * from the key's extension.
314
+ *
315
+ * @param {Record<string, unknown>[]} rows Rows with `key` and `contentType`
316
+ * @returns {SnapshotObject[]} One entry per distinct key
317
+ * @example
318
+ * collectSnapshotObjects([{ key: "media/a.png", contentType: null }])
319
+ * // => [{ key: "media/a.png", contentType: "image/png" }]
320
+ */
149
321
  export function collectSnapshotObjects(rows) {
150
322
  const objects = new Map();
151
323
 
@@ -179,6 +351,43 @@ export function snapshotObjectPath(key) {
179
351
 
180
352
  export const SNAPSHOT_DIALECTS = ["sqlite", "pg"];
181
353
 
354
+ /**
355
+ * Version of the installed `@jant/core`, which a snapshot records as `jant`.
356
+ *
357
+ * @returns {string} The package version, e.g. `0.8.0`
358
+ */
359
+ export function readInstalledJantVersion() {
360
+ const packageJson = JSON.parse(
361
+ readFileSync(new URL("../../package.json", import.meta.url), "utf8"),
362
+ );
363
+ return String(packageJson.version);
364
+ }
365
+
366
+ /**
367
+ * Schema migrations the installed `@jant/core` ships for a dialect, oldest
368
+ * first.
369
+ *
370
+ * @param {"sqlite" | "pg"} dialect Snapshot dialect
371
+ * @returns {string[]} Migration tags, e.g. `0034_cheerful_rumiko_fujikawa`
372
+ */
373
+ export function listInstalledSchemaTags(dialect) {
374
+ return listSchemaMigrationFiles(
375
+ resolveBundledSchemaMigrationsDir(dialect),
376
+ ).map((migration) => migration.tag);
377
+ }
378
+
379
+ /**
380
+ * Build a snapshot's `meta.json`.
381
+ *
382
+ * Besides the format, it records the `@jant/core` version that wrote the
383
+ * snapshot (`jant`) and, when the dialect is known, the last schema migration
384
+ * that version ships (`schema`). The CLI that exports is the one the site
385
+ * runs and migrates with, so `schema` is the schema the rows were read from.
386
+ *
387
+ * @param {{ id: string, key: string }} site The exported site
388
+ * @param {{ dialect?: "sqlite" | "pg" }} [options] Source database dialect
389
+ * @returns {SnapshotMeta} The object to write as `meta.json`
390
+ */
182
391
  export function buildSnapshotMeta(site, options = {}) {
183
392
  const dialect = options.dialect;
184
393
  if (dialect && !SNAPSHOT_DIALECTS.includes(dialect)) {
@@ -187,10 +396,14 @@ export function buildSnapshotMeta(site, options = {}) {
187
396
  );
188
397
  }
189
398
 
399
+ const schema = dialect ? listInstalledSchemaTags(dialect).at(-1) : undefined;
400
+
190
401
  return {
191
402
  format: SNAPSHOT_FORMAT,
192
403
  version: SNAPSHOT_VERSION,
193
404
  ...(dialect ? { dialect } : {}),
405
+ jant: readInstalledJantVersion(),
406
+ ...(schema ? { schema } : {}),
194
407
  site: {
195
408
  id: site.id,
196
409
  key: site.key,
@@ -198,6 +411,32 @@ export function buildSnapshotMeta(site, options = {}) {
198
411
  };
199
412
  }
200
413
 
414
+ /**
415
+ * A snapshot's `meta.json`, as `assertSnapshotMeta` accepts it.
416
+ *
417
+ * @typedef {object} SnapshotMeta
418
+ * @property {typeof SNAPSHOT_FORMAT} format
419
+ * @property {number} version One of `SUPPORTED_SNAPSHOT_VERSIONS`
420
+ * @property {"sqlite" | "pg"} [dialect] Absent from snapshots that predate it
421
+ * @property {string} [jant] The `@jant/core` version that wrote the snapshot;
422
+ * absent before 0.8.0
423
+ * @property {string} [schema] The last schema migration of that version, for
424
+ * `dialect`; absent before 0.8.0
425
+ * @property {{ id: string, key: string }} [site] The site the snapshot was
426
+ * exported from; absent from legacy snapshots
427
+ * @property {unknown} [tables] Listed by legacy snapshots only
428
+ */
429
+
430
+ /**
431
+ * Refuse a `meta.json` this version cannot import.
432
+ *
433
+ * @param {unknown} meta Parsed `meta.json`
434
+ * @returns {asserts meta is SnapshotMeta}
435
+ * @throws {Error} When the format, version, dialect, or site is not supported
436
+ * @example
437
+ * const meta = JSON.parse(await readFile(metaPath, "utf8"));
438
+ * assertSnapshotMeta(meta);
439
+ */
201
440
  export function assertSnapshotMeta(meta) {
202
441
  if (!meta || typeof meta !== "object") {
203
442
  throw new Error("Snapshot meta.json is missing or invalid.");
@@ -230,6 +469,38 @@ export function assertSnapshotMeta(meta) {
230
469
  ) {
231
470
  throw new Error("Snapshot meta site must contain string id and key.");
232
471
  }
472
+
473
+ for (const field of ["jant", "schema"]) {
474
+ if (meta[field] !== undefined && typeof meta[field] !== "string") {
475
+ throw new Error(`Snapshot meta ${field} must be a string.`);
476
+ }
477
+ }
478
+ }
479
+
480
+ /**
481
+ * Refuse a snapshot written by a newer Jant than the installed one.
482
+ *
483
+ * A snapshot's rows fit the schema it records. When the installed
484
+ * `@jant/core` does not ship that migration, its schema is older than the
485
+ * snapshot's, and the rows can name columns it doesn't have. Snapshots from
486
+ * before 0.8.0 record no schema and are accepted.
487
+ *
488
+ * @param {SnapshotMeta} meta Checked by `assertSnapshotMeta`
489
+ * @returns {void}
490
+ * @throws {Error} When the installed package lacks the snapshot's schema
491
+ * @example
492
+ * assertSnapshotSchemaInstalled({ format: "jant-site-snapshot", version: 2, schema: "9999_later" });
493
+ * // throws: This snapshot was written by a newer Jant …
494
+ */
495
+ export function assertSnapshotSchemaInstalled(meta) {
496
+ if (typeof meta.schema !== "string") return;
497
+ const dialect = meta.dialect ?? "sqlite";
498
+ if (listInstalledSchemaTags(dialect).includes(meta.schema)) return;
499
+
500
+ const writer = meta.jant ? `Jant ${meta.jant}` : "a newer Jant";
501
+ throw new Error(
502
+ `This snapshot was written by ${writer}, whose schema reaches ${meta.schema}. The installed @jant/core (${readInstalledJantVersion()}) doesn't have that migration. Upgrade @jant/core, run jant migrate, then import again.`,
503
+ );
233
504
  }
234
505
 
235
506
  /**
@@ -262,7 +533,7 @@ export function assertSnapshotDialectMatches(meta, targetDialect) {
262
533
  `Snapshot dialect mismatch: source is ${sourceDialect}, target is ${targetDialect}.`,
263
534
  "Snapshot db.sql is dialect-specific (BLOB literals, generated columns, FTS, etc.)",
264
535
  "and cannot be replayed across SQLite and Postgres safely.",
265
- "Use `jant site export <url>` (HTTP, dialect-neutral) to move content between",
536
+ "Use `jant site export --url <url>` (HTTP, dialect-neutral) to move content between",
266
537
  "different DB engines.",
267
538
  ].join("\n"),
268
539
  );
@@ -274,6 +545,15 @@ export function isLegacySnapshotMeta(meta) {
274
545
  return !meta?.site || tables.includes("setting");
275
546
  }
276
547
 
548
+ /**
549
+ * The site a snapshot was exported from, for creating or remapping the target.
550
+ *
551
+ * @param {SnapshotMeta} meta Snapshot meta accepted by `assertSnapshotMeta`
552
+ * @returns {{ id: string, key: string } | undefined} The source site, or
553
+ * undefined for a legacy snapshot, which records none
554
+ * @example
555
+ * const snapshotSite = getSnapshotBootstrapSite(meta);
556
+ */
277
557
  export function getSnapshotBootstrapSite(meta) {
278
558
  if (isLegacySnapshotMeta(meta)) {
279
559
  return undefined;
@@ -285,6 +565,18 @@ export function getSnapshotBootstrapSite(meta) {
285
565
  };
286
566
  }
287
567
 
568
+ /**
569
+ * Refuse to import a snapshot into a site other than the one it came from.
570
+ *
571
+ * Legacy snapshots record no site and pass.
572
+ *
573
+ * @param {SnapshotMeta} meta Snapshot meta accepted by `assertSnapshotMeta`
574
+ * @param {{ id: string }} site The import target
575
+ * @returns {void}
576
+ * @throws {Error} When the snapshot names a different site
577
+ * @example
578
+ * validateSnapshotTargetSite(meta, targetSite);
579
+ */
288
580
  export function validateSnapshotTargetSite(meta, site) {
289
581
  if (isLegacySnapshotMeta(meta)) {
290
582
  return;
@@ -297,6 +589,17 @@ export function validateSnapshotTargetSite(meta, site) {
297
589
  }
298
590
  }
299
591
 
592
+ /**
593
+ * Replace a snapshot's source site id with the target's throughout its SQL.
594
+ *
595
+ * @param {string} sql Snapshot `db.sql`
596
+ * @param {string} sourceSiteId Site the snapshot was exported from; empty
597
+ * leaves the SQL unchanged
598
+ * @param {string} targetSiteId Site the snapshot is imported into
599
+ * @returns {string} The rewritten SQL
600
+ * @example
601
+ * rewriteSnapshotSiteIdentifiers(dbSql, snapshotSite.id, targetSite.id)
602
+ */
300
603
  export function rewriteSnapshotSiteIdentifiers(
301
604
  sql,
302
605
  sourceSiteId,
@@ -311,6 +614,17 @@ export function rewriteSnapshotSiteIdentifiers(
311
614
  return sql.replaceAll(escapedSource, escapedTarget);
312
615
  }
313
616
 
617
+ /**
618
+ * Move a storage key from the source site's namespace to the target's.
619
+ *
620
+ * @param {string} key Storage key as exported
621
+ * @param {string} sourceSiteId Site the snapshot was exported from; empty
622
+ * leaves the key unchanged
623
+ * @param {string} targetSiteId Site the snapshot is imported into
624
+ * @returns {string} The key to store the object under
625
+ * @example
626
+ * remapSnapshotObjectKey(entry.key, snapshotSite.id, targetSite.id)
627
+ */
314
628
  export function remapSnapshotObjectKey(key, sourceSiteId, targetSiteId) {
315
629
  if (!sourceSiteId || sourceSiteId === targetSiteId) {
316
630
  return key;
@@ -325,6 +639,12 @@ export function remapSnapshotObjectKey(key, sourceSiteId, targetSiteId) {
325
639
  * export time (with forward slashes). If the snapshot was produced by a
326
640
  * different site than the import target, callers apply
327
641
  * `remapSnapshotObjectKey()` before uploading.
642
+ *
643
+ * @param {string} rootDir Snapshot directory
644
+ * @returns {Promise<{ key: string, filePath: string, contentType: string }[]>}
645
+ * Files sorted by key; empty when there is no `objects/` directory
646
+ * @example
647
+ * const objectFiles = await enumerateSnapshotObjectFiles(snapshotDir);
328
648
  */
329
649
  export async function enumerateSnapshotObjectFiles(rootDir) {
330
650
  const objectsRoot = join(rootDir, "objects");
@@ -485,6 +805,16 @@ function splitSqlStatements(sql) {
485
805
  return statements;
486
806
  }
487
807
 
808
+ /**
809
+ * Scope a legacy single-site dump to a site: global `setting` rows become
810
+ * `site_setting` rows, and site-owned tables gain a `site_id` column.
811
+ *
812
+ * @param {string} sql Legacy snapshot `db.sql`
813
+ * @param {string} siteId Site the snapshot is imported into
814
+ * @returns {string} Site-scoped SQL
815
+ * @example
816
+ * rewriteLegacySnapshotSql(dbSql, targetSite.id)
817
+ */
488
818
  export function rewriteLegacySnapshotSql(sql, siteId) {
489
819
  const rewrittenStatements = splitSqlStatements(sql).map((statement) => {
490
820
  const normalized = statement.trim();
@@ -840,6 +1170,58 @@ function parseSqlScalar(raw) {
840
1170
  return trimmed;
841
1171
  }
842
1172
 
1173
+ /**
1174
+ * SQL clearing a site's snapshot content before a replacing import.
1175
+ *
1176
+ * @param {string} siteId Site to clear
1177
+ * @returns {string} `DELETE` statements for every `SNAPSHOT_CLEAR_TABLES`
1178
+ * table and the snapshot's setting keys
1179
+ * @example
1180
+ * await execute(`${buildReplaceSql(site.id)}\n${dbSql}`);
1181
+ */
1182
+ /**
1183
+ * Order `post` rows so every row comes after its Thread root and the post it
1184
+ * replies to.
1185
+ *
1186
+ * The dump reads posts by creation time, and `(site_id, thread_id)` and
1187
+ * `(site_id, reply_to_id)` are foreign keys. A post moved into a Thread keeps
1188
+ * its own creation time, and an import restores creation times, so a reply
1189
+ * can be older than its root; inserted in creation order it names a row that
1190
+ * isn't there yet, and the whole import fails. Otherwise the order is kept.
1191
+ *
1192
+ * @param {Record<string, unknown>[]} rows - `post` rows in dump order
1193
+ * @returns {Record<string, unknown>[]} The same rows, parents first
1194
+ * @example
1195
+ * orderSnapshotPostRows([reply, root]); // [root, reply]
1196
+ */
1197
+ export function orderSnapshotPostRows(rows) {
1198
+ const byId = new Map(rows.map((row) => [row.id, row]));
1199
+ const placed = new Set();
1200
+ const ordered = [];
1201
+
1202
+ const place = (row, visiting) => {
1203
+ if (placed.has(row.id) || visiting.has(row.id)) return;
1204
+ visiting.add(row.id);
1205
+ for (const parentId of [row.thread_id, row.reply_to_id]) {
1206
+ const parent = parentId !== row.id ? byId.get(parentId) : undefined;
1207
+ if (parent) place(parent, visiting);
1208
+ }
1209
+ placed.add(row.id);
1210
+ ordered.push(row);
1211
+ };
1212
+
1213
+ for (const row of rows) place(row, new Set());
1214
+ return ordered;
1215
+ }
1216
+
1217
+ /**
1218
+ * SQL a snapshot import runs before its inserts on SQLite and D1: foreign
1219
+ * keys are checked at commit rather than per row, so a snapshot written
1220
+ * before posts were ordered parents-first still loads. Postgres has no
1221
+ * equivalent for its non-deferrable keys; its snapshots are ordered at export.
1222
+ */
1223
+ export const DEFER_FOREIGN_KEYS_SQL = "PRAGMA defer_foreign_keys = ON;";
1224
+
843
1225
  export function buildReplaceSql(siteId) {
844
1226
  const statements = [];
845
1227
 
@@ -856,6 +1238,41 @@ export function buildReplaceSql(siteId) {
856
1238
  return statements.join("\n");
857
1239
  }
858
1240
 
1241
+ /** The storage drivers a `media` row can name as its `provider`. */
1242
+ const MEDIA_STORAGE_PROVIDERS = ["r2", "s3", "local"];
1243
+
1244
+ /**
1245
+ * SQL recording a site's media under the storage an import just wrote it to.
1246
+ *
1247
+ * A snapshot carries each media row's `provider` from the site it was exported
1248
+ * from, but the import uploads every object into the target's own storage. A
1249
+ * row exported on R2 and imported into S3 would still say `r2`, and everything
1250
+ * that reads `provider` as where the bytes live goes wrong: the public URL looks
1251
+ * for `R2_PUBLIC_URL`, replacing the avatar or favicon misses the existing row
1252
+ * and inserts a second one for the same key, and a trashed object is never
1253
+ * purged because the sweep only handles the active driver. Run after the
1254
+ * snapshot's inserts, while every media row of the site is one the snapshot
1255
+ * brought.
1256
+ *
1257
+ * @param {string} siteId - Site whose media was imported
1258
+ * @param {string} provider - Storage driver the import uploaded through
1259
+ * @returns {string} An `UPDATE` statement for the site's media rows
1260
+ * @throws {Error} When `provider` is not one of r2, s3, or local
1261
+ * @example
1262
+ * await execute(
1263
+ * `${buildReplaceSql(site.id)}\n${dbSql}\n${buildMediaProviderSql(site.id, "s3")}`,
1264
+ * );
1265
+ */
1266
+ export function buildMediaProviderSql(siteId, provider) {
1267
+ if (!MEDIA_STORAGE_PROVIDERS.includes(provider)) {
1268
+ throw new Error(
1269
+ `Snapshot import cannot record media under storage driver "${provider}". Expected one of: ${MEDIA_STORAGE_PROVIDERS.join(", ")}.`,
1270
+ );
1271
+ }
1272
+
1273
+ return `UPDATE "media" SET "provider" = '${provider}' WHERE "site_id" = '${escapeSqlString(siteId)}';`;
1274
+ }
1275
+
859
1276
  export function normalizeD1Sql(sql) {
860
1277
  return sql
861
1278
  .replace(/^\s*BEGIN(?:\s+TRANSACTION)?\s*;\s*$/gim, "")
@@ -1,4 +1,17 @@
1
- const TABLE_EXPORT_ORDER = [
1
+ /**
2
+ * The order rows are dumped, and so the order they are replayed on import.
3
+ *
4
+ * It is a foreign-key topological sort: a table follows everything it points
5
+ * at. `sortExportTables` applies it to whatever table list it is handed, so
6
+ * this — not the caller's list — is what decides an export's order.
7
+ *
8
+ * A table missing from here is not an ordering no-op. Unknown names sort after
9
+ * every known one, so a new child table lands at the end, behind its own
10
+ * parents, and the dump only fails once there is a row to violate the
11
+ * constraint. `snapshot-tables.test.ts` checks the sorted result, not the
12
+ * caller's list, for that reason.
13
+ */
14
+ export const TABLE_EXPORT_ORDER = [
2
15
  "site",
3
16
  "user",
4
17
  "account",
@@ -8,11 +21,15 @@ const TABLE_EXPORT_ORDER = [
8
21
  "site_setting",
9
22
  "site_member",
10
23
  "collection",
11
- "nav_item",
12
- "collection_directory_item",
24
+ // Before the three tables that hold a key into it: `nav_item`,
25
+ // `collection_directory_item` and `path_registry`.
26
+ "smart_collection",
13
27
  "api_token",
14
28
  "post",
15
29
  "thread_collection",
30
+ // After `post`: a `page` nav item carries a `post_id`.
31
+ "nav_item",
32
+ "collection_directory_item",
16
33
  "path_registry",
17
34
  "media",
18
35
  ];
@@ -167,8 +184,48 @@ export async function getTableColumns(
167
184
  .map((row) => String(row.name));
168
185
  }
169
186
 
187
+ /**
188
+ * Read an ordered SELECT a page at a time.
189
+ *
190
+ * `LIMIT … OFFSET …` is appended to the statement, so it must end in an
191
+ * ORDER BY with a unique tiebreaker. Pages are separate reads: rows written
192
+ * between two of them can be skipped or repeated, which is why a snapshot
193
+ * should be taken of a site nobody is writing to.
194
+ *
195
+ * @param {{ query(sql: string): Promise<Record<string, unknown>[]> }} queryRunner
196
+ * @param {string} selectSql - An ordered SELECT with no LIMIT
197
+ * @param {number} pageSize - Rows per read
198
+ * @returns {Promise<Record<string, unknown>[]>} Every row, in order
199
+ * @example
200
+ * await queryAllPages(runner, 'SELECT * FROM "post" ORDER BY rowid', 200);
201
+ */
202
+ async function queryAllPages(queryRunner, selectSql, pageSize) {
203
+ const base = selectSql.trim();
204
+ const rows = [];
205
+ for (let offset = 0; ; offset += pageSize) {
206
+ const page = await queryRunner.query(
207
+ `${base} LIMIT ${pageSize} OFFSET ${offset}`,
208
+ );
209
+ rows.push(...page);
210
+ if (page.length < pageSize) return rows;
211
+ }
212
+ }
213
+
214
+ /**
215
+ * Dump tables as INSERT statements.
216
+ *
217
+ * `options.pageSize` reads each table in pages. D1 needs it: every query runs
218
+ * through `wrangler d1 execute --json`, and one SELECT of a real site's
219
+ * `post` table outgrew the output the CLI can buffer.
220
+ * `options.orderRowsByTable` reorders a table's rows before they are written,
221
+ * for inserts that must follow their own foreign keys.
222
+ */
170
223
  export async function dumpDatabaseToSql(queryRunner, options) {
171
224
  const dialect = options.dialect ?? "sqlite";
225
+ const pageSize =
226
+ Number.isInteger(options.pageSize) && options.pageSize > 0
227
+ ? options.pageSize
228
+ : null;
172
229
  const onProgress =
173
230
  typeof options.onProgress === "function" ? options.onProgress : null;
174
231
  const configuredTables = Array.isArray(options.tables)
@@ -194,8 +251,14 @@ export async function dumpDatabaseToSql(queryRunner, options) {
194
251
 
195
252
  const selectSql =
196
253
  options.selectSqlByTable?.[tableName] ||
197
- `SELECT * FROM ${quoteIdentifier(tableName)}`;
198
- const rows = await queryRunner.query(selectSql);
254
+ (pageSize && dialect === "sqlite"
255
+ ? `SELECT * FROM ${quoteIdentifier(tableName)} ORDER BY rowid`
256
+ : `SELECT * FROM ${quoteIdentifier(tableName)}`);
257
+ const readRows = pageSize
258
+ ? await queryAllPages(queryRunner, selectSql, pageSize)
259
+ : await queryRunner.query(selectSql);
260
+ const orderRows = options.orderRowsByTable?.[tableName];
261
+ const rows = orderRows ? orderRows(readRows) : readRows;
199
262
  if (rows.length === 0) {
200
263
  continue;
201
264
  }