@jant/core 0.8.0 → 0.9.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/dist/{app-CFsmRVJN.js → app-BzH8jmh3.js} +1619 -500
- package/dist/client/.vite/manifest.json +2 -2
- package/dist/client/_assets/{client-DTLBOHqD.js → client-S8oryJ0m.js} +1 -1
- package/dist/client/_assets/{client-auth-D6Ix6SmE.js → client-auth-Ds9G0IgR.js} +1 -1
- package/dist/index.js +1 -1
- package/dist/node.js +2 -2
- package/package.json +1 -1
- package/src/__tests__/fixtures/releases/0.8.0/site-export/README.md +130 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/2thjq/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/2u5e5/_index.md +35 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/41q27/0x4nv/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/41q27/_index.md +44 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/41q27/faqyt/index.md +30 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/41q27/the-potting-mix-guide-i-keep-rereading/index.md +20 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/5kayp/_index.md +23 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/5ynfs/_index.md +31 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/5ynfs/hu597/index.md +21 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/_index.md +5 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/a-night-heron-field-guide-for-my-walk-folder/_index.md +31 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/a-quiet-saturday-after-a-busy-week/_index.md +36 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/archive/_index.md +8 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/are-na-is-the-only-bookmark-pile-i-still-revisit/_index.md +30 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/bought-too-many-lemons-again/_index.md +37 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/city-walks/_index.md +12 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/cleanshot-for-screenshots-ocr-and-screen-recording-on-the-mac/_index.md +33 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/cleanshotmac-shang-de-jie-tu-ocr-lu-ping-gong-ju/_index.md +32 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/co344/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/collections/_index.md +5 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/current-tea-rotation/_index.md +34 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/derek-sivers-still-writes-the-kind-of-internet-i-want-more-of/_index.md +30 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/desk-but-better/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/e0kcg/_index.md +22 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/egi3c/_index.md +24 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/evf9j/_index.md +152 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/featured/_index.md +8 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/from-basho/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/from-epictetus/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/from-marcus-aurelius/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/from-seneca/_index.md +26 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/from-thoreau/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/gkbvv/2cl6d/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/gkbvv/3zqv7/index.md +30 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/gkbvv/5oxsv/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/gkbvv/_index.md +39 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/gwob9/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/home-cooking/_index.md +12 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/hz729/_index.md +24 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/inaturalist-ai-zi-ran-she-qu/_index.md +44 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/j4v0q/_index.md +35 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/k278t/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/k4eee/_index.md +22 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/k5vh8/_index.md +32 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/k5vh8/a-reading-log-idea-i-might-steal/index.md +20 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/k5vh8/a83qu/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/k5vh8/from-seneca-5hibo/index.md +21 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/kan-qi-lai-bi-jiao-ku-de-gong-si-men/_index.md +41 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/l2m7y/_index.md +29 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/lan-ya-yao-kong-qi-chuang-shang-yue-du-de-fan-ye-shen-qi/_index.md +57 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/mynoise-for-rainy-afternoons/_index.md +30 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/n09le/_index.md +23 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/ni-fu-jin-de-wei-ji-bai-ke-tiao-mu/_index.md +42 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/nts-archives-are-good-cleaning-music/_index.md +30 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/qgfcu/_index.md +32 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/qgfcu/c91j0/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/qgfcu/qyucy/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/qgfcu/wsgck/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/rain-makes-my-neighborhood-look-better/_index.md +46 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/reading-notes/_index.md +12 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/s4r3e/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/serious-eats-on-tomato-and-egg-soup/_index.md +30 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/te812/_index.md +44 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/te812/cxiu6/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/te812/t77ms/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/te812/the-soup-trick-i-always-forget/index.md +20 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/telk3/_index.md +30 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/telk3/from-thoreau-pawt2/index.md +21 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/the-five-minute-reset-is-still-the-best-habit-i-have/_index.md +36 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/the-hallway-light-took-12-minutes-and-3-months/_index.md +32 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/the-recurse-center-manual-is-weirdly-calming/_index.md +30 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/tiny-projects/_index.md +12 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/tong-wang-xing-fu-zhi-lu/_index.md +68 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/tou-ma-yan-jiang-ju-le-bu-chu-ti-yan/_index.md +62 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/useful-links/_index.md +12 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/weekend-notes/_index.md +12 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/what-i-actually-use-my-notebook-for/_index.md +52 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/data/jant.toml +124 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/hugo.toml +45 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/_redirects +25 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/15d51730a4f7-med_01kn8jtq3penf98tfq4gzmh9g9.png +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01kn8jtx8qenf98tm9ahxr48sw.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01kn8jv0jdenf98tp6qr9zgjjc.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01kn8jv452enf98trbkwrvhvgd.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01kn8jvb16enf98txp7p0pf5ge.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01kn8jve5nenf98tzap11gpxzr.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01kn8jvq58enf98v538w5vsqp4.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01kn8jvsaeenf98v6ct4gjzppc.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01kn8jw26cenf98vc7k0ppz5k8.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m313q1hme4e8cmby77dn66yy.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m313q2w7e4e8cmc20036yh66.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m313q7d2e4e8cmdeqjmyafby.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m313q887e4e8cmdjssych7yh.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167jx2f6ct88pkz45j3ycp-poster.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167jx2f6ct88pkz45j3ycp.mp4 +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167mbdf6ct88pr4ga1b9kf-poster.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167mbdf6ct88pr4ga1b9kf.mp4 +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167nsvf6ct88q1anhz4svb-poster.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167nsvf6ct88q1anhz4svb.mp4 +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167qaxf6ct88qfndwzxx83-poster.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167qaxf6ct88qfndwzxx83.mp4 +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167sm0f6ct88qw5brtsgcw.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167tf8f6ct88r169s51j49.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167vaaf6ct88rbx5ztenwb.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167w51f6ct88rp19pybkw1.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167x0nf6ct88rzajb84tw3.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167xxbf6ct88s5t2300bjk.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167yq5f6ct88s9pjwt5fxg.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167zg4f6ct88sge8jp28ja.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/themes/jant/static/apple-touch-icon.png +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/themes/jant/static/custom.css +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/themes/jant/static/favicon.ico +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/wrangler.jsonc +24 -0
- package/src/__tests__/fixtures/releases/0.8.0/snapshot/db.sql +322 -0
- package/src/__tests__/fixtures/releases/0.8.0/snapshot/meta.json +11 -0
- package/src/__tests__/helpers/cursor-walk.ts +82 -0
- package/src/__tests__/release-fixtures.test.ts +6 -2
- package/src/app.tsx +4 -0
- package/src/lib/__tests__/post-list-cursor.test.ts +105 -0
- package/src/lib/__tests__/thread-fold.test.ts +43 -0
- package/src/lib/__tests__/timeline.test.ts +14 -14
- package/src/lib/api-posts.ts +110 -2
- package/src/lib/api-public-posts.ts +263 -0
- package/src/lib/api-threads.ts +207 -0
- package/src/lib/post-list-cursor.ts +211 -0
- package/src/lib/thread-fold.ts +83 -41
- package/src/lib/thread-query.ts +143 -0
- package/src/middleware/cors.ts +8 -1
- package/src/middleware/deprecation.ts +48 -0
- package/src/routes/api/__tests__/mcp.test.ts +147 -0
- package/src/routes/api/__tests__/posts.test.ts +157 -0
- package/src/routes/api/__tests__/public-access.test.ts +5 -0
- package/src/routes/api/__tests__/threads.test.ts +115 -0
- package/src/routes/api/posts.ts +19 -112
- package/src/routes/api/public/__tests__/archive.test.ts +261 -0
- package/src/routes/api/public/__tests__/posts.test.ts +344 -19
- package/src/routes/api/public/__tests__/threads.test.ts +363 -0
- package/src/routes/api/public/archive.ts +82 -79
- package/src/routes/api/public/posts.ts +97 -299
- package/src/routes/api/public/threads.ts +141 -0
- package/src/routes/api/threads.ts +128 -0
- package/src/services/__tests__/post.test.ts +342 -36
- package/src/services/__tests__/thread.test.ts +495 -0
- package/src/services/index.ts +4 -0
- package/src/services/mcp.ts +213 -63
- package/src/services/post.ts +734 -361
- package/src/services/thread.ts +392 -0
- package/src/types/constants.ts +25 -0
- package/src/ui/feed/ThreadPreview.tsx +9 -14
- package/src/ui/feed/__tests__/thread-preview.test.ts +18 -22
- package/src/ui/feed/thread-preview-state.ts +0 -35
- package/src/ui/shared/Pagination.tsx +1 -1
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { createTestApp } from "../../../../__tests__/helpers/app.js";
|
|
3
|
+
import { enforceD1BoundParameterLimit } from "../../../../__tests__/helpers/db.js";
|
|
4
|
+
import {
|
|
5
|
+
walkPostPages,
|
|
6
|
+
walkThreadPages,
|
|
7
|
+
} from "../../../../__tests__/helpers/cursor-walk.js";
|
|
8
|
+
import type { CreatePost, Post } from "../../../../types.js";
|
|
9
|
+
import { publicArchiveApiRoutes } from "../archive.js";
|
|
10
|
+
import { publicPostsApiRoutes } from "../posts.js";
|
|
11
|
+
import { publicThreadsApiRoutes } from "../threads.js";
|
|
12
|
+
|
|
13
|
+
const DAY = 86_400;
|
|
14
|
+
const BASE = Date.UTC(2025, 0, 1) / 1000;
|
|
15
|
+
const day = (n: number) => BASE + n * DAY;
|
|
16
|
+
|
|
17
|
+
function setup() {
|
|
18
|
+
const testApp = createTestApp({ authenticated: false });
|
|
19
|
+
testApp.app.route("/api/public/threads", publicThreadsApiRoutes);
|
|
20
|
+
testApp.app.route("/api/public/posts", publicPostsApiRoutes);
|
|
21
|
+
testApp.app.route("/api/public/archive", publicArchiveApiRoutes);
|
|
22
|
+
const { services } = testApp;
|
|
23
|
+
const post = (data: Partial<CreatePost>) =>
|
|
24
|
+
services.posts.create({ format: "note", bodyMarkdown: "body", ...data });
|
|
25
|
+
/** A root and `replies` replies, one a day, each created when published. */
|
|
26
|
+
const thread = async (replies: number, root: Partial<CreatePost> = {}) => {
|
|
27
|
+
const first = await post({
|
|
28
|
+
publishedAt: day(0),
|
|
29
|
+
createdAt: day(0),
|
|
30
|
+
...root,
|
|
31
|
+
});
|
|
32
|
+
const all: Post[] = [first];
|
|
33
|
+
let parent = first;
|
|
34
|
+
for (let i = 1; i <= replies; i++) {
|
|
35
|
+
parent = await post({
|
|
36
|
+
replyToId: parent.id,
|
|
37
|
+
publishedAt: day(i),
|
|
38
|
+
createdAt: day(i),
|
|
39
|
+
});
|
|
40
|
+
all.push(parent);
|
|
41
|
+
}
|
|
42
|
+
return all;
|
|
43
|
+
};
|
|
44
|
+
const get = async (path: string) => {
|
|
45
|
+
const res = await testApp.app.request(path);
|
|
46
|
+
return { status: res.status, headers: res.headers, body: await res.json() };
|
|
47
|
+
};
|
|
48
|
+
return { ...testApp, post, thread, get };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const ids = (items: Array<{ id: string }>) => items.map((item) => item.id);
|
|
52
|
+
|
|
53
|
+
describe("GET /api/public/threads", () => {
|
|
54
|
+
it("lists what the homepage lists, as Thread objects", async () => {
|
|
55
|
+
const { post, thread, get } = setup();
|
|
56
|
+
const [root, reply] = await thread(1);
|
|
57
|
+
const lone = await post({ publishedAt: day(5) });
|
|
58
|
+
await post({ publishedAt: day(6), visibility: "latest_hidden" });
|
|
59
|
+
await post({ publishedAt: day(7), visibility: "private" });
|
|
60
|
+
|
|
61
|
+
const { status, body } = await get("/api/public/threads");
|
|
62
|
+
expect(status).toBe(200);
|
|
63
|
+
expect(ids(body.threads)).toEqual([lone.id, root?.id]);
|
|
64
|
+
expect(body.nextCursor).toBeNull();
|
|
65
|
+
|
|
66
|
+
const [loneThread, rootThread] = body.threads;
|
|
67
|
+
expect(rootThread).toMatchObject({
|
|
68
|
+
id: root?.id,
|
|
69
|
+
postCount: 2,
|
|
70
|
+
lastActivityAt: reply?.publishedAt,
|
|
71
|
+
root: { id: root?.id, threadPostCount: 2, permalink: `/${root?.slug}` },
|
|
72
|
+
});
|
|
73
|
+
expect(rootThread.fold).toBeUndefined();
|
|
74
|
+
expect(loneThread.postCount).toBe(1);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("attaches the homepage fold on request", async () => {
|
|
78
|
+
const { post, thread, get } = setup();
|
|
79
|
+
const all = await thread(8);
|
|
80
|
+
const lone = await post({ publishedAt: day(1) });
|
|
81
|
+
|
|
82
|
+
const { body } = await get("/api/public/threads?include=fold&sort=oldest");
|
|
83
|
+
const [long, single] = body.threads;
|
|
84
|
+
expect(long.id).toBe(all[0]?.id);
|
|
85
|
+
expect(ids(long.fold.leading)).toEqual(ids(all.slice(1, 3)));
|
|
86
|
+
expect(long.fold.hidden).toBe(3);
|
|
87
|
+
expect(long.fold.gap).toEqual({
|
|
88
|
+
id: all[3]?.id,
|
|
89
|
+
slug: all[3]?.slug,
|
|
90
|
+
permalink: `/${all[3]?.slug}`,
|
|
91
|
+
});
|
|
92
|
+
// Oldest first, the newest reply last.
|
|
93
|
+
expect(ids(long.fold.trailing)).toEqual(ids(all.slice(6)));
|
|
94
|
+
expect(long.fold.trailing[2].threadPostCount).toBe(9);
|
|
95
|
+
|
|
96
|
+
expect(single.id).toBe(lone.id);
|
|
97
|
+
expect(single.fold).toEqual({
|
|
98
|
+
leading: [],
|
|
99
|
+
hidden: 0,
|
|
100
|
+
gap: null,
|
|
101
|
+
trailing: [],
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("opens the run a fold hides with one request", async () => {
|
|
106
|
+
const { thread, get, app } = setup();
|
|
107
|
+
const all = await thread(10);
|
|
108
|
+
const {
|
|
109
|
+
body: { threads },
|
|
110
|
+
} = await get("/api/public/threads?include=fold");
|
|
111
|
+
const fold = threads[0].fold;
|
|
112
|
+
const lastLeading = fold.leading[fold.leading.length - 1].id;
|
|
113
|
+
|
|
114
|
+
const { body } = await get(
|
|
115
|
+
`/api/public/threads/${all[0]?.slug}/posts?cursor=${lastLeading}&limit=${fold.hidden}`,
|
|
116
|
+
);
|
|
117
|
+
expect(body.posts[0].id).toBe(fold.gap.id);
|
|
118
|
+
expect(ids(body.posts)).toEqual(ids(all.slice(3, 3 + fold.hidden)));
|
|
119
|
+
|
|
120
|
+
expect(
|
|
121
|
+
await walkPostPages(app, `/api/public/threads/${all[0]?.slug}/posts`, 3),
|
|
122
|
+
).toEqual(ids(all));
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("widens to every visibility a reader may see with visibility=any", async () => {
|
|
126
|
+
const { post, get } = setup();
|
|
127
|
+
const shown = await post({ publishedAt: day(1) });
|
|
128
|
+
const hidden = await post({
|
|
129
|
+
publishedAt: day(2),
|
|
130
|
+
visibility: "latest_hidden",
|
|
131
|
+
});
|
|
132
|
+
await post({ publishedAt: day(3), visibility: "private" });
|
|
133
|
+
|
|
134
|
+
const any = await get("/api/public/threads?visibility=any");
|
|
135
|
+
expect(ids(any.body.threads)).toEqual([hidden.id, shown.id]);
|
|
136
|
+
const only = await get("/api/public/threads?visibility=hidden");
|
|
137
|
+
expect(ids(only.body.threads)).toEqual([hidden.id]);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("walks a whole site in publication order", async () => {
|
|
141
|
+
const { post, thread, app } = setup();
|
|
142
|
+
const [old] = await thread(1);
|
|
143
|
+
await post({ publishedAt: day(4), visibility: "latest_hidden" });
|
|
144
|
+
await post({ publishedAt: day(3), pinned: true });
|
|
145
|
+
await post({ publishedAt: day(2) });
|
|
146
|
+
|
|
147
|
+
const full = await app.request(
|
|
148
|
+
"/api/public/threads?visibility=any&sort=published&limit=100",
|
|
149
|
+
);
|
|
150
|
+
const expected = ids((await full.json()).threads);
|
|
151
|
+
expect(expected).toHaveLength(4);
|
|
152
|
+
expect(expected[3]).toBe(old?.id);
|
|
153
|
+
expect(
|
|
154
|
+
await walkThreadPages(
|
|
155
|
+
app,
|
|
156
|
+
"/api/public/threads?visibility=any&sort=published",
|
|
157
|
+
1,
|
|
158
|
+
),
|
|
159
|
+
).toEqual(expected);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("takes the archive's filters", async () => {
|
|
163
|
+
const { services, post, get } = setup();
|
|
164
|
+
const collection = await services.collections.create({
|
|
165
|
+
slug: "books",
|
|
166
|
+
title: "Books",
|
|
167
|
+
});
|
|
168
|
+
const titled = await post({
|
|
169
|
+
title: "A title",
|
|
170
|
+
publishedAt: day(1),
|
|
171
|
+
collectionIds: [collection.id],
|
|
172
|
+
});
|
|
173
|
+
await post({ publishedAt: day(2), collectionIds: [collection.id] });
|
|
174
|
+
await post({ title: "Elsewhere", publishedAt: day(3) });
|
|
175
|
+
|
|
176
|
+
const { body } = await get(
|
|
177
|
+
"/api/public/threads?collection=books&title=any",
|
|
178
|
+
);
|
|
179
|
+
expect(ids(body.threads)).toEqual([titled.id]);
|
|
180
|
+
const missing = await get("/api/public/threads?collection=nope");
|
|
181
|
+
expect(missing.status).toBe(200);
|
|
182
|
+
expect(missing.body).toEqual({ threads: [], nextCursor: null });
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it.each([
|
|
186
|
+
["an unknown parameter", "?sorting=published"],
|
|
187
|
+
["visibility=all", "?visibility=all"],
|
|
188
|
+
["visibility=private", "?visibility=private"],
|
|
189
|
+
["an unknown include", "?include=replies"],
|
|
190
|
+
["an unknown sort", "?sort=newest"],
|
|
191
|
+
["featured with another order", "?visibility=featured&sort=activity"],
|
|
192
|
+
])("refuses %s", async (_label, query) => {
|
|
193
|
+
const { get } = setup();
|
|
194
|
+
const { status, body } = await get(`/api/public/threads${query}`);
|
|
195
|
+
expect(status).toBe(400);
|
|
196
|
+
expect(typeof body.error).toBe("string");
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// D1 refuses a statement with more than 100 bound parameters, and a full
|
|
200
|
+
// page with the fold asks about 100 Threads at once.
|
|
201
|
+
it("serves a full page with the fold within D1's parameter limit", async () => {
|
|
202
|
+
const { services, sqlite, get } = setup();
|
|
203
|
+
for (let i = 0; i < 101; i++) {
|
|
204
|
+
const root = await services.posts.create({
|
|
205
|
+
format: "note",
|
|
206
|
+
bodyMarkdown: `root ${i}`,
|
|
207
|
+
publishedAt: day(i),
|
|
208
|
+
});
|
|
209
|
+
if (i % 10 === 0) {
|
|
210
|
+
await services.posts.create({
|
|
211
|
+
format: "note",
|
|
212
|
+
bodyMarkdown: `reply ${i}`,
|
|
213
|
+
replyToId: root.id,
|
|
214
|
+
publishedAt: day(i) + 1,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
enforceD1BoundParameterLimit(sqlite);
|
|
219
|
+
|
|
220
|
+
const { status, body } = await get(
|
|
221
|
+
"/api/public/threads?limit=100&include=fold",
|
|
222
|
+
);
|
|
223
|
+
expect(status).toBe(200);
|
|
224
|
+
expect(body.threads).toHaveLength(100);
|
|
225
|
+
expect(
|
|
226
|
+
body.threads.filter(
|
|
227
|
+
(thread: { fold: { trailing: unknown[] } }) =>
|
|
228
|
+
thread.fold.trailing.length === 1,
|
|
229
|
+
),
|
|
230
|
+
).toHaveLength(10);
|
|
231
|
+
expect(body.nextCursor).not.toBeNull();
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("returns Markdown on request", async () => {
|
|
235
|
+
const { post, get } = setup();
|
|
236
|
+
await post({ publishedAt: day(1), bodyMarkdown: "Some *text*" });
|
|
237
|
+
const { body } = await get("/api/public/threads?content=markdown");
|
|
238
|
+
expect(body.threads[0].root.bodyMarkdown).toBe("Some *text*");
|
|
239
|
+
expect(body.threads[0].root.bodyHtml).toBeUndefined();
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
describe("GET /api/public/threads/:slug", () => {
|
|
244
|
+
it("returns the Thread any of its Posts names", async () => {
|
|
245
|
+
const { thread, get } = setup();
|
|
246
|
+
const all = await thread(2);
|
|
247
|
+
const { status, body } = await get(
|
|
248
|
+
`/api/public/threads/${all[2]?.slug}?include=fold`,
|
|
249
|
+
);
|
|
250
|
+
expect(status).toBe(200);
|
|
251
|
+
expect(body).toMatchObject({ id: all[0]?.id, postCount: 3 });
|
|
252
|
+
expect(ids(body.fold.leading)).toEqual(ids(all.slice(1, 2)));
|
|
253
|
+
expect(ids(body.fold.trailing)).toEqual(ids(all.slice(2)));
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it("finds a Thread hidden from Latest", async () => {
|
|
257
|
+
const { thread, get } = setup();
|
|
258
|
+
const [root] = await thread(0, { visibility: "latest_hidden" });
|
|
259
|
+
expect((await get(`/api/public/threads/${root?.slug}`)).status).toBe(200);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it("returns 404 for what a reader can't see", async () => {
|
|
263
|
+
const { services, post, thread, get } = setup();
|
|
264
|
+
const secret = await post({ publishedAt: day(1), visibility: "private" });
|
|
265
|
+
const draft = await post({ status: "draft" });
|
|
266
|
+
const all = await thread(1);
|
|
267
|
+
const unsent = await services.posts.create({
|
|
268
|
+
format: "note",
|
|
269
|
+
bodyMarkdown: "unsent",
|
|
270
|
+
replyToId: all[1]?.id,
|
|
271
|
+
status: "draft",
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
for (const slug of [secret.slug, draft.slug, unsent.slug, "missing"]) {
|
|
275
|
+
expect((await get(`/api/public/threads/${slug}`)).status).toBe(404);
|
|
276
|
+
expect((await get(`/api/public/threads/${slug}/posts`)).status).toBe(404);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
describe("GET /api/public/threads/:slug/posts", () => {
|
|
282
|
+
it("lists published Posts in Thread order", async () => {
|
|
283
|
+
const { services, thread, get } = setup();
|
|
284
|
+
const all = await thread(3);
|
|
285
|
+
await services.posts.create({
|
|
286
|
+
format: "note",
|
|
287
|
+
bodyMarkdown: "unsent",
|
|
288
|
+
replyToId: all[3]?.id,
|
|
289
|
+
status: "draft",
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
const { body } = await get(`/api/public/threads/${all[1]?.slug}/posts`);
|
|
293
|
+
expect(ids(body.posts)).toEqual(ids(all));
|
|
294
|
+
expect(body.posts[0].threadPostCount).toBe(4);
|
|
295
|
+
expect(body.nextCursor).toBeNull();
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it("pages a Thread longer than one page", async () => {
|
|
299
|
+
const { thread, get, sqlite } = setup();
|
|
300
|
+
const all = await thread(104);
|
|
301
|
+
enforceD1BoundParameterLimit(sqlite);
|
|
302
|
+
|
|
303
|
+
const path = `/api/public/threads/${all[0]?.slug}/posts`;
|
|
304
|
+
const first = await get(path);
|
|
305
|
+
expect(first.status).toBe(200);
|
|
306
|
+
expect(first.body.posts).toHaveLength(100);
|
|
307
|
+
expect(first.body.posts[0].threadPostCount).toBe(105);
|
|
308
|
+
const second = await get(`${path}?cursor=${first.body.nextCursor}`);
|
|
309
|
+
expect(second.body.nextCursor).toBeNull();
|
|
310
|
+
expect([...ids(first.body.posts), ...ids(second.body.posts)]).toEqual(
|
|
311
|
+
ids(all),
|
|
312
|
+
);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it("refuses a cursor that names a Post outside the Thread", async () => {
|
|
316
|
+
const { post, thread, get } = setup();
|
|
317
|
+
const all = await thread(1);
|
|
318
|
+
const other = await post({ publishedAt: day(3) });
|
|
319
|
+
const { status } = await get(
|
|
320
|
+
`/api/public/threads/${all[0]?.slug}/posts?cursor=${other.id}`,
|
|
321
|
+
);
|
|
322
|
+
expect(status).toBe(400);
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
describe("deprecated Thread lists", () => {
|
|
327
|
+
it.each([
|
|
328
|
+
["/api/public/posts", "</api/public/threads>"],
|
|
329
|
+
[
|
|
330
|
+
"/api/public/archive",
|
|
331
|
+
"</api/public/threads?visibility=any&sort=published>",
|
|
332
|
+
],
|
|
333
|
+
])(
|
|
334
|
+
"%s names its replacement and still answers as before",
|
|
335
|
+
async (path, successor) => {
|
|
336
|
+
const { thread, get } = setup();
|
|
337
|
+
const [root] = await thread(2);
|
|
338
|
+
|
|
339
|
+
const { status, headers, body } = await get(path);
|
|
340
|
+
expect(status).toBe(200);
|
|
341
|
+
expect(headers.get("Deprecation")).toMatch(/^@\d+$/);
|
|
342
|
+
expect(headers.get("Link")).toBe(`${successor}; rel="successor-version"`);
|
|
343
|
+
expect(ids(body.posts)).toEqual([root?.id]);
|
|
344
|
+
expect(body.posts[0].threadPostCount).toBe(3);
|
|
345
|
+
|
|
346
|
+
// Errors carry the headers too.
|
|
347
|
+
const refused = await get(`${path}?limit=0`);
|
|
348
|
+
expect(refused.status).toBe(400);
|
|
349
|
+
expect(refused.headers.get("Deprecation")).toMatch(/^@\d+$/);
|
|
350
|
+
},
|
|
351
|
+
);
|
|
352
|
+
|
|
353
|
+
it("leaves the single-post endpoint undeprecated", async () => {
|
|
354
|
+
const { thread, get } = setup();
|
|
355
|
+
const all = await thread(1);
|
|
356
|
+
const { status, headers, body } = await get(
|
|
357
|
+
`/api/public/posts/${all[1]?.slug}`,
|
|
358
|
+
);
|
|
359
|
+
expect(status).toBe(200);
|
|
360
|
+
expect(headers.get("Deprecation")).toBeNull();
|
|
361
|
+
expect(body.threadPostCount).toBe(2);
|
|
362
|
+
});
|
|
363
|
+
});
|
|
@@ -13,8 +13,12 @@ import {
|
|
|
13
13
|
toPostFilters,
|
|
14
14
|
} from "../../../lib/filter-dimensions.js";
|
|
15
15
|
import { ValidationError } from "../../../lib/errors.js";
|
|
16
|
-
import {
|
|
16
|
+
import { loadPublicPostResponses } from "../../../lib/api-public-posts.js";
|
|
17
17
|
import { requirePublicApiEnabled } from "../../../middleware/public-content-access.js";
|
|
18
|
+
import {
|
|
19
|
+
deprecated,
|
|
20
|
+
THREAD_LIST_DEPRECATED_AT,
|
|
21
|
+
} from "../../../middleware/deprecation.js";
|
|
18
22
|
|
|
19
23
|
type Env = { Bindings: Bindings; Variables: AppVariables };
|
|
20
24
|
|
|
@@ -45,88 +49,87 @@ const INVALID_VISIBILITY_MESSAGE =
|
|
|
45
49
|
value === "latest_hidden" ? "hidden" : value,
|
|
46
50
|
).join(", ");
|
|
47
51
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Deprecated in 0.9 for `GET /api/public/threads?visibility=any&sort=published`,
|
|
54
|
+
* which takes the same filters. Answers as it always has until 1.0.1 removes it.
|
|
55
|
+
*/
|
|
56
|
+
publicArchiveApiRoutes.get(
|
|
57
|
+
"/",
|
|
58
|
+
deprecated(
|
|
59
|
+
THREAD_LIST_DEPRECATED_AT,
|
|
60
|
+
"/api/public/threads?visibility=any&sort=published",
|
|
61
|
+
),
|
|
62
|
+
async (c) => {
|
|
63
|
+
const { lang, cursor, limit, content } = parseValidated(
|
|
64
|
+
ListPublicArchiveQuerySchema,
|
|
65
|
+
c.req.query(),
|
|
66
|
+
);
|
|
55
67
|
|
|
56
|
-
|
|
57
|
-
// the caller named one.
|
|
58
|
-
const slugs = readCollectionSlugs(read);
|
|
59
|
-
const ctx: DimensionContext = {
|
|
60
|
-
collections:
|
|
61
|
-
slugs.length > 0
|
|
62
|
-
? buildCollectionVocabulary(await c.var.services.collections.list())
|
|
63
|
-
: EMPTY_COLLECTION_VOCABULARY,
|
|
64
|
-
};
|
|
68
|
+
const read = (key: string): string | undefined => c.req.query(key);
|
|
65
69
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
ctx
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
// Resolving a collection slug costs a round trip, so it is paid for only when
|
|
71
|
+
// the caller named one.
|
|
72
|
+
const slugs = readCollectionSlugs(read);
|
|
73
|
+
const ctx: DimensionContext = {
|
|
74
|
+
collections:
|
|
75
|
+
slugs.length > 0
|
|
76
|
+
? buildCollectionVocabulary(await c.var.services.collections.list())
|
|
77
|
+
: EMPTY_COLLECTION_VOCABULARY,
|
|
78
|
+
};
|
|
72
79
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
) {
|
|
80
|
-
return c.json({ posts: [], nextCursor: null });
|
|
81
|
-
}
|
|
82
|
-
if (!parsed.ok) {
|
|
83
|
-
const first = parsed.issues[0];
|
|
84
|
-
throw new ValidationError(first?.message ?? "Validation failed");
|
|
85
|
-
}
|
|
80
|
+
const parsed = parsePostFilterSelectionStrict(
|
|
81
|
+
read,
|
|
82
|
+
Object.keys(c.req.query()),
|
|
83
|
+
ctx,
|
|
84
|
+
{ allow: ENDPOINT_PARAMS },
|
|
85
|
+
);
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
87
|
+
// A collection slug that names nothing is answered as an empty result rather
|
|
88
|
+
// than a rejection: the caller's words were understood, and this site simply
|
|
89
|
+
// holds no such collection.
|
|
90
|
+
if (
|
|
91
|
+
!parsed.ok &&
|
|
92
|
+
parsed.issues.every((issue) => issue.param === "collection")
|
|
93
|
+
) {
|
|
94
|
+
return c.json({ posts: [], nextCursor: null });
|
|
95
|
+
}
|
|
96
|
+
if (!parsed.ok) {
|
|
97
|
+
const first = parsed.issues[0];
|
|
98
|
+
throw new ValidationError(first?.message ?? "Validation failed");
|
|
99
|
+
}
|
|
97
100
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
// counterpart on a cursor keyed off the post id.
|
|
109
|
-
...toPostFilters(parsed.selection, { yearAxis: "published" }),
|
|
110
|
-
ignorePinnedSort: true,
|
|
111
|
-
});
|
|
101
|
+
// `private` names a set no anonymous caller may see. Rejected rather than
|
|
102
|
+
// dropped: silently widening the result to the whole archive would answer a
|
|
103
|
+
// different question under the caller's own words.
|
|
104
|
+
const visibility = parsed.selection.visibility;
|
|
105
|
+
if (
|
|
106
|
+
visibility !== undefined &&
|
|
107
|
+
!(PUBLIC_ARCHIVE_VISIBILITIES as readonly string[]).includes(visibility)
|
|
108
|
+
) {
|
|
109
|
+
throw new ValidationError(INVALID_VISIBILITY_MESSAGE);
|
|
110
|
+
}
|
|
112
111
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
112
|
+
const { posts, nextCursor } = await c.var.services.posts.listPage(
|
|
113
|
+
{
|
|
114
|
+
lang,
|
|
115
|
+
status: "published",
|
|
116
|
+
excludePrivate: true,
|
|
117
|
+
excludeLatestHidden: false,
|
|
118
|
+
excludeReplies: true,
|
|
119
|
+
// Newest-published-first, the page's default order. Named explicitly:
|
|
120
|
+
// left unset, a published list sorts by activity, and a reply would
|
|
121
|
+
// lift an old root to the top. The year filter reads the same column,
|
|
122
|
+
// and so does the cursor.
|
|
123
|
+
...toPostFilters(parsed.selection, { yearAxis: "published" }),
|
|
124
|
+
sortBy: "published",
|
|
125
|
+
ignorePinnedSort: true,
|
|
126
|
+
},
|
|
127
|
+
{ cursor, limit },
|
|
128
|
+
);
|
|
118
129
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
c.var.appConfig,
|
|
126
|
-
{ content },
|
|
127
|
-
),
|
|
128
|
-
),
|
|
129
|
-
nextCursor:
|
|
130
|
-
posts.length === limit ? (posts[posts.length - 1]?.id ?? null) : null,
|
|
131
|
-
});
|
|
132
|
-
});
|
|
130
|
+
return c.json({
|
|
131
|
+
posts: await loadPublicPostResponses(c.var, posts, { content }),
|
|
132
|
+
nextCursor,
|
|
133
|
+
});
|
|
134
|
+
},
|
|
135
|
+
);
|