@jant/core 0.8.0 → 0.8.1
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--uxnaIRV.js} +427 -245
- package/dist/client/.vite/manifest.json +2 -2
- package/dist/client/_assets/{client-DTLBOHqD.js → client-BT6kpcuG.js} +1 -1
- package/dist/client/_assets/{client-auth-D6Ix6SmE.js → client-auth-begiT1tq.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 +52 -0
- package/src/__tests__/release-fixtures.test.ts +6 -2
- package/src/lib/__tests__/post-list-cursor.test.ts +105 -0
- package/src/lib/__tests__/timeline.test.ts +14 -14
- package/src/lib/post-list-cursor.ts +211 -0
- package/src/routes/api/__tests__/mcp.test.ts +58 -0
- package/src/routes/api/__tests__/posts.test.ts +79 -0
- package/src/routes/api/posts.ts +5 -9
- 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/archive.ts +18 -16
- package/src/routes/api/public/posts.ts +15 -16
- package/src/services/__tests__/post.test.ts +342 -36
- package/src/services/mcp.ts +6 -11
- package/src/services/post.ts +513 -319
- package/src/ui/shared/Pagination.tsx +1 -1
|
@@ -95,20 +95,23 @@ publicArchiveApiRoutes.get("/", async (c) => {
|
|
|
95
95
|
throw new ValidationError(INVALID_VISIBILITY_MESSAGE);
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
const posts = await c.var.services.posts.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
98
|
+
const { posts, nextCursor } = await c.var.services.posts.listPage(
|
|
99
|
+
{
|
|
100
|
+
lang,
|
|
101
|
+
status: "published",
|
|
102
|
+
excludePrivate: true,
|
|
103
|
+
excludeLatestHidden: false,
|
|
104
|
+
excludeReplies: true,
|
|
105
|
+
// Newest-published-first, the page's default order. Named explicitly:
|
|
106
|
+
// left unset, a published list sorts by activity, and a reply would
|
|
107
|
+
// lift an old root to the top. The year filter reads the same column,
|
|
108
|
+
// and so does the cursor.
|
|
109
|
+
...toPostFilters(parsed.selection, { yearAxis: "published" }),
|
|
110
|
+
sortBy: "published",
|
|
111
|
+
ignorePinnedSort: true,
|
|
112
|
+
},
|
|
113
|
+
{ cursor, limit },
|
|
114
|
+
);
|
|
112
115
|
|
|
113
116
|
const postIds = posts.map((post) => post.id);
|
|
114
117
|
const [mediaMap, collectionsMap] = await Promise.all([
|
|
@@ -126,7 +129,6 @@ publicArchiveApiRoutes.get("/", async (c) => {
|
|
|
126
129
|
{ content },
|
|
127
130
|
),
|
|
128
131
|
),
|
|
129
|
-
nextCursor
|
|
130
|
-
posts.length === limit ? (posts[posts.length - 1]?.id ?? null) : null,
|
|
132
|
+
nextCursor,
|
|
131
133
|
});
|
|
132
134
|
});
|
|
@@ -292,8 +292,8 @@ publicPostsApiRoutes.get("/", async (c) => {
|
|
|
292
292
|
sortOrder = resolveCollectionSortOrder(sort, defaultSort, showRatingSort);
|
|
293
293
|
}
|
|
294
294
|
|
|
295
|
-
const posts = collectionIds
|
|
296
|
-
? await c.var.services.posts.
|
|
295
|
+
const { posts, nextCursor } = collectionIds
|
|
296
|
+
? await c.var.services.posts.listCollectionThreadRootPage(
|
|
297
297
|
collectionIds,
|
|
298
298
|
{
|
|
299
299
|
status: "published",
|
|
@@ -302,20 +302,20 @@ publicPostsApiRoutes.get("/", async (c) => {
|
|
|
302
302
|
rootFormat: format,
|
|
303
303
|
lang,
|
|
304
304
|
sortOrder,
|
|
305
|
-
cursor: cursor ?? undefined,
|
|
306
|
-
limit,
|
|
307
305
|
},
|
|
306
|
+
{ cursor, limit },
|
|
308
307
|
)
|
|
309
|
-
: await c.var.services.posts.
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
308
|
+
: await c.var.services.posts.listPage(
|
|
309
|
+
{
|
|
310
|
+
format,
|
|
311
|
+
lang,
|
|
312
|
+
status: "published",
|
|
313
|
+
excludePrivate: true,
|
|
314
|
+
excludeLatestHidden: true,
|
|
315
|
+
excludeReplies: true,
|
|
316
|
+
},
|
|
317
|
+
{ cursor, limit },
|
|
318
|
+
);
|
|
319
319
|
|
|
320
320
|
const postIds = posts.map((post) => post.id);
|
|
321
321
|
const [mediaMap, collectionsMap] = await Promise.all([
|
|
@@ -333,8 +333,7 @@ publicPostsApiRoutes.get("/", async (c) => {
|
|
|
333
333
|
{ content },
|
|
334
334
|
),
|
|
335
335
|
),
|
|
336
|
-
nextCursor
|
|
337
|
-
posts.length === limit ? (posts[posts.length - 1]?.id ?? null) : null,
|
|
336
|
+
nextCursor,
|
|
338
337
|
});
|
|
339
338
|
});
|
|
340
339
|
|
|
@@ -683,13 +683,17 @@ describe("PostService", () => {
|
|
|
683
683
|
]);
|
|
684
684
|
|
|
685
685
|
// The keyset cursor reads the same keys or pagination skips rows.
|
|
686
|
+
const first = await postService.listPage(
|
|
687
|
+
{ sortOrder: "newest" },
|
|
688
|
+
{ limit: 1 },
|
|
689
|
+
);
|
|
686
690
|
expect(
|
|
687
691
|
(
|
|
688
|
-
await postService.
|
|
689
|
-
sortOrder: "newest",
|
|
690
|
-
cursor:
|
|
691
|
-
|
|
692
|
-
).map((post) => post.bodyText),
|
|
692
|
+
await postService.listPage(
|
|
693
|
+
{ sortOrder: "newest" },
|
|
694
|
+
{ cursor: first.nextCursor ?? undefined, limit: 10 },
|
|
695
|
+
)
|
|
696
|
+
).posts.map((post) => post.bodyText),
|
|
693
697
|
).toEqual(["middle, worst", "oldest, best"]);
|
|
694
698
|
});
|
|
695
699
|
|
|
@@ -858,20 +862,21 @@ describe("PostService", () => {
|
|
|
858
862
|
.set({ featuredAt: 7000 })
|
|
859
863
|
.where(eq(posts.id, newest.id));
|
|
860
864
|
|
|
861
|
-
const firstPage = await postService.
|
|
862
|
-
featured: true,
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
cursor: middle.id,
|
|
870
|
-
limit: 2,
|
|
871
|
-
});
|
|
865
|
+
const firstPage = await postService.listPage(
|
|
866
|
+
{ featured: true, ignorePinnedSort: true },
|
|
867
|
+
{ limit: 2 },
|
|
868
|
+
);
|
|
869
|
+
const secondPage = await postService.listPage(
|
|
870
|
+
{ featured: true, ignorePinnedSort: true },
|
|
871
|
+
{ cursor: firstPage.nextCursor ?? undefined, limit: 2 },
|
|
872
|
+
);
|
|
872
873
|
|
|
873
|
-
expect(firstPage.map((post) => post.id)).toEqual([
|
|
874
|
-
|
|
874
|
+
expect(firstPage.posts.map((post) => post.id)).toEqual([
|
|
875
|
+
newest.id,
|
|
876
|
+
middle.id,
|
|
877
|
+
]);
|
|
878
|
+
expect(secondPage.posts.map((post) => post.id)).toEqual([oldest.id]);
|
|
879
|
+
expect(secondPage.nextCursor).toBeNull();
|
|
875
880
|
});
|
|
876
881
|
|
|
877
882
|
it("excludes posts hidden from Latest when requested", async () => {
|
|
@@ -1032,24 +1037,6 @@ describe("PostService", () => {
|
|
|
1032
1037
|
expect(posts).toHaveLength(2);
|
|
1033
1038
|
});
|
|
1034
1039
|
|
|
1035
|
-
it("supports cursor pagination", async () => {
|
|
1036
|
-
const created = [];
|
|
1037
|
-
for (let i = 0; i < 5; i++) {
|
|
1038
|
-
created.push(
|
|
1039
|
-
await postService.create({
|
|
1040
|
-
format: "note",
|
|
1041
|
-
bodyMarkdown: `post ${i}`,
|
|
1042
|
-
publishedAt: 1000 + i,
|
|
1043
|
-
}),
|
|
1044
|
-
);
|
|
1045
|
-
}
|
|
1046
|
-
|
|
1047
|
-
// Get posts with ID less than the 3rd post
|
|
1048
|
-
const thirdPostId = created[2]?.id ?? 0;
|
|
1049
|
-
const posts = await postService.list({ cursor: thirdPostId });
|
|
1050
|
-
expect(posts.every((p) => p.id < thirdPostId)).toBe(true);
|
|
1051
|
-
});
|
|
1052
|
-
|
|
1053
1040
|
it("excludes replies when requested", async () => {
|
|
1054
1041
|
const root = await postService.create({
|
|
1055
1042
|
format: "note",
|
|
@@ -1136,6 +1123,325 @@ describe("PostService", () => {
|
|
|
1136
1123
|
});
|
|
1137
1124
|
});
|
|
1138
1125
|
|
|
1126
|
+
describe("listPage", () => {
|
|
1127
|
+
type PageFilters = Parameters<typeof postService.listPage>[0];
|
|
1128
|
+
|
|
1129
|
+
/** Every page of a walk, one request per page, until `nextCursor` is null. */
|
|
1130
|
+
async function walk(filters: PageFilters, limit: number) {
|
|
1131
|
+
const ids: string[] = [];
|
|
1132
|
+
let cursor: string | undefined;
|
|
1133
|
+
// A walk that never ends is a failure too; bound it by the corpus size.
|
|
1134
|
+
for (let page = 0; page < 100; page++) {
|
|
1135
|
+
const result = await postService.listPage(filters, { cursor, limit });
|
|
1136
|
+
ids.push(...result.posts.map((post) => post.id));
|
|
1137
|
+
if (result.nextCursor === null) return ids;
|
|
1138
|
+
cursor = result.nextCursor;
|
|
1139
|
+
}
|
|
1140
|
+
throw new Error("The walk did not end");
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
async function publishSeries(count: number, from = 1000) {
|
|
1144
|
+
const created = [];
|
|
1145
|
+
for (let i = 0; i < count; i++) {
|
|
1146
|
+
created.push(
|
|
1147
|
+
await postService.create({
|
|
1148
|
+
format: "note",
|
|
1149
|
+
bodyMarkdown: `post ${i}`,
|
|
1150
|
+
publishedAt: from + i,
|
|
1151
|
+
}),
|
|
1152
|
+
);
|
|
1153
|
+
}
|
|
1154
|
+
return created;
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
/**
|
|
1158
|
+
* A corpus where every sort key has ties and NULLs, and the three time
|
|
1159
|
+
* axes disagree, so some page boundary lands on each case a wrong keyset
|
|
1160
|
+
* would get wrong.
|
|
1161
|
+
*/
|
|
1162
|
+
async function seedSortCorpus() {
|
|
1163
|
+
const at = 1_700_000_000;
|
|
1164
|
+
const note = (body: string, extra: Record<string, unknown> = {}) =>
|
|
1165
|
+
postService.create({ format: "note", bodyMarkdown: body, ...extra });
|
|
1166
|
+
|
|
1167
|
+
await note("pinned, older pin", {
|
|
1168
|
+
publishedAt: at + 10,
|
|
1169
|
+
pinnedAt: at + 500,
|
|
1170
|
+
rating: 3,
|
|
1171
|
+
});
|
|
1172
|
+
await note("pinned, newer pin", {
|
|
1173
|
+
publishedAt: at + 20,
|
|
1174
|
+
pinnedAt: at + 600,
|
|
1175
|
+
});
|
|
1176
|
+
await note("pinned, same pin and time", {
|
|
1177
|
+
publishedAt: at + 20,
|
|
1178
|
+
pinnedAt: at + 600,
|
|
1179
|
+
});
|
|
1180
|
+
await note("featured, rated 5", {
|
|
1181
|
+
publishedAt: at + 30,
|
|
1182
|
+
featuredAt: at + 700,
|
|
1183
|
+
rating: 5,
|
|
1184
|
+
});
|
|
1185
|
+
await note("featured, same time and rating", {
|
|
1186
|
+
publishedAt: at + 30,
|
|
1187
|
+
featuredAt: at + 710,
|
|
1188
|
+
rating: 5,
|
|
1189
|
+
});
|
|
1190
|
+
await note("featured, oldest", {
|
|
1191
|
+
publishedAt: at + 5,
|
|
1192
|
+
featuredAt: at + 720,
|
|
1193
|
+
});
|
|
1194
|
+
await note("same time, rated 2", { publishedAt: at + 40, rating: 2 });
|
|
1195
|
+
await note("same time, also rated 2", {
|
|
1196
|
+
publishedAt: at + 40,
|
|
1197
|
+
rating: 2,
|
|
1198
|
+
});
|
|
1199
|
+
await note("same time, unrated", { publishedAt: at + 40 });
|
|
1200
|
+
const announced = await note("old root, announced reply", {
|
|
1201
|
+
publishedAt: at + 1,
|
|
1202
|
+
rating: 4,
|
|
1203
|
+
});
|
|
1204
|
+
await note("announced reply", {
|
|
1205
|
+
replyToId: announced.id,
|
|
1206
|
+
publishedAt: at + 100,
|
|
1207
|
+
});
|
|
1208
|
+
const quiet = await note("old root, quiet reply", {
|
|
1209
|
+
publishedAt: at + 2,
|
|
1210
|
+
});
|
|
1211
|
+
await note("quiet reply", {
|
|
1212
|
+
replyToId: quiet.id,
|
|
1213
|
+
quietReply: true,
|
|
1214
|
+
publishedAt: at + 200,
|
|
1215
|
+
});
|
|
1216
|
+
await note("private", { publishedAt: at + 50, visibility: "private" });
|
|
1217
|
+
await note("hidden from Latest", {
|
|
1218
|
+
publishedAt: at + 60,
|
|
1219
|
+
visibility: "latest_hidden",
|
|
1220
|
+
});
|
|
1221
|
+
await note("draft one", { status: "draft" });
|
|
1222
|
+
await note("draft two", { status: "draft", rating: 1 });
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
const ORDERS = ["newest", "oldest", "rating_desc"] as const;
|
|
1226
|
+
const AXES = ["activity", "thread_updated", "published"] as const;
|
|
1227
|
+
const MODES: Array<{ name: string; filters: PageFilters }> = [
|
|
1228
|
+
...ORDERS.flatMap((sortOrder) =>
|
|
1229
|
+
AXES.flatMap((sortBy) =>
|
|
1230
|
+
[false, true].map((ignorePinnedSort) => ({
|
|
1231
|
+
name: `${sortOrder} by ${sortBy}, ${ignorePinnedSort ? "unpinned" : "pinned"}`,
|
|
1232
|
+
filters: { sortOrder, sortBy, ignorePinnedSort },
|
|
1233
|
+
})),
|
|
1234
|
+
),
|
|
1235
|
+
),
|
|
1236
|
+
{ name: "featured, pinned", filters: { featured: true } },
|
|
1237
|
+
{
|
|
1238
|
+
name: "featured, unpinned",
|
|
1239
|
+
filters: { featured: true, ignorePinnedSort: true },
|
|
1240
|
+
},
|
|
1241
|
+
];
|
|
1242
|
+
|
|
1243
|
+
// Walking page by page must return exactly the unpaged order: nothing
|
|
1244
|
+
// skipped, nothing repeated, at every page size. Drafts are in the set,
|
|
1245
|
+
// so the activity axis also covers its draft branch.
|
|
1246
|
+
it.each(MODES)("walks $name in list order", async ({ filters }) => {
|
|
1247
|
+
await seedSortCorpus();
|
|
1248
|
+
const expected = (
|
|
1249
|
+
await postService.list({ ...filters, limit: 1000 })
|
|
1250
|
+
).map((post) => post.id);
|
|
1251
|
+
expect(new Set(expected).size).toBe(expected.length);
|
|
1252
|
+
expect(expected.length).toBeGreaterThan(2);
|
|
1253
|
+
|
|
1254
|
+
for (const limit of [1, 2, 3, 7]) {
|
|
1255
|
+
expect(await walk(filters, limit)).toEqual(expected);
|
|
1256
|
+
}
|
|
1257
|
+
const published = { ...filters, status: "published" as const };
|
|
1258
|
+
const expectedPublished = (
|
|
1259
|
+
await postService.list({ ...published, limit: 1000 })
|
|
1260
|
+
).map((post) => post.id);
|
|
1261
|
+
expect(await walk(published, 2)).toEqual(expectedPublished);
|
|
1262
|
+
});
|
|
1263
|
+
|
|
1264
|
+
it("ends with a null cursor on a page that exactly fills", async () => {
|
|
1265
|
+
await publishSeries(4);
|
|
1266
|
+
|
|
1267
|
+
const first = await postService.listPage({}, { limit: 2 });
|
|
1268
|
+
expect(first.posts).toHaveLength(2);
|
|
1269
|
+
expect(first.nextCursor).not.toBeNull();
|
|
1270
|
+
|
|
1271
|
+
const second = await postService.listPage(
|
|
1272
|
+
{},
|
|
1273
|
+
{ cursor: first.nextCursor ?? undefined, limit: 2 },
|
|
1274
|
+
);
|
|
1275
|
+
expect(second.posts).toHaveLength(2);
|
|
1276
|
+
expect(second.nextCursor).toBeNull();
|
|
1277
|
+
});
|
|
1278
|
+
|
|
1279
|
+
it("keeps walking past a row it can't return", async () => {
|
|
1280
|
+
// Hydration drops a Post with no slug. The page it was on comes back
|
|
1281
|
+
// short; the walk must not read that as the end.
|
|
1282
|
+
const [oldest, middle, newest] = await publishSeries(3);
|
|
1283
|
+
sqlite
|
|
1284
|
+
.prepare("DELETE FROM path_registry WHERE post_id = ?")
|
|
1285
|
+
.run(middle?.id);
|
|
1286
|
+
|
|
1287
|
+
const first = await postService.listPage({}, { limit: 1 });
|
|
1288
|
+
expect(first.posts.map((post) => post.id)).toEqual([newest?.id]);
|
|
1289
|
+
const second = await postService.listPage(
|
|
1290
|
+
{},
|
|
1291
|
+
{ cursor: first.nextCursor ?? undefined, limit: 1 },
|
|
1292
|
+
);
|
|
1293
|
+
expect(second.posts).toEqual([]);
|
|
1294
|
+
expect(second.nextCursor).not.toBeNull();
|
|
1295
|
+
const third = await postService.listPage(
|
|
1296
|
+
{},
|
|
1297
|
+
{ cursor: second.nextCursor ?? undefined, limit: 1 },
|
|
1298
|
+
);
|
|
1299
|
+
expect(third.posts.map((post) => post.id)).toEqual([oldest?.id]);
|
|
1300
|
+
expect(third.nextCursor).toBeNull();
|
|
1301
|
+
});
|
|
1302
|
+
|
|
1303
|
+
it("continues after the post the cursor was taken on is deleted", async () => {
|
|
1304
|
+
const [oldest, middle, newest] = await publishSeries(3);
|
|
1305
|
+
|
|
1306
|
+
const first = await postService.listPage({}, { limit: 2 });
|
|
1307
|
+
expect(first.posts.map((post) => post.id)).toEqual([
|
|
1308
|
+
newest?.id,
|
|
1309
|
+
middle?.id,
|
|
1310
|
+
]);
|
|
1311
|
+
await postService.delete(middle?.id ?? "");
|
|
1312
|
+
|
|
1313
|
+
const second = await postService.listPage(
|
|
1314
|
+
{},
|
|
1315
|
+
{ cursor: first.nextCursor ?? undefined, limit: 2 },
|
|
1316
|
+
);
|
|
1317
|
+
expect(second.posts.map((post) => post.id)).toEqual([oldest?.id]);
|
|
1318
|
+
});
|
|
1319
|
+
|
|
1320
|
+
it("resumes from where the page ended when that post is re-dated", async () => {
|
|
1321
|
+
const [oldest, middle, newest] = await publishSeries(3);
|
|
1322
|
+
const filters = { sortBy: "published" as const };
|
|
1323
|
+
|
|
1324
|
+
const first = await postService.listPage(filters, { limit: 2 });
|
|
1325
|
+
expect(first.posts.map((post) => post.id)).toEqual([
|
|
1326
|
+
newest?.id,
|
|
1327
|
+
middle?.id,
|
|
1328
|
+
]);
|
|
1329
|
+
// Moved before `oldest`: a cursor that looked the post up would resume
|
|
1330
|
+
// from its new place and skip `oldest`; moved to the top, it would
|
|
1331
|
+
// return `newest` again.
|
|
1332
|
+
await postService.update(middle?.id ?? "", { publishedAt: 500 });
|
|
1333
|
+
|
|
1334
|
+
const second = await postService.listPage(filters, {
|
|
1335
|
+
cursor: first.nextCursor ?? undefined,
|
|
1336
|
+
limit: 2,
|
|
1337
|
+
});
|
|
1338
|
+
// `middle` comes round again because its own sort key changed, which
|
|
1339
|
+
// the guarantee leaves open. `oldest`, which stayed put, is not skipped.
|
|
1340
|
+
expect(second.posts.map((post) => post.id)).toEqual([
|
|
1341
|
+
oldest?.id,
|
|
1342
|
+
middle?.id,
|
|
1343
|
+
]);
|
|
1344
|
+
|
|
1345
|
+
await postService.update(middle?.id ?? "", { publishedAt: 5000 });
|
|
1346
|
+
const again = await postService.listPage(filters, {
|
|
1347
|
+
cursor: first.nextCursor ?? undefined,
|
|
1348
|
+
limit: 2,
|
|
1349
|
+
});
|
|
1350
|
+
expect(again.posts.map((post) => post.id)).toEqual([oldest?.id]);
|
|
1351
|
+
});
|
|
1352
|
+
|
|
1353
|
+
it("treats an empty cursor as the first page", async () => {
|
|
1354
|
+
await publishSeries(2);
|
|
1355
|
+
|
|
1356
|
+
const page = await postService.listPage({}, { cursor: "", limit: 5 });
|
|
1357
|
+
expect(page.posts).toHaveLength(2);
|
|
1358
|
+
});
|
|
1359
|
+
|
|
1360
|
+
it("resumes after a bare post ID, as earlier releases' cursors are", async () => {
|
|
1361
|
+
const created = await publishSeries(5);
|
|
1362
|
+
const third = created[2];
|
|
1363
|
+
|
|
1364
|
+
const page = await postService.listPage(
|
|
1365
|
+
{},
|
|
1366
|
+
{ cursor: third?.id, limit: 10 },
|
|
1367
|
+
);
|
|
1368
|
+
expect(page.posts.map((post) => post.id)).toEqual([
|
|
1369
|
+
created[1]?.id,
|
|
1370
|
+
created[0]?.id,
|
|
1371
|
+
]);
|
|
1372
|
+
});
|
|
1373
|
+
|
|
1374
|
+
it("rejects a bare post ID the caller can't see, whatever the reason", async () => {
|
|
1375
|
+
const [visible] = await publishSeries(1);
|
|
1376
|
+
const draft = await postService.create({
|
|
1377
|
+
format: "note",
|
|
1378
|
+
bodyMarkdown: "draft",
|
|
1379
|
+
status: "draft",
|
|
1380
|
+
});
|
|
1381
|
+
const hidden = await postService.create({
|
|
1382
|
+
format: "note",
|
|
1383
|
+
bodyMarkdown: "private",
|
|
1384
|
+
visibility: "private",
|
|
1385
|
+
});
|
|
1386
|
+
const deleted = await postService.create({
|
|
1387
|
+
format: "note",
|
|
1388
|
+
bodyMarkdown: "deleted",
|
|
1389
|
+
});
|
|
1390
|
+
await postService.delete(deleted.id);
|
|
1391
|
+
const publicFilters = {
|
|
1392
|
+
status: "published" as const,
|
|
1393
|
+
excludePrivate: true,
|
|
1394
|
+
};
|
|
1395
|
+
|
|
1396
|
+
const errors = [];
|
|
1397
|
+
for (const cursor of [draft.id, hidden.id, deleted.id]) {
|
|
1398
|
+
const error = await postService
|
|
1399
|
+
.listPage(publicFilters, { cursor, limit: 5 })
|
|
1400
|
+
.catch((caught: unknown) => caught);
|
|
1401
|
+
expect(error).toBeInstanceOf(ValidationError);
|
|
1402
|
+
errors.push((error as ValidationError).message);
|
|
1403
|
+
}
|
|
1404
|
+
// One message for all three, so the answer says nothing about the post.
|
|
1405
|
+
expect(new Set(errors).size).toBe(1);
|
|
1406
|
+
|
|
1407
|
+
// A post the caller can see still resumes.
|
|
1408
|
+
await expect(
|
|
1409
|
+
postService.listPage(publicFilters, { cursor: visible?.id, limit: 5 }),
|
|
1410
|
+
).resolves.toEqual({ posts: [], nextCursor: null });
|
|
1411
|
+
});
|
|
1412
|
+
|
|
1413
|
+
it("rejects a cursor taken in another sort mode", async () => {
|
|
1414
|
+
await publishSeries(3);
|
|
1415
|
+
const first = await postService.listPage(
|
|
1416
|
+
{ sortBy: "published" },
|
|
1417
|
+
{ limit: 1 },
|
|
1418
|
+
);
|
|
1419
|
+
|
|
1420
|
+
await expect(
|
|
1421
|
+
postService.listPage(
|
|
1422
|
+
{ sortBy: "activity" },
|
|
1423
|
+
{ cursor: first.nextCursor ?? undefined, limit: 1 },
|
|
1424
|
+
),
|
|
1425
|
+
).rejects.toThrow(/different order/);
|
|
1426
|
+
await expect(
|
|
1427
|
+
postService.listPage(
|
|
1428
|
+
{ sortBy: "published", ignorePinnedSort: true },
|
|
1429
|
+
{ cursor: first.nextCursor ?? undefined, limit: 1 },
|
|
1430
|
+
),
|
|
1431
|
+
).rejects.toThrow(/different order/);
|
|
1432
|
+
});
|
|
1433
|
+
|
|
1434
|
+
it("rejects a cursor it can't read", async () => {
|
|
1435
|
+
await publishSeries(1);
|
|
1436
|
+
|
|
1437
|
+
for (const cursor of ["not a cursor", "eyJ2IjoxfQ", "pst_nope"]) {
|
|
1438
|
+
await expect(
|
|
1439
|
+
postService.listPage({}, { cursor, limit: 1 }),
|
|
1440
|
+
).rejects.toBeInstanceOf(ValidationError);
|
|
1441
|
+
}
|
|
1442
|
+
});
|
|
1443
|
+
});
|
|
1444
|
+
|
|
1139
1445
|
describe("count", () => {
|
|
1140
1446
|
it("returns 0 when no posts exist", async () => {
|
|
1141
1447
|
const count = await postService.count();
|
package/src/services/mcp.ts
CHANGED
|
@@ -144,7 +144,7 @@ const mcpTools: McpToolDefinition[] = [
|
|
|
144
144
|
{
|
|
145
145
|
name: "jant_posts_list",
|
|
146
146
|
description:
|
|
147
|
-
"List posts, with optional format, status, cursor, and limit filters.",
|
|
147
|
+
"List posts, with optional format, status, cursor, and limit filters. Pass nextCursor back as cursor for the next page.",
|
|
148
148
|
inputSchema: {
|
|
149
149
|
type: "object",
|
|
150
150
|
properties: {
|
|
@@ -157,19 +157,14 @@ const mcpTools: McpToolDefinition[] = [
|
|
|
157
157
|
},
|
|
158
158
|
async execute(args, context) {
|
|
159
159
|
const input = ListPostsToolSchema.parse(args ?? {});
|
|
160
|
-
const posts = await context.services.posts.
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
status: input.status ?? "published",
|
|
165
|
-
});
|
|
160
|
+
const { posts, nextCursor } = await context.services.posts.listPage(
|
|
161
|
+
{ format: input.format, status: input.status ?? "published" },
|
|
162
|
+
{ cursor: input.cursor, limit: input.limit },
|
|
163
|
+
);
|
|
166
164
|
|
|
167
165
|
return {
|
|
168
166
|
posts: await serializePosts(posts, context),
|
|
169
|
-
nextCursor
|
|
170
|
-
posts.length === input.limit
|
|
171
|
-
? (posts[posts.length - 1]?.id ?? null)
|
|
172
|
-
: null,
|
|
167
|
+
nextCursor,
|
|
173
168
|
};
|
|
174
169
|
},
|
|
175
170
|
},
|