@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,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cursor Walk Helper
|
|
3
|
+
*
|
|
4
|
+
* Follows a paginated posts or Threads endpoint the way a client does, so route
|
|
5
|
+
* tests can compare a walk against one unpaged request.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { expect } from "vitest";
|
|
9
|
+
|
|
10
|
+
interface RequestTarget {
|
|
11
|
+
request(path: string): Response | Promise<Response>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Follow `nextCursor` from the first page until it is null, one request per
|
|
16
|
+
* page, and fail on any non-200 page or a walk that doesn't end.
|
|
17
|
+
*
|
|
18
|
+
* @param app - The test app the endpoint is mounted on
|
|
19
|
+
* @param path - Endpoint path with its query, without `limit` or `cursor`
|
|
20
|
+
* @param limit - Page size
|
|
21
|
+
* @param from - A `nextCursor` to resume from instead of the first page
|
|
22
|
+
* @returns Every post ID, in the order the pages returned them
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* expect(await walkPostPages(app, "/api/public/archive", 1)).toEqual(ids);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export async function walkPostPages(
|
|
29
|
+
app: RequestTarget,
|
|
30
|
+
path: string,
|
|
31
|
+
limit: number,
|
|
32
|
+
from: string | null = null,
|
|
33
|
+
): Promise<string[]> {
|
|
34
|
+
return walkPages(app, path, limit, "posts", from);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* {@link walkPostPages} for a Thread list, whose pages hold `threads`.
|
|
39
|
+
*
|
|
40
|
+
* @param app - The test app the endpoint is mounted on
|
|
41
|
+
* @param path - Endpoint path with its query, without `limit` or `cursor`
|
|
42
|
+
* @param limit - Page size
|
|
43
|
+
* @returns Every Thread ID, in the order the pages returned them
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* expect(await walkThreadPages(app, "/api/public/threads", 1)).toEqual(ids);
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export async function walkThreadPages(
|
|
50
|
+
app: RequestTarget,
|
|
51
|
+
path: string,
|
|
52
|
+
limit: number,
|
|
53
|
+
): Promise<string[]> {
|
|
54
|
+
return walkPages(app, path, limit, "threads", null);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function walkPages(
|
|
58
|
+
app: RequestTarget,
|
|
59
|
+
path: string,
|
|
60
|
+
limit: number,
|
|
61
|
+
key: "posts" | "threads",
|
|
62
|
+
from: string | null,
|
|
63
|
+
): Promise<string[]> {
|
|
64
|
+
const separator = path.includes("?") ? "&" : "?";
|
|
65
|
+
const ids: string[] = [];
|
|
66
|
+
let cursor = from;
|
|
67
|
+
for (let page = 0; page < 100; page++) {
|
|
68
|
+
const query: string = cursor
|
|
69
|
+
? `limit=${limit}&cursor=${encodeURIComponent(cursor)}`
|
|
70
|
+
: `limit=${limit}`;
|
|
71
|
+
const res = await app.request(`${path}${separator}${query}`);
|
|
72
|
+
expect(res.status).toBe(200);
|
|
73
|
+
const body = (await res.json()) as Record<
|
|
74
|
+
typeof key,
|
|
75
|
+
Array<{ id: string }>
|
|
76
|
+
> & { nextCursor: string | null };
|
|
77
|
+
ids.push(...body[key].map((item) => item.id));
|
|
78
|
+
if (body.nextCursor === null) return ids;
|
|
79
|
+
cursor = body.nextCursor;
|
|
80
|
+
}
|
|
81
|
+
throw new Error(`The walk of ${path} did not end`);
|
|
82
|
+
}
|
|
@@ -4,8 +4,12 @@
|
|
|
4
4
|
* `fixtures/releases/<version>/` freezes what that release wrote: a site
|
|
5
5
|
* snapshot (`snapshot/meta.json` and `snapshot/db.sql`, no objects) and a
|
|
6
6
|
* site export (`site-export/`, without the bundled theme's templates and
|
|
7
|
-
* styles, which import doesn't read).
|
|
8
|
-
*
|
|
7
|
+
* styles, which import doesn't read). From 0.8.0 on, that release's published
|
|
8
|
+
* package writes both from the canonical demo content at its tag
|
|
9
|
+
* (`scripts/release/freeze-fixtures.mjs`). 0.7.0 and 0.7.1 are copies of the
|
|
10
|
+
* canonical directory at their tags, which earlier versions had written: a
|
|
11
|
+
* July site export and a snapshot without `jant` or `schema`. Fixtures are
|
|
12
|
+
* never edited afterwards.
|
|
9
13
|
*
|
|
10
14
|
* The canonical fixtures under `sites/demo-source/canonical/` are
|
|
11
15
|
* re-exported as the demo changes, so they only prove that head reads what
|
package/src/app.tsx
CHANGED
|
@@ -36,6 +36,7 @@ import { customUrlsRoutes } from "./routes/dash/custom-urls.js";
|
|
|
36
36
|
|
|
37
37
|
// Routes - API
|
|
38
38
|
import { postsApiRoutes } from "./routes/api/posts.js";
|
|
39
|
+
import { threadsApiRoutes } from "./routes/api/threads.js";
|
|
39
40
|
import { attachmentsApiRoutes } from "./routes/api/attachments.js";
|
|
40
41
|
import { navItemsApiRoutes } from "./routes/api/nav-items.js";
|
|
41
42
|
import { collectionsApiRoutes } from "./routes/api/collections.js";
|
|
@@ -60,6 +61,7 @@ import { internalPostBodyHtmlRoutes } from "./routes/api/internal/post-body-html
|
|
|
60
61
|
import { internalUploadsRoutes } from "./routes/api/internal/uploads.js";
|
|
61
62
|
import { publicArchiveApiRoutes } from "./routes/api/public/archive.js";
|
|
62
63
|
import { publicPostsApiRoutes } from "./routes/api/public/posts.js";
|
|
64
|
+
import { publicThreadsApiRoutes } from "./routes/api/public/threads.js";
|
|
63
65
|
import { discoverApiRoutes } from "./routes/api/discover.js";
|
|
64
66
|
// Routes - Compose
|
|
65
67
|
import { composeRoutes } from "./routes/compose.js";
|
|
@@ -579,9 +581,11 @@ export function createApp(): App {
|
|
|
579
581
|
|
|
580
582
|
// API Routes
|
|
581
583
|
app.route("/api/public/posts", publicPostsApiRoutes);
|
|
584
|
+
app.route("/api/public/threads", publicThreadsApiRoutes);
|
|
582
585
|
app.route("/api/public/archive", publicArchiveApiRoutes);
|
|
583
586
|
app.route("/api/discover", discoverApiRoutes);
|
|
584
587
|
app.route("/api/posts", postsApiRoutes);
|
|
588
|
+
app.route("/api/threads", threadsApiRoutes);
|
|
585
589
|
app.route("/api/nav-items", navItemsApiRoutes);
|
|
586
590
|
app.route("/api/collections", collectionsApiRoutes);
|
|
587
591
|
app.route("/api/smart-collections", smartCollectionsApiRoutes);
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { ValidationError } from "../errors.js";
|
|
3
|
+
import {
|
|
4
|
+
decodePostListCursor,
|
|
5
|
+
encodePostListCursor,
|
|
6
|
+
isLegacyPostListCursor,
|
|
7
|
+
type PostListCursorShape,
|
|
8
|
+
} from "../post-list-cursor.js";
|
|
9
|
+
|
|
10
|
+
const POST_ID = "pst_01jpyx3m7gw4w3h7m4bknq0v1d";
|
|
11
|
+
const SHAPE: PostListCursorShape = {
|
|
12
|
+
mode: "newest:activity:pinned",
|
|
13
|
+
kinds: ["number", "number", "id"],
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/** Encode an arbitrary payload the way the codec would, for hostile inputs. */
|
|
17
|
+
function encodeRaw(payload: unknown): string {
|
|
18
|
+
return btoa(JSON.stringify(payload))
|
|
19
|
+
.replace(/\+/g, "-")
|
|
20
|
+
.replace(/\//g, "_")
|
|
21
|
+
.replace(/=+$/, "");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function decodeError(raw: string, shape = SHAPE): string {
|
|
25
|
+
try {
|
|
26
|
+
decodePostListCursor(raw, shape);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
expect(error).toBeInstanceOf(ValidationError);
|
|
29
|
+
return (error as ValidationError).message;
|
|
30
|
+
}
|
|
31
|
+
throw new Error(`Expected ${raw} to be rejected`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
describe("post list cursor", () => {
|
|
35
|
+
it("round-trips a key tuple", () => {
|
|
36
|
+
const values = [-1, 1706000000, POST_ID];
|
|
37
|
+
const cursor = encodePostListCursor(SHAPE.mode, values);
|
|
38
|
+
|
|
39
|
+
expect(cursor).toMatch(/^[A-Za-z0-9_-]+$/);
|
|
40
|
+
expect(decodePostListCursor(cursor, SHAPE)).toEqual(values);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("stays short enough for a URL at the widest tuple", () => {
|
|
44
|
+
const cursor = encodePostListCursor("rating_desc:thread_updated:pinned", [
|
|
45
|
+
1706000000,
|
|
46
|
+
5,
|
|
47
|
+
1706000000,
|
|
48
|
+
POST_ID,
|
|
49
|
+
]);
|
|
50
|
+
expect(cursor.length).toBeLessThan(200);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("never looks like a bare post ID", () => {
|
|
54
|
+
const cursor = encodePostListCursor(SHAPE.mode, [-1, 0, POST_ID]);
|
|
55
|
+
expect(isLegacyPostListCursor(cursor)).toBe(false);
|
|
56
|
+
expect(isLegacyPostListCursor(POST_ID)).toBe(true);
|
|
57
|
+
expect(isLegacyPostListCursor("med_01jpyx4g9m8b4y50a4gx3t7p1n")).toBe(
|
|
58
|
+
false,
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("rejects a cursor that can't be read", () => {
|
|
63
|
+
const unreadable = decodeError("not a cursor");
|
|
64
|
+
for (const raw of [
|
|
65
|
+
"",
|
|
66
|
+
"a",
|
|
67
|
+
"%%%",
|
|
68
|
+
"x".repeat(600),
|
|
69
|
+
encodeRaw("just a string"),
|
|
70
|
+
encodeRaw([1, "newest:activity:pinned", []]),
|
|
71
|
+
encodeRaw({ s: SHAPE.mode, k: [-1, 0, POST_ID] }),
|
|
72
|
+
encodeRaw({ v: 1, s: SHAPE.mode }),
|
|
73
|
+
encodeRaw({ v: 1, s: SHAPE.mode, k: [-1, 0, POST_ID], extra: true }),
|
|
74
|
+
encodeRaw({ v: 1, s: 7, k: [-1, 0, POST_ID] }),
|
|
75
|
+
// Wrong length, wrong kinds, a fraction, an unsafe integer, a non-post ID.
|
|
76
|
+
encodeRaw({ v: 1, s: SHAPE.mode, k: [-1, POST_ID] }),
|
|
77
|
+
encodeRaw({ v: 1, s: SHAPE.mode, k: [-1, 0, POST_ID, 4] }),
|
|
78
|
+
encodeRaw({ v: 1, s: SHAPE.mode, k: ["-1", 0, POST_ID] }),
|
|
79
|
+
encodeRaw({ v: 1, s: SHAPE.mode, k: [-1, 0.5, POST_ID] }),
|
|
80
|
+
encodeRaw({ v: 1, s: SHAPE.mode, k: [-1, 2 ** 60, POST_ID] }),
|
|
81
|
+
encodeRaw({
|
|
82
|
+
v: 1,
|
|
83
|
+
s: SHAPE.mode,
|
|
84
|
+
k: [-1, 0, "med_01jpyx4g9m8b4y50a4gx3t7p1n"],
|
|
85
|
+
}),
|
|
86
|
+
encodeRaw({ v: 1, s: SHAPE.mode, k: [-1, 0, null] }),
|
|
87
|
+
]) {
|
|
88
|
+
expect(decodeError(raw)).toBe(unreadable);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("names an unknown format version", () => {
|
|
93
|
+
expect(
|
|
94
|
+
decodeError(encodeRaw({ v: 2, s: SHAPE.mode, k: [-1, 0, POST_ID] })),
|
|
95
|
+
).toMatch(/different version/);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("names a cursor taken in another sort mode", () => {
|
|
99
|
+
const cursor = encodePostListCursor("newest:published:unpinned", [
|
|
100
|
+
0,
|
|
101
|
+
POST_ID,
|
|
102
|
+
]);
|
|
103
|
+
expect(decodeError(cursor)).toMatch(/different order/);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import {
|
|
3
|
+
foldReplyWindows,
|
|
3
4
|
foldThreadReplies,
|
|
4
5
|
getThreadHiddenCount,
|
|
5
6
|
THREAD_LEADING_REPLIES,
|
|
@@ -73,6 +74,48 @@ describe("foldThreadReplies", () => {
|
|
|
73
74
|
});
|
|
74
75
|
});
|
|
75
76
|
|
|
77
|
+
describe("foldReplyWindows", () => {
|
|
78
|
+
/**
|
|
79
|
+
* The windows as `getThreadTimelineContext` ranks them in SQL: overlapping
|
|
80
|
+
* on a short thread, the trailing window without the hero, and the reply one
|
|
81
|
+
* past the leading window fetched whether or not it ends up hidden.
|
|
82
|
+
*/
|
|
83
|
+
const rankedWindows = (count: number) => {
|
|
84
|
+
const all = replies(count);
|
|
85
|
+
return {
|
|
86
|
+
leadingReplies: all.slice(0, THREAD_LEADING_REPLIES),
|
|
87
|
+
trailingReplies: all.slice(
|
|
88
|
+
Math.max(0, count - THREAD_TRAILING_REPLIES),
|
|
89
|
+
count - 1,
|
|
90
|
+
),
|
|
91
|
+
latestReply: all[count - 1] ?? reply(0),
|
|
92
|
+
nextReply: all[THREAD_LEADING_REPLIES] ?? null,
|
|
93
|
+
totalReplyCount: count,
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// The site and the API fold from ranked windows, the feed from the whole
|
|
98
|
+
// chain. Both must describe the same thread the same way.
|
|
99
|
+
it.each([1, 2, 3, 4, 5, 6, 7, 12])(
|
|
100
|
+
"folds %i replies the way the whole chain does",
|
|
101
|
+
(count) => {
|
|
102
|
+
expect(foldReplyWindows(rankedWindows(count))).toEqual(
|
|
103
|
+
foldThreadReplies(replies(count)),
|
|
104
|
+
);
|
|
105
|
+
},
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
// With four replies the reply after the leading window is the third-newest,
|
|
109
|
+
// on screen in the trailing window. It is not a gap target.
|
|
110
|
+
it("never points the gap at a reply it shows", () => {
|
|
111
|
+
const fold = foldReplyWindows(rankedWindows(4));
|
|
112
|
+
|
|
113
|
+
expect(fold.hiddenCount).toBe(0);
|
|
114
|
+
expect(fold.firstHiddenReply).toBeNull();
|
|
115
|
+
expect(ids(fold.trailingReplies)).toEqual(["reply-3"]);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
76
119
|
describe("getThreadHiddenCount", () => {
|
|
77
120
|
// The site selects its buckets in SQL and they overlap on short threads, so
|
|
78
121
|
// the count has to dedupe rather than subtract two lengths.
|
|
@@ -219,25 +219,25 @@ describe("Timeline data assembly", () => {
|
|
|
219
219
|
);
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
+
const filters = { status: "published" as const, excludeReplies: true };
|
|
223
|
+
|
|
222
224
|
// First page
|
|
223
|
-
const page1 = await postService.
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
limit: 3,
|
|
227
|
-
});
|
|
228
|
-
expect(page1).toHaveLength(3);
|
|
225
|
+
const page1 = await postService.listPage(filters, { limit: 3 });
|
|
226
|
+
expect(page1.posts).toHaveLength(3);
|
|
227
|
+
expect(page1.nextCursor).not.toBeNull();
|
|
229
228
|
|
|
230
229
|
// Second page using cursor
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
const page2 = await postService.list({
|
|
234
|
-
status: "published",
|
|
235
|
-
excludeReplies: true,
|
|
230
|
+
const page2 = await postService.listPage(filters, {
|
|
231
|
+
cursor: page1.nextCursor ?? undefined,
|
|
236
232
|
limit: 3,
|
|
237
|
-
cursor: lastPost?.id,
|
|
238
233
|
});
|
|
239
|
-
expect(page2).
|
|
240
|
-
|
|
234
|
+
expect(page2.posts.map((post) => post.id)).toEqual(
|
|
235
|
+
posts
|
|
236
|
+
.slice(0, 2)
|
|
237
|
+
.map((post) => post.id)
|
|
238
|
+
.reverse(),
|
|
239
|
+
);
|
|
240
|
+
expect(page2.nextCursor).toBeNull();
|
|
241
241
|
});
|
|
242
242
|
|
|
243
243
|
it("supports offset-based pagination for page navigation", async () => {
|
package/src/lib/api-posts.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { isTextAttachment } from "../services/media.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Services } from "../services/index.js";
|
|
3
|
+
import type { PostFilters } from "../services/post.js";
|
|
4
|
+
import type { AppConfig } from "../types/config.js";
|
|
5
|
+
import type { Media, Post, Status } from "../types.js";
|
|
3
6
|
import { getPostDisplayTitle } from "./post-meta.js";
|
|
4
7
|
import { getImageUrl, getMediaUrl, getPublicUrlForProvider } from "./image.js";
|
|
5
8
|
import { toPublicPath } from "./url.js";
|
|
@@ -14,11 +17,37 @@ export type ApiPostResponse = Omit<Post, "title" | "url"> & {
|
|
|
14
17
|
* a URL, not a name.
|
|
15
18
|
*/
|
|
16
19
|
displayTitle: string;
|
|
20
|
+
/**
|
|
21
|
+
* Published Posts in this Post's Thread, its root included: 1 for a Post on
|
|
22
|
+
* its own, 0 while nothing in the Thread is published.
|
|
23
|
+
*/
|
|
24
|
+
threadPostCount: number;
|
|
17
25
|
url?: string | null;
|
|
18
26
|
sourceName?: string | null;
|
|
19
27
|
sourceUrl?: string | null;
|
|
20
28
|
};
|
|
21
29
|
|
|
30
|
+
/**
|
|
31
|
+
* The order `GET /api/posts` and `jant_posts_list` walk Posts in.
|
|
32
|
+
*
|
|
33
|
+
* Published Posts run newest-published first, pins ignored: a Post's place
|
|
34
|
+
* then depends on its own publication alone, and a reply added to an old
|
|
35
|
+
* Thread doesn't lift the root past a walk's cursor. Drafts keep the editing
|
|
36
|
+
* order the composer's draft list reads, last edited first.
|
|
37
|
+
*
|
|
38
|
+
* @param status - The status the list is filtered to
|
|
39
|
+
* @returns The `PostFilters` ordering fields for that list
|
|
40
|
+
* @example
|
|
41
|
+
* posts.listPage({ status, ...apiPostListOrder(status) }, { limit: 100 });
|
|
42
|
+
*/
|
|
43
|
+
export function apiPostListOrder(
|
|
44
|
+
status: Status,
|
|
45
|
+
): Pick<PostFilters, "sortBy" | "ignorePinnedSort"> {
|
|
46
|
+
return status === "draft"
|
|
47
|
+
? {}
|
|
48
|
+
: { sortBy: "published", ignorePinnedSort: true };
|
|
49
|
+
}
|
|
50
|
+
|
|
22
51
|
export function toApiAttachment(
|
|
23
52
|
media: Media,
|
|
24
53
|
r2PublicUrl?: string,
|
|
@@ -84,9 +113,10 @@ export function toApiAttachment(
|
|
|
84
113
|
export function toApiPost(
|
|
85
114
|
post: Post,
|
|
86
115
|
extras: {
|
|
116
|
+
threadPostCount: number;
|
|
87
117
|
attachments?: ReturnType<typeof toApiAttachment>[];
|
|
88
118
|
collectionIds?: string[];
|
|
89
|
-
}
|
|
119
|
+
},
|
|
90
120
|
): ApiPostResponse {
|
|
91
121
|
const { title, url, ...rest } = post;
|
|
92
122
|
// A short name for this Post wherever it is referenced from somewhere else —
|
|
@@ -111,3 +141,81 @@ export function toApiPost(
|
|
|
111
141
|
url: url ?? null,
|
|
112
142
|
};
|
|
113
143
|
}
|
|
144
|
+
|
|
145
|
+
/** What {@link loadApiPostResponses} reads through. */
|
|
146
|
+
export interface ApiPostResponseDeps {
|
|
147
|
+
services: Pick<Services, "media" | "posts" | "collections">;
|
|
148
|
+
appConfig: AppConfig;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* API responses for Posts already loaded. Attachments, Thread Post counts,
|
|
153
|
+
* and (when asked) Thread collections are each read in one batch for the
|
|
154
|
+
* whole set, so a page costs the same few round trips however long it is.
|
|
155
|
+
*
|
|
156
|
+
* @param deps - Services and app config; a request's `c.var` or an MCP context
|
|
157
|
+
* @param posts - Posts to respond with, in order
|
|
158
|
+
* @param options - `collectionIds` adds each Post's shared Thread collections
|
|
159
|
+
* @returns One response per Post, in the same order
|
|
160
|
+
* @example
|
|
161
|
+
* const responses = await loadApiPostResponses(c.var, page.posts);
|
|
162
|
+
*/
|
|
163
|
+
export async function loadApiPostResponses(
|
|
164
|
+
deps: ApiPostResponseDeps,
|
|
165
|
+
posts: Post[],
|
|
166
|
+
options: { collectionIds?: boolean } = {},
|
|
167
|
+
): Promise<ApiPostResponse[]> {
|
|
168
|
+
if (posts.length === 0) return [];
|
|
169
|
+
const { services, appConfig } = deps;
|
|
170
|
+
const postIds = posts.map((post) => post.id);
|
|
171
|
+
const [mediaMap, threadPostCounts, collectionsMap] = await Promise.all([
|
|
172
|
+
services.media.getByPostIds(postIds),
|
|
173
|
+
services.posts.countThreadPosts(posts.map((post) => post.threadId)),
|
|
174
|
+
options.collectionIds
|
|
175
|
+
? services.collections.getCollectionsByPostIds(postIds)
|
|
176
|
+
: Promise.resolve(null),
|
|
177
|
+
]);
|
|
178
|
+
|
|
179
|
+
return posts.map((post) =>
|
|
180
|
+
toApiPost(post, {
|
|
181
|
+
threadPostCount: threadPostCounts.get(post.threadId) ?? 0,
|
|
182
|
+
attachments: (mediaMap.get(post.id) ?? []).map((media) =>
|
|
183
|
+
toApiAttachment(
|
|
184
|
+
media,
|
|
185
|
+
appConfig.r2PublicUrl,
|
|
186
|
+
appConfig.imageTransformUrl,
|
|
187
|
+
appConfig.s3PublicUrl,
|
|
188
|
+
appConfig.localPublicUrl,
|
|
189
|
+
appConfig.sitePathPrefix,
|
|
190
|
+
),
|
|
191
|
+
),
|
|
192
|
+
...(collectionsMap
|
|
193
|
+
? {
|
|
194
|
+
collectionIds: (collectionsMap.get(post.id) ?? []).map(
|
|
195
|
+
(collection) => collection.id,
|
|
196
|
+
),
|
|
197
|
+
}
|
|
198
|
+
: {}),
|
|
199
|
+
}),
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* One Post's API response. See {@link loadApiPostResponses}.
|
|
205
|
+
*
|
|
206
|
+
* @param deps - Services and app config
|
|
207
|
+
* @param post - The Post
|
|
208
|
+
* @param options - `collectionIds` adds the Post's shared Thread collections
|
|
209
|
+
* @returns The Post's response
|
|
210
|
+
* @example
|
|
211
|
+
* return c.json(await loadApiPostResponse(c.var, post));
|
|
212
|
+
*/
|
|
213
|
+
export async function loadApiPostResponse(
|
|
214
|
+
deps: ApiPostResponseDeps,
|
|
215
|
+
post: Post,
|
|
216
|
+
options: { collectionIds?: boolean } = {},
|
|
217
|
+
): Promise<ApiPostResponse> {
|
|
218
|
+
const [response] = await loadApiPostResponses(deps, [post], options);
|
|
219
|
+
if (!response) throw new Error(`No response built for post ${post.id}`);
|
|
220
|
+
return response;
|
|
221
|
+
}
|