@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.
- package/bin/commands/assets/prepare.js +3 -3
- package/bin/commands/db/export.js +115 -2
- package/bin/commands/deploy.js +11 -3
- package/bin/commands/{search-reindex.js → search/reindex.js} +5 -5
- package/bin/commands/setup.js +136 -0
- package/bin/commands/site/export.js +117 -68
- package/bin/commands/site/import.js +3074 -2
- package/bin/commands/site/pull-media.js +2 -6
- package/bin/commands/site/snapshot/export.js +18 -60
- package/bin/commands/site/snapshot/import.js +24 -23
- package/bin/commands/telegram/register-webhooks.js +48 -23
- package/bin/jant.js +16 -11
- package/bin/lib/command-registry.js +120 -0
- package/bin/lib/d1-query.js +87 -2
- package/bin/lib/hugo-markdown.js +4 -0
- package/bin/lib/migration-artifacts.js +19 -0
- package/bin/lib/renamed-arguments.js +56 -0
- package/bin/lib/site-pull-media.js +21 -28
- package/bin/lib/site-selection.js +10 -1
- package/bin/lib/site-snapshot.js +421 -4
- package/bin/lib/sql-export.js +68 -5
- package/bin/lib/wrangler-cli.js +9 -0
- package/bin/lib/zip-archive.js +187 -0
- package/dist/{app-K_Aa1MMn.js → app-CFsmRVJN.js} +8629 -697
- package/dist/client/.vite/manifest.json +20 -20
- package/dist/client/_assets/chunks/{create-editor-CD3FhrOB.js → create-editor-B-m7X7S5.js} +50 -46
- package/dist/client/_assets/chunks/{sortable-list-CgaL2jCs.js → sortable-list-BJyd-LXE.js} +1 -1
- package/dist/client/_assets/chunks/{unsafe-svg-0QCkP0vZ.js → unsafe-svg-BkscJx69.js} +2 -2
- package/dist/client/_assets/{client-GiYENVw8.css → client-BCumu1-D.css} +1 -1
- package/dist/client/_assets/{client-VnFxJN7G.js → client-DTLBOHqD.js} +1 -1
- package/dist/client/_assets/{client-auth-k8gJ6QJj.js → client-auth-D6Ix6SmE.js} +1 -1
- package/dist/client/_assets/{client-compose-B_kDtWkW.js → client-compose-D6rExKVK.js} +1 -1
- package/dist/client/_assets/{client-manage-M90aSTOk.js → client-manage-sVOkqVbH.js} +1 -1
- package/dist/client/_assets/{client-settings-DfYs9n1F.js → client-settings-CGR_nZ78.js} +7 -7
- package/dist/index.js +2 -3
- package/dist/node.js +8 -5
- package/dist/url-CKlGzvdN.js +428 -0
- package/package.json +13 -7
- package/src/__tests__/cli-commands.test.ts +144 -0
- package/src/__tests__/config-docs.test.ts +148 -0
- package/src/__tests__/dev-scripts.test.ts +203 -0
- package/src/__tests__/export-collection-order.test.ts +276 -0
- package/src/__tests__/export-feed-ids.test.ts +184 -0
- package/src/__tests__/export-feed-order.test.ts +294 -0
- package/src/__tests__/export-hugo-build.test.ts +130 -0
- package/src/__tests__/export-import-roundtrip.test.ts +95 -1
- package/src/__tests__/export-service.test.ts +611 -28
- package/src/__tests__/export-smart-collection.test.ts +329 -0
- package/src/__tests__/feed-docs.test.ts +36 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/README.md +89 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/41q27/0x4nv/index.md +16 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/41q27/_index.md +41 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/41q27/faqyt/index.md +28 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/41q27/the-potting-mix-guide-i-keep-rereading/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/_index.md +4 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/a-night-heron-field-guide-for-my-walk-folder/_index.md +27 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/a-quiet-saturday-after-a-busy-week/_index.md +32 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/archive/_index.md +7 -0
- 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
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/bought-too-many-lemons-again/_index.md +34 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/city-walks/_index.md +11 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/collections/_index.md +4 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/current-tea-rotation/_index.md +31 -0
- 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
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/desk-but-better/_index.md +22 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/e0kcg/_index.md +19 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/featured/_index.md +7 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/from-basho/_index.md +22 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/from-epictetus/_index.md +22 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/from-marcus-aurelius/_index.md +22 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/from-seneca/_index.md +22 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/from-thoreau/_index.md +22 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/gkbvv/2cl6d/index.md +16 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/gkbvv/3zqv7/index.md +28 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/gkbvv/5oxsv/index.md +16 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/gkbvv/_index.md +36 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/home-cooking/_index.md +11 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/k5vh8/_index.md +29 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/k5vh8/a-reading-log-idea-i-might-steal/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/k5vh8/a83qu/index.md +16 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/k5vh8/from-seneca-5hibo/index.md +19 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/mynoise-for-rainy-afternoons/_index.md +27 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/nts-archives-are-good-cleaning-music/_index.md +27 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/qgfcu/_index.md +29 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/qgfcu/c91j0/index.md +16 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/qgfcu/qyucy/index.md +16 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/qgfcu/wsgck/index.md +16 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/rain-makes-my-neighborhood-look-better/_index.md +43 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/reading-notes/_index.md +11 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/serious-eats-on-tomato-and-egg-soup/_index.md +27 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/te812/_index.md +41 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/te812/cxiu6/index.md +16 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/te812/t77ms/index.md +16 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/te812/the-soup-trick-i-always-forget/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/telk3/_index.md +27 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/telk3/from-thoreau-pawt2/index.md +17 -0
- 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
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/the-hallway-light-took-12-minutes-and-3-months/_index.md +29 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/the-recurse-center-manual-is-weirdly-calming/_index.md +27 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/tiny-projects/_index.md +11 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/useful-links/_index.md +11 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/weekend-notes/_index.md +11 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/content/what-i-actually-use-my-notebook-for/_index.md +49 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/data/jant.toml +119 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/hugo.toml +43 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/static/media/021801c20ab3-med_01kn8jw26cenf98vc7k0ppz5k8.webp +0 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/static/media/0f868ce9ac84-med_01kn8jtx8qenf98tm9ahxr48sw.webp +0 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/static/media/50c2ad911bad-med_01kn8jvb16enf98txp7p0pf5ge.webp +0 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/static/media/7a91f0960491-med_01kn8jvq58enf98v538w5vsqp4.webp +0 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/static/media/8714116d3c8e-med_01kn8jve5nenf98tzap11gpxzr.webp +0 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/static/media/8a0b4277443f-med_01kn8jv0jdenf98tp6qr9zgjjc.webp +0 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/static/media/a7d1c8a1afd9-med_01kn8jv452enf98trbkwrvhvgd.webp +0 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/static/media/e25570b405f5-med_01kn8jvsaeenf98v6ct4gjzppc.webp +0 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/static/media/e89ea4eabf01-med_01kn8jtq3penf98tfq4gzmh9g9.png +0 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/themes/jant/static/apple-touch-icon.png +0 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/themes/jant/static/custom.css +0 -0
- package/src/__tests__/fixtures/releases/0.7.0/site-export/themes/jant/static/favicon.ico +0 -0
- package/src/__tests__/fixtures/releases/0.7.0/snapshot/db.sql +218 -0
- package/src/__tests__/fixtures/releases/0.7.0/snapshot/meta.json +9 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/README.md +89 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/41q27/0x4nv/index.md +16 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/41q27/_index.md +41 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/41q27/faqyt/index.md +28 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/41q27/the-potting-mix-guide-i-keep-rereading/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/_index.md +4 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/a-night-heron-field-guide-for-my-walk-folder/_index.md +27 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/a-quiet-saturday-after-a-busy-week/_index.md +32 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/archive/_index.md +7 -0
- 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
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/bought-too-many-lemons-again/_index.md +34 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/city-walks/_index.md +11 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/collections/_index.md +4 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/current-tea-rotation/_index.md +31 -0
- 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
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/desk-but-better/_index.md +22 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/e0kcg/_index.md +19 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/featured/_index.md +7 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/from-basho/_index.md +22 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/from-epictetus/_index.md +22 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/from-marcus-aurelius/_index.md +22 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/from-seneca/_index.md +22 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/from-thoreau/_index.md +22 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/gkbvv/2cl6d/index.md +16 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/gkbvv/3zqv7/index.md +28 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/gkbvv/5oxsv/index.md +16 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/gkbvv/_index.md +36 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/home-cooking/_index.md +11 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/k5vh8/_index.md +29 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/k5vh8/a-reading-log-idea-i-might-steal/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/k5vh8/a83qu/index.md +16 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/k5vh8/from-seneca-5hibo/index.md +19 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/mynoise-for-rainy-afternoons/_index.md +27 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/nts-archives-are-good-cleaning-music/_index.md +27 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/qgfcu/_index.md +29 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/qgfcu/c91j0/index.md +16 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/qgfcu/qyucy/index.md +16 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/qgfcu/wsgck/index.md +16 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/rain-makes-my-neighborhood-look-better/_index.md +43 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/reading-notes/_index.md +11 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/serious-eats-on-tomato-and-egg-soup/_index.md +27 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/te812/_index.md +41 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/te812/cxiu6/index.md +16 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/te812/t77ms/index.md +16 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/te812/the-soup-trick-i-always-forget/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/telk3/_index.md +27 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/telk3/from-thoreau-pawt2/index.md +17 -0
- 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
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/the-hallway-light-took-12-minutes-and-3-months/_index.md +29 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/the-recurse-center-manual-is-weirdly-calming/_index.md +27 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/tiny-projects/_index.md +11 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/useful-links/_index.md +11 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/weekend-notes/_index.md +11 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/content/what-i-actually-use-my-notebook-for/_index.md +49 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/data/jant.toml +119 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/hugo.toml +43 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/static/media/021801c20ab3-med_01kn8jw26cenf98vc7k0ppz5k8.webp +0 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/static/media/0f868ce9ac84-med_01kn8jtx8qenf98tm9ahxr48sw.webp +0 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/static/media/50c2ad911bad-med_01kn8jvb16enf98txp7p0pf5ge.webp +0 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/static/media/7a91f0960491-med_01kn8jvq58enf98v538w5vsqp4.webp +0 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/static/media/8714116d3c8e-med_01kn8jve5nenf98tzap11gpxzr.webp +0 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/static/media/8a0b4277443f-med_01kn8jv0jdenf98tp6qr9zgjjc.webp +0 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/static/media/a7d1c8a1afd9-med_01kn8jv452enf98trbkwrvhvgd.webp +0 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/static/media/e25570b405f5-med_01kn8jvsaeenf98v6ct4gjzppc.webp +0 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/static/media/e89ea4eabf01-med_01kn8jtq3penf98tfq4gzmh9g9.png +0 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/themes/jant/static/apple-touch-icon.png +0 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/themes/jant/static/custom.css +0 -0
- package/src/__tests__/fixtures/releases/0.7.1/site-export/themes/jant/static/favicon.ico +0 -0
- package/src/__tests__/fixtures/releases/0.7.1/snapshot/db.sql +322 -0
- package/src/__tests__/fixtures/releases/0.7.1/snapshot/meta.json +9 -0
- package/src/__tests__/helpers/hugo-site.ts +146 -0
- package/src/__tests__/helpers/site-export-import.ts +97 -0
- package/src/__tests__/import-site-command.test.ts +514 -2
- package/src/__tests__/mise-config.test.ts +75 -4
- package/src/__tests__/node-dev-tasks.test.ts +264 -0
- package/src/__tests__/release-fixtures.test.ts +132 -0
- package/src/__tests__/site-export-canonical-import.test.ts +113 -0
- package/src/__tests__/snapshot-canonical-replay.test.ts +179 -0
- package/src/__tests__/snapshot-settings.test.ts +97 -0
- package/src/__tests__/snapshot-tables.test.ts +219 -0
- package/src/__tests__/sql-export.test.ts +173 -0
- package/src/__tests__/theme-docs.test.ts +109 -0
- package/src/__tests__/zip-archive.test.ts +106 -0
- package/src/app.tsx +16 -11
- package/src/client/components/__tests__/jant-settings-avatar.test.ts +1 -1
- package/src/client/components/__tests__/jant-settings-general.test.ts +21 -1
- package/src/client/components/jant-repo-picker-types.ts +6 -1
- package/src/client/components/jant-repo-picker.ts +4 -7
- package/src/client/components/jant-settings-general.ts +17 -12
- package/src/client/tiptap/__tests__/list-editing.test.ts +224 -86
- package/src/client/tiptap/__tests__/mark-exit.test.ts +1 -2
- package/src/client/tiptap/__tests__/markdown-clipboard.test.ts +26 -0
- package/src/client/tiptap/extensions.ts +0 -3
- package/src/client/tiptap/structural-keymap.ts +158 -47
- package/src/db/__tests__/d1-query.test.ts +56 -1
- package/src/db/rehearsal-fixtures/pg-demo-current.json +55 -0
- package/src/db/rehearsal-fixtures/pg-demo-current.sql +431 -0
- package/src/i18n/locales/public/en.po +0 -2
- package/src/i18n/locales/public/zh-Hans.po +0 -2
- package/src/i18n/locales/public/zh-Hant.po +0 -2
- package/src/i18n/locales/settings/en.po +8 -8
- package/src/i18n/locales/settings/en.ts +1 -1
- package/src/i18n/locales/settings/zh-Hans.po +8 -8
- package/src/i18n/locales/settings/zh-Hans.ts +1 -1
- package/src/i18n/locales/settings/zh-Hant.po +8 -8
- package/src/i18n/locales/settings/zh-Hant.ts +1 -1
- package/src/index.ts +6 -77
- package/src/lib/__tests__/github-sync-repo-name.test.ts +40 -0
- package/src/lib/__tests__/image.test.ts +27 -1
- package/src/lib/__tests__/markdown-to-tiptap.test.ts +105 -0
- package/src/lib/__tests__/markdown.test.ts +10 -0
- package/src/lib/__tests__/resolve-config.test.ts +67 -0
- package/src/lib/__tests__/schemas.test.ts +27 -1
- package/src/lib/__tests__/timeline.test.ts +87 -0
- package/src/lib/__tests__/tiptap-to-markdown.test.ts +172 -4
- package/src/lib/__tests__/view.test.ts +0 -46
- package/src/lib/discover.ts +3 -1
- package/src/lib/feed.ts +0 -6
- package/src/lib/github-sync-repo-name.ts +45 -0
- package/src/lib/hugo-markdown.ts +46 -0
- package/src/lib/image.ts +17 -4
- package/src/lib/markdown-manager.ts +392 -2
- package/src/lib/post-body-html.ts +11 -4
- package/src/lib/resolve-config.ts +58 -1
- package/src/lib/schemas.ts +50 -5
- package/src/lib/thread-fold.ts +3 -3
- package/src/lib/timeline.ts +1 -1
- package/src/lib/tiptap-to-markdown.ts +13 -7
- package/src/lib/url.ts +20 -0
- package/src/lib/view.ts +2 -29
- package/src/node/__tests__/cli-export.test.ts +2 -2
- package/src/node/__tests__/cli-setup.test.ts +163 -0
- package/src/node/__tests__/cli-site-snapshot.test.ts +73 -0
- package/src/node/__tests__/cli-site-token-env.test.ts +4 -1
- package/src/node/__tests__/cli-snapshot-meta.test.ts +84 -0
- package/src/node/__tests__/runtime.test.ts +38 -0
- package/src/node/index.ts +2 -0
- package/src/node/request-handler.ts +3 -1
- package/src/routes/api/__tests__/posts.test.ts +24 -0
- package/src/routes/api/__tests__/upload.test.ts +34 -0
- package/src/routes/api/export.ts +3 -3
- package/src/routes/api/internal/search-reindex.ts +1 -1
- package/src/routes/api/internal/sites.ts +0 -1
- package/src/routes/api/posts.ts +2 -0
- package/src/routes/api/public/posts.ts +21 -1
- package/src/routes/api/upload.ts +10 -3
- package/src/routes/compose.tsx +4 -0
- package/src/routes/dash/__tests__/github-sync-app.test.ts +365 -0
- package/src/routes/dash/settings.tsx +212 -70
- package/src/routes/pages/__tests__/post-page-round-trips.test.ts +211 -0
- package/src/routes/pages/__tests__/thread-order.test.ts +179 -0
- package/src/routes/pages/archive.tsx +17 -11
- package/src/routes/pages/featured.tsx +11 -5
- package/src/routes/pages/page.tsx +53 -31
- package/src/routes/pages/search.tsx +4 -2
- package/src/runtime/__tests__/readiness.test.ts +23 -0
- package/src/runtime/node.ts +49 -0
- package/src/runtime/readiness.ts +15 -0
- package/src/services/__tests__/bootstrap-setup-instance.test.ts +230 -0
- package/src/services/__tests__/custom-url.test.ts +34 -0
- package/src/services/__tests__/github-app-installations.test.ts +153 -0
- package/src/services/__tests__/github-sync-push.test.ts +46 -0
- package/src/services/__tests__/media.test.ts +31 -271
- package/src/services/__tests__/path.test.ts +56 -0
- package/src/services/__tests__/post-timeline.test.ts +127 -0
- package/src/services/__tests__/post.test.ts +74 -0
- package/src/services/bootstrap.ts +263 -44
- package/src/services/custom-url.ts +2 -2
- package/src/services/export-theme/layouts/_default/alias.html +27 -1
- package/src/services/export-theme/layouts/_default/list.html +2 -63
- package/src/services/export-theme/layouts/_default/rss.xml +27 -38
- package/src/services/export-theme/layouts/collections/list.html +3 -3
- package/src/services/export-theme/layouts/featured/list.html +1 -4
- package/src/services/export-theme/layouts/index.html +40 -26
- package/src/services/export-theme/layouts/partials/collection-members.html +100 -0
- package/src/services/export-theme/layouts/partials/collection-threads.html +33 -0
- package/src/services/export-theme/layouts/partials/featured-members.html +35 -0
- package/src/services/export-theme/layouts/partials/featured-thread.html +1 -1
- package/src/services/export-theme/layouts/partials/footer.html +1 -1
- package/src/services/export-theme/layouts/partials/head.html +1 -1
- package/src/services/export-theme/layouts/partials/header.html +5 -3
- package/src/services/export-theme/layouts/partials/jant-data.html +23 -0
- package/src/services/export-theme/layouts/partials/latest-members.html +48 -0
- package/src/services/export-theme/layouts/partials/smart-collection-members.html +129 -0
- package/src/services/export-theme/layouts/partials/thread-preview.html +1 -1
- package/src/services/export-theme/layouts/post/list.html +1 -1
- package/src/services/export-theme/layouts/smart_collection/list.html +24 -0
- package/src/services/export-theme/styles/main.css +0 -1
- package/src/services/export-theme/theme.toml +1 -1
- package/src/services/export.ts +630 -73
- package/src/services/github-app-installations.ts +171 -4
- package/src/services/github-sync.ts +69 -15
- package/src/services/mcp.ts +19 -1
- package/src/services/media.ts +9 -220
- package/src/services/path.ts +34 -1
- package/src/services/post.ts +214 -39
- package/src/services/site-admin.ts +3 -7
- package/src/services/site.ts +83 -31
- package/src/styles/ui.css +7 -119
- package/src/types/app-context.ts +16 -0
- package/src/types/bindings.ts +5 -0
- package/src/types/operations.ts +10 -0
- package/src/ui/dash/settings/GeneralContent.tsx +10 -8
- package/bin/commands/export.js +0 -118
- package/bin/commands/import-site.js +0 -2561
- package/bin/commands/migrate-text-attachments.js +0 -181
- package/dist/github-sync-BPAvT999.js +0 -7709
- package/src/client/multipart-upload.ts +0 -206
- package/src/client/tiptap/exitable-marks.ts +0 -73
- package/src/routes/api/__tests__/upload-multipart.test.ts +0 -739
- package/src/routes/api/internal/text-attachments.ts +0 -60
- package/src/routes/api/upload-multipart.ts +0 -366
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Snapshot Setting Registry Guard
|
|
3
|
+
*
|
|
4
|
+
* `jant site snapshot export/import` filters `site_setting` through the
|
|
5
|
+
* hand-written `SNAPSHOT_SETTING_KEYS` allowlist in `bin/lib/site-snapshot.js`.
|
|
6
|
+
* `bin/` is plain JavaScript, outside the type system, so a new setting key
|
|
7
|
+
* compiles, lints and tests clean while the snapshot silently skips it.
|
|
8
|
+
*
|
|
9
|
+
* That already happened. `MULTILINGUAL_ENABLED` and `ADDITIONAL_LANGUAGES`
|
|
10
|
+
* arrived with multilingual content and never reached the allowlist, while the
|
|
11
|
+
* whole-row `post` dump kept carrying `language` and `translation_group_id`.
|
|
12
|
+
* Restoring a multilingual site therefore produced posts stamped per language
|
|
13
|
+
* on a site that served no per-language views — and the nightly demo rebuild
|
|
14
|
+
* reset `demo.jant.me` to a single-language site every night.
|
|
15
|
+
*
|
|
16
|
+
* This test closes the gap the same way `snapshot-tables.test.ts` does for
|
|
17
|
+
* tables: every DB-backed setting has to be named in one of the two
|
|
18
|
+
* registries, so a new key forces a decision instead of defaulting to
|
|
19
|
+
* "forgotten".
|
|
20
|
+
*
|
|
21
|
+
* `envOnly` keys are the one exemption, and are asserted to be in neither
|
|
22
|
+
* list: they resolve from the environment and never reach `site_setting`, so
|
|
23
|
+
* there is no row for an export to read or for `--replace` to clear.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { describe, expect, it } from "vitest";
|
|
27
|
+
import {
|
|
28
|
+
SNAPSHOT_EXCLUDED_SETTING_KEYS,
|
|
29
|
+
SNAPSHOT_SETTING_KEYS,
|
|
30
|
+
} from "../../bin/lib/site-snapshot.js";
|
|
31
|
+
import { CONFIG_FIELDS } from "../types/config.js";
|
|
32
|
+
|
|
33
|
+
type ConfigKey = keyof typeof CONFIG_FIELDS;
|
|
34
|
+
|
|
35
|
+
const ALL_KEYS = Object.keys(CONFIG_FIELDS) as ConfigKey[];
|
|
36
|
+
|
|
37
|
+
/** Keys that can hold a `site_setting` row — everything not env-resolved. */
|
|
38
|
+
const DB_BACKED_KEYS = ALL_KEYS.filter(
|
|
39
|
+
(key) => !("envOnly" in CONFIG_FIELDS[key] && CONFIG_FIELDS[key].envOnly),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
/** Keys resolved from the environment, which never reach `site_setting`. */
|
|
43
|
+
const ENV_ONLY_KEYS = ALL_KEYS.filter((key) => !DB_BACKED_KEYS.includes(key));
|
|
44
|
+
|
|
45
|
+
describe("snapshot setting registry", () => {
|
|
46
|
+
it("names every DB-backed setting in exactly one registry", () => {
|
|
47
|
+
const carried = new Set<string>(SNAPSHOT_SETTING_KEYS);
|
|
48
|
+
const excluded = new Set<string>(SNAPSHOT_EXCLUDED_SETTING_KEYS);
|
|
49
|
+
|
|
50
|
+
const unregistered = DB_BACKED_KEYS.filter(
|
|
51
|
+
(key) => !carried.has(key) && !excluded.has(key),
|
|
52
|
+
);
|
|
53
|
+
const registeredTwice = DB_BACKED_KEYS.filter(
|
|
54
|
+
(key) => carried.has(key) && excluded.has(key),
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
expect(
|
|
58
|
+
{ unregistered, registeredTwice },
|
|
59
|
+
"Add each new DB-backed setting to SNAPSHOT_SETTING_KEYS (it belongs to " +
|
|
60
|
+
"the site's published content) or to SNAPSHOT_EXCLUDED_SETTING_KEYS " +
|
|
61
|
+
"(with the reason), in bin/lib/site-snapshot.js.",
|
|
62
|
+
).toEqual({ unregistered: [], registeredTwice: [] });
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("leaves env-only settings out of both registries", () => {
|
|
66
|
+
const listed = ENV_ONLY_KEYS.filter(
|
|
67
|
+
(key) =>
|
|
68
|
+
SNAPSHOT_SETTING_KEYS.includes(key) ||
|
|
69
|
+
SNAPSHOT_EXCLUDED_SETTING_KEYS.includes(key),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
expect(listed).toEqual([]);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("registers no key that CONFIG_FIELDS does not define", () => {
|
|
76
|
+
const known = new Set<string>(ALL_KEYS);
|
|
77
|
+
const unknown = [
|
|
78
|
+
...SNAPSHOT_SETTING_KEYS,
|
|
79
|
+
...SNAPSHOT_EXCLUDED_SETTING_KEYS,
|
|
80
|
+
].filter((key) => !known.has(key));
|
|
81
|
+
|
|
82
|
+
expect(unknown).toEqual([]);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("carries the whole language trio, so restored posts keep their views", () => {
|
|
86
|
+
// `post.language` and `post.translation_group_id` ride along in the
|
|
87
|
+
// whole-row `post` dump. A snapshot that carried those but not the switch
|
|
88
|
+
// restored a site whose per-language views had silently disappeared.
|
|
89
|
+
expect(SNAPSHOT_SETTING_KEYS).toEqual(
|
|
90
|
+
expect.arrayContaining([
|
|
91
|
+
"SITE_LANGUAGE",
|
|
92
|
+
"MULTILINGUAL_ENABLED",
|
|
93
|
+
"ADDITIONAL_LANGUAGES",
|
|
94
|
+
]),
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Snapshot Table Registry Guard
|
|
3
|
+
*
|
|
4
|
+
* `jant site snapshot export/import` walks two hand-written arrays in
|
|
5
|
+
* `bin/lib/site-snapshot.js`. Nothing connects them to `db/schema.ts`: `bin/`
|
|
6
|
+
* is plain JavaScript, outside the type system, so a new site-scoped table
|
|
7
|
+
* compiles, lints and tests clean while the snapshot silently skips it.
|
|
8
|
+
*
|
|
9
|
+
* That already happened. `smart_collection` arrived with migration 0033, and
|
|
10
|
+
* the commit that added it updated the schema, both dialects, five services, a
|
|
11
|
+
* route and three test files — but not these arrays. The damage was silent in
|
|
12
|
+
* both directions: export dropped smart collections, and `--replace` could not
|
|
13
|
+
* delete the ones a visitor created, so they outlived every nightly demo
|
|
14
|
+
* rebuild as rows with no slug and no nav entry.
|
|
15
|
+
*
|
|
16
|
+
* These tests close the gap. Every site-scoped table has to be named in one of
|
|
17
|
+
* the two registries, so a new table forces a decision instead of defaulting to
|
|
18
|
+
* "forgotten". The order assertions pin the arrays' other implicit contract:
|
|
19
|
+
* `SNAPSHOT_TABLES` is an INSERT order and `SNAPSHOT_CLEAR_TABLES` is a DELETE
|
|
20
|
+
* order, and both have to respect foreign keys — which are enforced, on D1 and
|
|
21
|
+
* on Node alike (`bin/lib/node-sqlite.js` sets `foreign_keys = ON`).
|
|
22
|
+
*
|
|
23
|
+
* Reading `db/schema.ts` alone covers both dialects: the registries are shared
|
|
24
|
+
* (only the dumped SQL is dialect-specific), and `db/pg/schema.ts` is required
|
|
25
|
+
* to declare the same tables.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { is } from "drizzle-orm";
|
|
29
|
+
import { SQLiteTable, getTableConfig } from "drizzle-orm/sqlite-core";
|
|
30
|
+
import { describe, expect, it } from "vitest";
|
|
31
|
+
import {
|
|
32
|
+
SNAPSHOT_CLEAR_TABLES,
|
|
33
|
+
SNAPSHOT_EXCLUDED_TABLES,
|
|
34
|
+
SNAPSHOT_TABLES,
|
|
35
|
+
getSnapshotSelectSql,
|
|
36
|
+
} from "../../bin/lib/site-snapshot.js";
|
|
37
|
+
import {
|
|
38
|
+
TABLE_EXPORT_ORDER,
|
|
39
|
+
sortExportTables,
|
|
40
|
+
} from "../../bin/lib/sql-export.js";
|
|
41
|
+
import * as schema from "../db/schema.js";
|
|
42
|
+
|
|
43
|
+
/** `site_setting` is cleared by key, not wholesale — see `buildReplaceSql`. */
|
|
44
|
+
const CLEARED_BY_KEY = "site_setting";
|
|
45
|
+
|
|
46
|
+
type SchemaTable = {
|
|
47
|
+
/** Physical table name, as it appears in SQL. */
|
|
48
|
+
name: string;
|
|
49
|
+
/** Tables this one points at with a foreign key, excluding self-references. */
|
|
50
|
+
dependsOn: string[];
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Reads every site-scoped table out of the Drizzle schema with its foreign-key
|
|
55
|
+
* dependencies. "Site-scoped" means the table carries a `site_id` column, which
|
|
56
|
+
* is what makes a row belong to one site's content rather than the instance.
|
|
57
|
+
*
|
|
58
|
+
* @returns One entry per site-scoped table, in declaration order.
|
|
59
|
+
*/
|
|
60
|
+
function readSiteScopedTables(): SchemaTable[] {
|
|
61
|
+
const tables: SchemaTable[] = [];
|
|
62
|
+
|
|
63
|
+
for (const exported of Object.values(schema)) {
|
|
64
|
+
if (!is(exported, SQLiteTable)) continue;
|
|
65
|
+
const config = getTableConfig(exported);
|
|
66
|
+
if (!config.columns.some((column) => column.name === "site_id")) continue;
|
|
67
|
+
|
|
68
|
+
const dependsOn = [
|
|
69
|
+
...new Set(
|
|
70
|
+
config.foreignKeys.map(
|
|
71
|
+
(foreignKey) =>
|
|
72
|
+
getTableConfig(foreignKey.reference().foreignTable).name,
|
|
73
|
+
),
|
|
74
|
+
),
|
|
75
|
+
].filter((target) => target !== config.name);
|
|
76
|
+
|
|
77
|
+
tables.push({ name: config.name, dependsOn });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return tables;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const siteScopedTables = readSiteScopedTables();
|
|
84
|
+
const siteScopedNames = siteScopedTables.map((table) => table.name);
|
|
85
|
+
|
|
86
|
+
describe("snapshot table registry", () => {
|
|
87
|
+
it("covers every site-scoped table as content or an explicit exclusion", () => {
|
|
88
|
+
const registered = new Set<string>([
|
|
89
|
+
...SNAPSHOT_TABLES,
|
|
90
|
+
...SNAPSHOT_EXCLUDED_TABLES,
|
|
91
|
+
]);
|
|
92
|
+
const unregistered = siteScopedNames.filter(
|
|
93
|
+
(name) => !registered.has(name),
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
expect(
|
|
97
|
+
unregistered,
|
|
98
|
+
[
|
|
99
|
+
"These site-scoped tables are in db/schema.ts but in neither snapshot registry.",
|
|
100
|
+
"A table the snapshot does not know about is dropped on export and survives",
|
|
101
|
+
"`--replace` on import. Add it to SNAPSHOT_TABLES if it is site content, or to",
|
|
102
|
+
"SNAPSHOT_EXCLUDED_TABLES with the reason if it is shell, credential or",
|
|
103
|
+
"transient state, in bin/lib/site-snapshot.js.",
|
|
104
|
+
].join("\n"),
|
|
105
|
+
).toEqual([]);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("does not register a table as both content and excluded", () => {
|
|
109
|
+
const excluded = new Set<string>(SNAPSHOT_EXCLUDED_TABLES);
|
|
110
|
+
const both = SNAPSHOT_TABLES.filter((name) => excluded.has(name));
|
|
111
|
+
|
|
112
|
+
expect(both).toEqual([]);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("can build an export query for every content table", () => {
|
|
116
|
+
// `getSnapshotSelectSql` has no default branch: a table listed as content
|
|
117
|
+
// without a matching statement throws "Unsupported snapshot table" at
|
|
118
|
+
// export time, which is the same silent-until-used failure the registry
|
|
119
|
+
// itself had.
|
|
120
|
+
for (const table of SNAPSHOT_TABLES) {
|
|
121
|
+
expect(() =>
|
|
122
|
+
getSnapshotSelectSql(table, "sit_00000000000000000000000000"),
|
|
123
|
+
).not.toThrow();
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("does not keep registry entries for tables the schema dropped", () => {
|
|
128
|
+
const known = new Set(siteScopedNames);
|
|
129
|
+
const stale = [...SNAPSHOT_TABLES, ...SNAPSHOT_EXCLUDED_TABLES].filter(
|
|
130
|
+
(name) => !known.has(name),
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
expect(stale).toEqual([]);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
describe("snapshot table ordering", () => {
|
|
138
|
+
it("registers every content table for export ordering", () => {
|
|
139
|
+
// A table missing here is not merely unordered: `sortExportTables` places
|
|
140
|
+
// unknown names after every known one, so a new child table is dumped
|
|
141
|
+
// behind its own parents and the import fails the first time a row exists
|
|
142
|
+
// to violate the constraint.
|
|
143
|
+
const ordered = new Set<string>(TABLE_EXPORT_ORDER);
|
|
144
|
+
expect(SNAPSHOT_TABLES.filter((name) => !ordered.has(name))).toEqual([]);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("inserts a table only after every table it references", () => {
|
|
148
|
+
// The order an export actually follows. `SNAPSHOT_TABLES` is re-sorted by
|
|
149
|
+
// `TABLE_EXPORT_ORDER` on the way out, so asserting on the raw list would
|
|
150
|
+
// check something the dump ignores.
|
|
151
|
+
const position = new Map(
|
|
152
|
+
sortExportTables(SNAPSHOT_TABLES).map((name, index) => [name, index]),
|
|
153
|
+
);
|
|
154
|
+
const violations: string[] = [];
|
|
155
|
+
|
|
156
|
+
for (const table of siteScopedTables) {
|
|
157
|
+
const self = position.get(table.name);
|
|
158
|
+
if (self === undefined) continue;
|
|
159
|
+
|
|
160
|
+
for (const dependency of table.dependsOn) {
|
|
161
|
+
const parent = position.get(dependency);
|
|
162
|
+
if (parent === undefined) continue;
|
|
163
|
+
if (parent > self) {
|
|
164
|
+
violations.push(
|
|
165
|
+
`${table.name} (${self}) references ${dependency} (${parent})`,
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
expect(
|
|
172
|
+
violations,
|
|
173
|
+
[
|
|
174
|
+
"TABLE_EXPORT_ORDER in sql-export.js is the order rows are dumped, and so the",
|
|
175
|
+
"order they are inserted on import. A table has to come after everything it",
|
|
176
|
+
"points at with a foreign key, or the child row lands before its parent exists",
|
|
177
|
+
"and the insert fails the constraint.",
|
|
178
|
+
].join("\n"),
|
|
179
|
+
).toEqual([]);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("deletes a table before every table it references", () => {
|
|
183
|
+
const position = new Map(
|
|
184
|
+
SNAPSHOT_CLEAR_TABLES.map((name, index) => [name, index]),
|
|
185
|
+
);
|
|
186
|
+
const violations: string[] = [];
|
|
187
|
+
|
|
188
|
+
for (const table of siteScopedTables) {
|
|
189
|
+
const self = position.get(table.name);
|
|
190
|
+
if (self === undefined) continue;
|
|
191
|
+
|
|
192
|
+
for (const dependency of table.dependsOn) {
|
|
193
|
+
const parent = position.get(dependency);
|
|
194
|
+
if (parent === undefined) continue;
|
|
195
|
+
if (parent < self) {
|
|
196
|
+
violations.push(
|
|
197
|
+
`${table.name} (${self}) references ${dependency} (${parent})`,
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
expect(
|
|
204
|
+
violations,
|
|
205
|
+
[
|
|
206
|
+
"SNAPSHOT_CLEAR_TABLES is the order rows are deleted by `--replace`, so a table",
|
|
207
|
+
"has to come before everything it points at. Deleting the parent first only",
|
|
208
|
+
"appears to work because the cascade takes the children with it — which is",
|
|
209
|
+
"implicit, and stops being true the moment a reference is not ON DELETE CASCADE.",
|
|
210
|
+
].join("\n"),
|
|
211
|
+
).toEqual([]);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("clears every content table except the one cleared by key", () => {
|
|
215
|
+
expect([...SNAPSHOT_CLEAR_TABLES].sort()).toEqual(
|
|
216
|
+
SNAPSHOT_TABLES.filter((name) => name !== CLEARED_BY_KEY).sort(),
|
|
217
|
+
);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The SQL dump behind `db export` and `site snapshot export`.
|
|
3
|
+
*
|
|
4
|
+
* On D1 every query goes through `wrangler d1 execute --json`, whose output
|
|
5
|
+
* the CLI buffers. One `SELECT *` of a real site's `post` table overflowed
|
|
6
|
+
* that buffer, so the dump reads D1 a page at a time.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { describe, expect, it } from "vitest";
|
|
10
|
+
import Database from "better-sqlite3";
|
|
11
|
+
import { dumpDatabaseToSql } from "../../bin/lib/sql-export.js";
|
|
12
|
+
import { orderSnapshotPostRows } from "../../bin/lib/site-snapshot.js";
|
|
13
|
+
import { describeWranglerFailure } from "../../bin/lib/d1-query.js";
|
|
14
|
+
import { WRANGLER_MAX_BUFFER } from "../../bin/lib/wrangler-cli.js";
|
|
15
|
+
|
|
16
|
+
function createQueryRunner() {
|
|
17
|
+
const db = new Database(":memory:");
|
|
18
|
+
db.exec(`
|
|
19
|
+
CREATE TABLE "post" ("id" TEXT PRIMARY KEY, "site_id" TEXT, "body" TEXT);
|
|
20
|
+
`);
|
|
21
|
+
const insert = db.prepare(
|
|
22
|
+
`INSERT INTO "post" ("id", "site_id", "body") VALUES (?, ?, ?)`,
|
|
23
|
+
);
|
|
24
|
+
for (let index = 0; index < 7; index += 1) {
|
|
25
|
+
insert.run(`pst_${index}`, "site", `body ${index}`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const statements: string[] = [];
|
|
29
|
+
return {
|
|
30
|
+
statements,
|
|
31
|
+
runner: {
|
|
32
|
+
async query(sql: string) {
|
|
33
|
+
statements.push(sql);
|
|
34
|
+
return db.prepare(sql).all() as Record<string, unknown>[];
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
describe("dumpDatabaseToSql", () => {
|
|
41
|
+
it("reads a table in pages when given a page size", async () => {
|
|
42
|
+
const { runner, statements } = createQueryRunner();
|
|
43
|
+
|
|
44
|
+
const sql = await dumpDatabaseToSql(runner, {
|
|
45
|
+
source: "local",
|
|
46
|
+
dialect: "sqlite",
|
|
47
|
+
tables: ["post"],
|
|
48
|
+
pageSize: 3,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const reads = statements.filter((statement) =>
|
|
52
|
+
statement.includes('FROM "post"'),
|
|
53
|
+
);
|
|
54
|
+
expect(reads).toEqual([
|
|
55
|
+
'SELECT * FROM "post" ORDER BY rowid LIMIT 3 OFFSET 0',
|
|
56
|
+
'SELECT * FROM "post" ORDER BY rowid LIMIT 3 OFFSET 3',
|
|
57
|
+
'SELECT * FROM "post" ORDER BY rowid LIMIT 3 OFFSET 6',
|
|
58
|
+
]);
|
|
59
|
+
for (let index = 0; index < 7; index += 1) {
|
|
60
|
+
expect(sql).toContain(`'pst_${index}'`);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("pages a table's own ordered select", async () => {
|
|
65
|
+
const { runner, statements } = createQueryRunner();
|
|
66
|
+
|
|
67
|
+
const sql = await dumpDatabaseToSql(runner, {
|
|
68
|
+
source: "local",
|
|
69
|
+
dialect: "sqlite",
|
|
70
|
+
tables: ["post"],
|
|
71
|
+
pageSize: 5,
|
|
72
|
+
selectSqlByTable: {
|
|
73
|
+
post: `SELECT * FROM "post" WHERE "site_id" = 'site' ORDER BY "id"\n`,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
expect(
|
|
78
|
+
statements.filter((statement) => statement.includes('FROM "post"')),
|
|
79
|
+
).toEqual([
|
|
80
|
+
`SELECT * FROM "post" WHERE "site_id" = 'site' ORDER BY "id" LIMIT 5 OFFSET 0`,
|
|
81
|
+
`SELECT * FROM "post" WHERE "site_id" = 'site' ORDER BY "id" LIMIT 5 OFFSET 5`,
|
|
82
|
+
]);
|
|
83
|
+
expect(sql.match(/INSERT INTO "post"/g)).toHaveLength(7);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("reads a table in one query without a page size", async () => {
|
|
87
|
+
const { runner, statements } = createQueryRunner();
|
|
88
|
+
|
|
89
|
+
await dumpDatabaseToSql(runner, {
|
|
90
|
+
source: "node",
|
|
91
|
+
dialect: "sqlite",
|
|
92
|
+
tables: ["post"],
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
expect(
|
|
96
|
+
statements.filter((statement) => statement.includes('FROM "post"')),
|
|
97
|
+
).toEqual(['SELECT * FROM "post"']);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe("describeWranglerFailure", () => {
|
|
102
|
+
it("names the buffer overflow instead of echoing the rows", () => {
|
|
103
|
+
const error = Object.assign(new Error("spawnSync node ENOBUFS"), {
|
|
104
|
+
code: "ENOBUFS",
|
|
105
|
+
stdout: '[{"results":[' + '{"id":"pst_x","body":"…"},'.repeat(50_000),
|
|
106
|
+
stderr: "",
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const message = describeWranglerFailure(
|
|
110
|
+
["d1", "execute", "DB", "--local", "--json"],
|
|
111
|
+
error,
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
expect(message).toBe(
|
|
115
|
+
`\`wrangler d1 execute DB\` printed more than ${WRANGLER_MAX_BUFFER} bytes, the most the CLI buffers.`,
|
|
116
|
+
);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("keeps a long failure's stdout to an excerpt", () => {
|
|
120
|
+
const message = describeWranglerFailure(["d1", "execute", "DB"], {
|
|
121
|
+
name: "Error",
|
|
122
|
+
message: "Command failed",
|
|
123
|
+
stdout: "x".repeat(10_000),
|
|
124
|
+
stderr: "",
|
|
125
|
+
} as Error & { stdout: string; stderr: string });
|
|
126
|
+
|
|
127
|
+
expect(message.length).toBeLessThan(2_200);
|
|
128
|
+
expect(message).toContain("(10000 characters)");
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe("snapshot post order", () => {
|
|
133
|
+
it("puts every post after its root and the post it replies to", () => {
|
|
134
|
+
const rows = [
|
|
135
|
+
{ id: "reply-2", thread_id: "root", reply_to_id: "reply-1" },
|
|
136
|
+
{ id: "reply-1", thread_id: "root", reply_to_id: "root" },
|
|
137
|
+
{ id: "other", thread_id: "other", reply_to_id: null },
|
|
138
|
+
{ id: "root", thread_id: "root", reply_to_id: null },
|
|
139
|
+
];
|
|
140
|
+
|
|
141
|
+
expect(orderSnapshotPostRows(rows).map((row) => row.id)).toEqual([
|
|
142
|
+
"root",
|
|
143
|
+
"reply-1",
|
|
144
|
+
"reply-2",
|
|
145
|
+
"other",
|
|
146
|
+
]);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("keeps the dump order when parents already come first", () => {
|
|
150
|
+
const rows = [
|
|
151
|
+
{ id: "a", thread_id: "a", reply_to_id: null },
|
|
152
|
+
{ id: "b", thread_id: "a", reply_to_id: "a" },
|
|
153
|
+
{ id: "c", thread_id: "c", reply_to_id: null },
|
|
154
|
+
];
|
|
155
|
+
|
|
156
|
+
expect(orderSnapshotPostRows(rows)).toEqual(rows);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("applies a table's row order to the dump", async () => {
|
|
160
|
+
const { runner } = createQueryRunner();
|
|
161
|
+
|
|
162
|
+
const sql = await dumpDatabaseToSql(runner, {
|
|
163
|
+
source: "node",
|
|
164
|
+
dialect: "sqlite",
|
|
165
|
+
tables: ["post"],
|
|
166
|
+
orderRowsByTable: {
|
|
167
|
+
post: (rows: Record<string, unknown>[]) => [...rows].reverse(),
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
expect(sql.indexOf("'pst_6'")).toBeLessThan(sql.indexOf("'pst_0'"));
|
|
172
|
+
});
|
|
173
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The theming docs name only hooks the markup and stylesheets provide.
|
|
3
|
+
*
|
|
4
|
+
* `docs/theming.md` is the public theme contract: the CSS variables it lists,
|
|
5
|
+
* the `data-*` attributes and their values, and the footnote classes. The
|
|
6
|
+
* rest of the roughly 270 custom properties are internal. `--site-width`
|
|
7
|
+
* stayed documented after it was removed, and `data-page="subscribe"` shipped
|
|
8
|
+
* without being documented; these checks fail on both kinds of drift.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
12
|
+
import { join, resolve } from "node:path";
|
|
13
|
+
import { describe, expect, it } from "vitest";
|
|
14
|
+
|
|
15
|
+
const CORE_DIR = resolve(import.meta.dirname, "../..");
|
|
16
|
+
const REPO_ROOT = resolve(CORE_DIR, "../..");
|
|
17
|
+
const SRC_DIR = join(CORE_DIR, "src");
|
|
18
|
+
const THEMING_DOCS = ["docs/theming.md", "docs/zh-Hans/theming.md"];
|
|
19
|
+
|
|
20
|
+
/** `data-page` values of author-only and internal pages, left out of the docs. */
|
|
21
|
+
const UNDOCUMENTED_PAGES = new Set(["compose", "brand", "theme-sample"]);
|
|
22
|
+
|
|
23
|
+
function listSourceFiles(dir: string, extensions: string[]): string[] {
|
|
24
|
+
return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
|
|
25
|
+
const fullPath = join(dir, entry.name);
|
|
26
|
+
if (entry.isDirectory()) {
|
|
27
|
+
return entry.name === "__tests__" || entry.name === "i18n"
|
|
28
|
+
? []
|
|
29
|
+
: listSourceFiles(fullPath, extensions);
|
|
30
|
+
}
|
|
31
|
+
return extensions.some((extension) => entry.name.endsWith(extension))
|
|
32
|
+
? [fullPath]
|
|
33
|
+
: [];
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const stylesheets = listSourceFiles(SRC_DIR, [".css"])
|
|
38
|
+
.map((path) => readFileSync(path, "utf8"))
|
|
39
|
+
.join("\n");
|
|
40
|
+
const markup = listSourceFiles(SRC_DIR, [".tsx", ".ts"])
|
|
41
|
+
.map((path) => readFileSync(path, "utf8"))
|
|
42
|
+
.join("\n");
|
|
43
|
+
|
|
44
|
+
const definedVariables = new Set(
|
|
45
|
+
[...stylesheets.matchAll(/(--[a-z][a-z0-9-]*)\s*:/g)].flatMap((match) =>
|
|
46
|
+
match[1] ? [match[1]] : [],
|
|
47
|
+
),
|
|
48
|
+
);
|
|
49
|
+
const emittedPages = new Set(
|
|
50
|
+
[
|
|
51
|
+
...markup.matchAll(/data-page="([a-z-]+)"/g),
|
|
52
|
+
...markup.matchAll(/"data-page": "([a-z-]+)"/g),
|
|
53
|
+
].flatMap((match) => (match[1] ? [match[1]] : [])),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
function readRepoFile(path: string): string {
|
|
57
|
+
return readFileSync(join(REPO_ROOT, path), "utf8");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Variables in the first cell of the docs' tables, e.g. `| `--site-accent` | … |`. */
|
|
61
|
+
function readDocumentedVariables(markdown: string): string[] {
|
|
62
|
+
return [...markdown.matchAll(/^\| `(--[a-z][a-z0-9-]*)`/gm)].flatMap(
|
|
63
|
+
(match) => (match[1] ? [match[1]] : []),
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function readDocumentedAttributes(markdown: string): string[] {
|
|
68
|
+
return [...markdown.matchAll(/`(data-[a-z][a-z-]*)`/g)].flatMap((match) =>
|
|
69
|
+
match[1] ? [match[1]] : [],
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function readDocumentedPages(markdown: string): string[] {
|
|
74
|
+
const row = markdown
|
|
75
|
+
.split("\n")
|
|
76
|
+
.find((line) => line.startsWith("| `data-page`"));
|
|
77
|
+
const values = row?.split("|")[3] ?? "";
|
|
78
|
+
return [...values.matchAll(/`([a-z-]+)`/g)].flatMap((match) =>
|
|
79
|
+
match[1] ? [match[1]] : [],
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
describe("theming docs", () => {
|
|
84
|
+
for (const path of THEMING_DOCS) {
|
|
85
|
+
it(`${path} lists only variables the stylesheets define`, () => {
|
|
86
|
+
const markdown = readRepoFile(path);
|
|
87
|
+
const documented = readDocumentedVariables(markdown);
|
|
88
|
+
expect(documented.length).toBeGreaterThan(0);
|
|
89
|
+
expect(documented.filter((name) => !definedVariables.has(name))).toEqual(
|
|
90
|
+
[],
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it(`${path} lists only data attributes the markup emits`, () => {
|
|
95
|
+
const documented = readDocumentedAttributes(readRepoFile(path));
|
|
96
|
+
expect(documented.length).toBeGreaterThan(0);
|
|
97
|
+
expect(documented.filter((name) => !markup.includes(name))).toEqual([]);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it(`${path} lists exactly the reader pages' data-page values`, () => {
|
|
101
|
+
const readerPages = [...emittedPages]
|
|
102
|
+
.filter((page) => !UNDOCUMENTED_PAGES.has(page))
|
|
103
|
+
.sort();
|
|
104
|
+
expect(readDocumentedPages(readRepoFile(path)).sort()).toEqual(
|
|
105
|
+
readerPages,
|
|
106
|
+
);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
});
|