@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
|
@@ -5344,9 +5344,9 @@ function normalizeThemeColorForMeta(color) {
|
|
|
5344
5344
|
*
|
|
5345
5345
|
* The dev flag itself lives in `build-env.ts`, which client bundles can import
|
|
5346
5346
|
* without these Worker-only globals.
|
|
5347
|
-
*/ var CORE_VERSION = "0.8.
|
|
5348
|
-
var CLIENT_JS_FILE = "/_assets/client-
|
|
5349
|
-
var CLIENT_AUTH_JS_FILE = "/_assets/client-auth-
|
|
5347
|
+
*/ var CORE_VERSION = "0.8.1-e6cbb5ae6bfbb200";
|
|
5348
|
+
var CLIENT_JS_FILE = "/_assets/client-BT6kpcuG.js";
|
|
5349
|
+
var CLIENT_AUTH_JS_FILE = "/_assets/client-auth-begiT1tq.js";
|
|
5350
5350
|
var CLIENT_COMPOSE_PRELOAD = [
|
|
5351
5351
|
"/_assets/client-compose-D6rExKVK.js",
|
|
5352
5352
|
"/_assets/chunks/create-editor-B-m7X7S5.js",
|
|
@@ -5943,7 +5943,7 @@ var IconSprite = () => {
|
|
|
5943
5943
|
const authorStylesheetPath = resolvedClientBundle === "full" ? IS_VITE_DEV ? assetPath("/src/style-author.css") : toPublicAssetPath(CLIENT_AUTHOR_CSS_FILE, assetBasePath) : null;
|
|
5944
5944
|
const clientScriptPath = IS_VITE_DEV ? resolvedClientBundle === "full" ? assetPath("/src/client-auth.ts") : assetPath("/src/client.ts") : toPublicAssetPath(resolvedClientBundle === "full" ? CLIENT_AUTH_JS_FILE : CLIENT_JS_FILE, assetBasePath);
|
|
5945
5945
|
const composePreloadPaths = !IS_VITE_DEV && resolvedClientBundle === "full" ? CLIENT_COMPOSE_PRELOAD.map((file) => toPublicAssetPath(file, assetBasePath)) : [];
|
|
5946
|
-
const faviconAssetVersion = resolvedFaviconVersion || "0.8.
|
|
5946
|
+
const faviconAssetVersion = resolvedFaviconVersion || "0.8.1-e6cbb5ae6bfbb200";
|
|
5947
5947
|
const resolvedFaviconHref = faviconHref ?? (faviconAssetVersion ? toPublicPath(`/favicon.ico?v=${faviconAssetVersion}`, sitePathPrefix) : toPublicPath("/favicon.ico", sitePathPrefix));
|
|
5948
5948
|
const resolvedAppleTouchHref = appleTouchHref ?? (faviconAssetVersion ? toPublicPath(`/apple-touch-icon.png?v=${faviconAssetVersion}`, sitePathPrefix) : toPublicPath("/apple-touch-icon.png", sitePathPrefix));
|
|
5949
5949
|
const socialImageHref = resolvedSocialImagePath ? toAbsoluteAssetUrl(resolvedSocialImagePath, appConfig?.siteUrl || "", sitePathPrefix) : "";
|
|
@@ -36795,10 +36795,11 @@ var PostSlugQuerySchema = z.discriminatedUnion("mode", [z.object({
|
|
|
36795
36795
|
})]);
|
|
36796
36796
|
postsApiRoutes.get("/", requireAuthApi(), async (c) => {
|
|
36797
36797
|
const { format, status, cursor, limit } = parseValidated(ListPostsQuerySchema, c.req.query());
|
|
36798
|
-
const posts = await c.var.services.posts.
|
|
36798
|
+
const { posts, nextCursor } = await c.var.services.posts.listPage({
|
|
36799
36799
|
format,
|
|
36800
|
-
status: status ?? "published"
|
|
36801
|
-
|
|
36800
|
+
status: status ?? "published"
|
|
36801
|
+
}, {
|
|
36802
|
+
cursor,
|
|
36802
36803
|
limit
|
|
36803
36804
|
});
|
|
36804
36805
|
const postIds = posts.map((p) => p.id);
|
|
@@ -36806,7 +36807,7 @@ postsApiRoutes.get("/", requireAuthApi(), async (c) => {
|
|
|
36806
36807
|
const { r2PublicUrl, imageTransformUrl, s3PublicUrl, localPublicUrl, sitePathPrefix } = c.var.appConfig;
|
|
36807
36808
|
return c.json({
|
|
36808
36809
|
posts: posts.map((p) => toApiPost(p, { attachments: (mediaMap.get(p.id) ?? []).map((m) => toApiAttachment(m, r2PublicUrl, imageTransformUrl, s3PublicUrl, localPublicUrl, sitePathPrefix)) })),
|
|
36809
|
-
nextCursor
|
|
36810
|
+
nextCursor
|
|
36810
36811
|
});
|
|
36811
36812
|
});
|
|
36812
36813
|
postsApiRoutes.get("/slug", requireAuthApi(), async (c) => {
|
|
@@ -38193,7 +38194,7 @@ var RemoveCollectionThreadToolSchema = AddCollectionThreadToolSchema;
|
|
|
38193
38194
|
var mcpTools = [
|
|
38194
38195
|
{
|
|
38195
38196
|
name: "jant_posts_list",
|
|
38196
|
-
description: "List posts, with optional format, status, cursor, and limit filters.",
|
|
38197
|
+
description: "List posts, with optional format, status, cursor, and limit filters. Pass nextCursor back as cursor for the next page.",
|
|
38197
38198
|
inputSchema: {
|
|
38198
38199
|
type: "object",
|
|
38199
38200
|
properties: {
|
|
@@ -38217,15 +38218,16 @@ var mcpTools = [
|
|
|
38217
38218
|
},
|
|
38218
38219
|
async execute(args, context) {
|
|
38219
38220
|
const input = ListPostsToolSchema.parse(args ?? {});
|
|
38220
|
-
const posts = await context.services.posts.
|
|
38221
|
-
cursor: input.cursor ?? void 0,
|
|
38221
|
+
const { posts, nextCursor } = await context.services.posts.listPage({
|
|
38222
38222
|
format: input.format,
|
|
38223
|
-
limit: input.limit,
|
|
38224
38223
|
status: input.status ?? "published"
|
|
38224
|
+
}, {
|
|
38225
|
+
cursor: input.cursor,
|
|
38226
|
+
limit: input.limit
|
|
38225
38227
|
});
|
|
38226
38228
|
return {
|
|
38227
38229
|
posts: await serializePosts(posts, context),
|
|
38228
|
-
nextCursor
|
|
38230
|
+
nextCursor
|
|
38229
38231
|
};
|
|
38230
38232
|
}
|
|
38231
38233
|
},
|
|
@@ -41016,6 +41018,137 @@ internalApiTokensRoutes.post("/purge", requireInternalAdminApi(), async (c) => {
|
|
|
41016
41018
|
if (options.lang) conditions.push(sql`${post.language} = ${options.lang}`);
|
|
41017
41019
|
return conditions;
|
|
41018
41020
|
}
|
|
41021
|
+
//#endregion
|
|
41022
|
+
//#region src/lib/post-list-cursor.ts
|
|
41023
|
+
/**
|
|
41024
|
+
* The cursor `posts.listPage()` and `posts.listCollectionThreadRootPage()`
|
|
41025
|
+
* hand out as `nextCursor`.
|
|
41026
|
+
*
|
|
41027
|
+
* A cursor says where the previous page ended: the sort mode it was taken in
|
|
41028
|
+
* and the full sort-key tuple of that page's last row, key for key as the
|
|
41029
|
+
* ORDER BY reads them. Resuming is a pure keyset comparison against those
|
|
41030
|
+
* values, so the post the page ended on can be deleted, unpublished, or edited
|
|
41031
|
+
* before the next request without moving the position. The two lists name
|
|
41032
|
+
* their sort modes apart, so a cursor from one never resumes the other.
|
|
41033
|
+
*
|
|
41034
|
+
* Wire format: `base64url(JSON { v, s, k })` — format version, sort mode, and
|
|
41035
|
+
* key tuple. It is not signed. A caller who edits one can only move their own
|
|
41036
|
+
* position on an axis they may already read; the values are never looked up.
|
|
41037
|
+
* Filters stay out: a position on the sort axis is valid under any filter.
|
|
41038
|
+
*
|
|
41039
|
+
* Callers treat the string as opaque. The one other shape still accepted is
|
|
41040
|
+
* the bare post TypeID earlier releases returned; see
|
|
41041
|
+
* {@link isLegacyPostListCursor}.
|
|
41042
|
+
*/
|
|
41043
|
+
/** Bumped when the payload shape changes; older versions are rejected. */ var POST_LIST_CURSOR_VERSION = 1;
|
|
41044
|
+
/**
|
|
41045
|
+
* Longest encoded cursor accepted. The largest tuple (pinned, rating, time,
|
|
41046
|
+
* id) encodes to under 200 characters; the cap only keeps a hostile value from
|
|
41047
|
+
* reaching the decoder.
|
|
41048
|
+
*/ var MAX_ENCODED_LENGTH = 512;
|
|
41049
|
+
var BASE64URL_PATTERN = /^[A-Za-z0-9_-]+$/;
|
|
41050
|
+
var UNREADABLE_MESSAGE = "This cursor can't be read. Pass back nextCursor unchanged, or leave cursor out to start from the first page.";
|
|
41051
|
+
var VERSION_MESSAGE = "This cursor is from a different version of Jant. Leave cursor out to start from the first page.";
|
|
41052
|
+
var MODE_MESSAGE = "This cursor is from a list in a different order. Leave cursor out to start from the first page.";
|
|
41053
|
+
/**
|
|
41054
|
+
* A legacy cursor naming a Post that is gone, or that the caller can't see.
|
|
41055
|
+
* One message for both, so a cursor can't be used to probe for private Posts.
|
|
41056
|
+
*/ var MISSING_LEGACY_CURSOR_MESSAGE = "This cursor names a post that can't be found. Leave cursor out to start from the first page.";
|
|
41057
|
+
function encodeBase64Url(text) {
|
|
41058
|
+
return btoa(text).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
41059
|
+
}
|
|
41060
|
+
function decodeBase64Url(encoded) {
|
|
41061
|
+
const padded = encoded.replace(/-/g, "+").replace(/_/g, "/") + "===".slice((encoded.length + 3) % 4);
|
|
41062
|
+
try {
|
|
41063
|
+
return atob(padded);
|
|
41064
|
+
} catch {
|
|
41065
|
+
return null;
|
|
41066
|
+
}
|
|
41067
|
+
}
|
|
41068
|
+
function isPlainObject(value) {
|
|
41069
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
41070
|
+
}
|
|
41071
|
+
function matchesKind(value, kind) {
|
|
41072
|
+
return kind === "number" ? Number.isSafeInteger(value) : typeof value === "string" && isTypeId(value, ID_PREFIX.post);
|
|
41073
|
+
}
|
|
41074
|
+
/**
|
|
41075
|
+
* Encode the position after a page's last row.
|
|
41076
|
+
*
|
|
41077
|
+
* @param mode - The sort mode the page was read in
|
|
41078
|
+
* @param values - That row's sort-key tuple, in ORDER BY order
|
|
41079
|
+
* @returns The opaque cursor string
|
|
41080
|
+
* @example
|
|
41081
|
+
* ```ts
|
|
41082
|
+
* encodePostListCursor("newest:activity:pinned", [-1, 1706000000, post.id]);
|
|
41083
|
+
* ```
|
|
41084
|
+
*/ function encodePostListCursor(mode, values) {
|
|
41085
|
+
const payload = {
|
|
41086
|
+
v: POST_LIST_CURSOR_VERSION,
|
|
41087
|
+
s: mode,
|
|
41088
|
+
k: [...values]
|
|
41089
|
+
};
|
|
41090
|
+
return encodeBase64Url(JSON.stringify(payload));
|
|
41091
|
+
}
|
|
41092
|
+
/**
|
|
41093
|
+
* Decode a cursor for the current request, strictly.
|
|
41094
|
+
*
|
|
41095
|
+
* Nothing here falls back to the first page: a cursor that can't be read, that
|
|
41096
|
+
* an unknown format version wrote, that was taken in another sort mode, or
|
|
41097
|
+
* whose tuple doesn't fit the mode's keys is rejected, because answering with
|
|
41098
|
+
* page 1 would hand the caller posts it already has.
|
|
41099
|
+
*
|
|
41100
|
+
* @param raw - The `cursor` the caller sent
|
|
41101
|
+
* @param shape - The current request's sort mode and key kinds
|
|
41102
|
+
* @returns The key tuple, in ORDER BY order
|
|
41103
|
+
* @throws {ValidationError} When the cursor doesn't resume this request
|
|
41104
|
+
* @example
|
|
41105
|
+
* ```ts
|
|
41106
|
+
* const after = decodePostListCursor(cursor, {
|
|
41107
|
+
* mode: "newest:published:unpinned",
|
|
41108
|
+
* kinds: ["number", "id"],
|
|
41109
|
+
* });
|
|
41110
|
+
* ```
|
|
41111
|
+
*/ function decodePostListCursor(raw, shape) {
|
|
41112
|
+
if (raw.length > MAX_ENCODED_LENGTH || !BASE64URL_PATTERN.test(raw)) throw new ValidationError(UNREADABLE_MESSAGE);
|
|
41113
|
+
const text = decodeBase64Url(raw);
|
|
41114
|
+
if (text === null) throw new ValidationError(UNREADABLE_MESSAGE);
|
|
41115
|
+
let parsed;
|
|
41116
|
+
try {
|
|
41117
|
+
parsed = JSON.parse(text);
|
|
41118
|
+
} catch {
|
|
41119
|
+
throw new ValidationError(UNREADABLE_MESSAGE);
|
|
41120
|
+
}
|
|
41121
|
+
if (!isPlainObject(parsed) || !Number.isSafeInteger(parsed.v)) throw new ValidationError(UNREADABLE_MESSAGE);
|
|
41122
|
+
if (parsed.v !== POST_LIST_CURSOR_VERSION) throw new ValidationError(VERSION_MESSAGE);
|
|
41123
|
+
const { s: mode, k: values } = parsed;
|
|
41124
|
+
if (Object.keys(parsed).length !== 3 || typeof mode !== "string" || !Array.isArray(values)) throw new ValidationError(UNREADABLE_MESSAGE);
|
|
41125
|
+
if (mode !== shape.mode) throw new ValidationError(MODE_MESSAGE);
|
|
41126
|
+
if (values.length !== shape.kinds.length) throw new ValidationError(UNREADABLE_MESSAGE);
|
|
41127
|
+
const tuple = [];
|
|
41128
|
+
for (const [index, kind] of shape.kinds.entries()) {
|
|
41129
|
+
const value = values[index];
|
|
41130
|
+
if (!matchesKind(value, kind)) throw new ValidationError(UNREADABLE_MESSAGE);
|
|
41131
|
+
tuple.push(value);
|
|
41132
|
+
}
|
|
41133
|
+
return tuple;
|
|
41134
|
+
}
|
|
41135
|
+
/**
|
|
41136
|
+
* Whether a cursor is the bare post TypeID that releases before the opaque
|
|
41137
|
+
* format returned as `nextCursor`.
|
|
41138
|
+
*
|
|
41139
|
+
* Accepted indefinitely — a stored cursor, or one a client built from a post
|
|
41140
|
+
* ID, must keep resuming. An encoded cursor can never look like one: it opens
|
|
41141
|
+
* with the base64url of `{"`, never with `pst_`.
|
|
41142
|
+
*
|
|
41143
|
+
* @param raw - The `cursor` the caller sent
|
|
41144
|
+
* @returns Whether to resolve it as a post ID
|
|
41145
|
+
* @example
|
|
41146
|
+
* ```ts
|
|
41147
|
+
* isLegacyPostListCursor("pst_01jpyx3m7gw4w3h7m4bknq0v1d"); // => true
|
|
41148
|
+
* ```
|
|
41149
|
+
*/ function isLegacyPostListCursor(raw) {
|
|
41150
|
+
return isTypeId(raw, ID_PREFIX.post);
|
|
41151
|
+
}
|
|
41019
41152
|
/**
|
|
41020
41153
|
* Render canonical post JSON with a stable page-wide footnote namespace.
|
|
41021
41154
|
*
|
|
@@ -73374,25 +73507,112 @@ function createPostService(db, config, siteId, paths, databaseSchema = sqliteSch
|
|
|
73374
73507
|
}
|
|
73375
73508
|
return conditions;
|
|
73376
73509
|
}
|
|
73377
|
-
|
|
73378
|
-
|
|
73379
|
-
|
|
73380
|
-
|
|
73510
|
+
/**
|
|
73511
|
+
* How `list()` orders a set of filters.
|
|
73512
|
+
*
|
|
73513
|
+
* A Featured list runs newest-published-first whatever `sortOrder` and
|
|
73514
|
+
* `sortBy` say. It is that order and no variant of it, so a cursor moves
|
|
73515
|
+
* between a Featured list and any other newest-published one. Everything
|
|
73516
|
+
* else takes both from the filters, defaulting to newest by announced
|
|
73517
|
+
* activity.
|
|
73518
|
+
*/ function resolveListSort(filters) {
|
|
73519
|
+
const pinned = !filters.ignorePinnedSort;
|
|
73520
|
+
if (filters.featured) return {
|
|
73521
|
+
order: "newest",
|
|
73522
|
+
axis: "published",
|
|
73523
|
+
pinned
|
|
73524
|
+
};
|
|
73525
|
+
return {
|
|
73526
|
+
order: filters.sortOrder ?? "newest",
|
|
73527
|
+
axis: filters.sortBy ?? "activity",
|
|
73528
|
+
pinned
|
|
73529
|
+
};
|
|
73530
|
+
}
|
|
73531
|
+
/**
|
|
73532
|
+
* The sort mode a cursor records. Two requests share a mode exactly when
|
|
73533
|
+
* their ORDER BY reads the same keys in the same directions, so a position
|
|
73534
|
+
* taken in one resumes the other.
|
|
73535
|
+
*/ function listSortMode(sort) {
|
|
73536
|
+
return `${sort.order}:${sort.axis}:${sort.pinned ? "pinned" : "unpinned"}`;
|
|
73381
73537
|
}
|
|
73382
73538
|
/**
|
|
73383
|
-
*
|
|
73539
|
+
* Where a Post sits on one of `list()`'s time axes. See `PostFilters.sortBy`.
|
|
73384
73540
|
*
|
|
73385
|
-
*
|
|
73386
|
-
* the
|
|
73387
|
-
|
|
73388
|
-
|
|
73389
|
-
|
|
73390
|
-
|
|
73391
|
-
|
|
73392
|
-
|
|
73393
|
-
|
|
73394
|
-
|
|
73395
|
-
|
|
73541
|
+
* On the activity axis a draft, which has announced nothing, sits at its last
|
|
73542
|
+
* edit. When the status filter already settles which case applies, only
|
|
73543
|
+
* that column is read.
|
|
73544
|
+
*/ function listAxisExpr(axis, status) {
|
|
73545
|
+
switch (axis) {
|
|
73546
|
+
case "published": return sql`coalesce(${posts.publishedAt}, ${posts.createdAt})`;
|
|
73547
|
+
case "thread_updated": return sql`${posts.threadUpdatedAt}`;
|
|
73548
|
+
case "activity":
|
|
73549
|
+
if (status === "draft") return sql`${posts.updatedAt}`;
|
|
73550
|
+
if (status === "published") return sql`${posts.lastActivityAt}`;
|
|
73551
|
+
return sql`CASE
|
|
73552
|
+
WHEN ${posts.status} = 'draft' THEN ${posts.updatedAt}
|
|
73553
|
+
ELSE ${posts.lastActivityAt}
|
|
73554
|
+
END`;
|
|
73555
|
+
}
|
|
73556
|
+
}
|
|
73557
|
+
/**
|
|
73558
|
+
* `list()`'s sort keys, in ORDER BY order — the one definition of it.
|
|
73559
|
+
*
|
|
73560
|
+
* The ORDER BY, the keyset condition that resumes after a cursor, and the
|
|
73561
|
+
* values a cursor records are all built from this list, so they cannot read
|
|
73562
|
+
* different expressions. Two of them used to, and a page boundary then
|
|
73563
|
+
* skipped or repeated Posts.
|
|
73564
|
+
*
|
|
73565
|
+
* Every nullable key is wrapped in `coalesce(…, -1)`. SQLite sorts NULLs
|
|
73566
|
+
* last under DESC and Postgres sorts them first, and a keyset comparison
|
|
73567
|
+
* against NULL is never true on either; with the wrap both engines order,
|
|
73568
|
+
* compare, and return the same values. The Post ID ends every list, so no
|
|
73569
|
+
* two rows share a tuple.
|
|
73570
|
+
*/ function listSortKeys(sort, status) {
|
|
73571
|
+
const numberKey = (expr, direction) => ({
|
|
73572
|
+
expr: sql`coalesce(${expr}, -1)`.mapWith(Number),
|
|
73573
|
+
direction,
|
|
73574
|
+
kind: "number"
|
|
73575
|
+
});
|
|
73576
|
+
const idKey = (direction) => ({
|
|
73577
|
+
expr: sql`${posts.id}`,
|
|
73578
|
+
direction,
|
|
73579
|
+
kind: "id"
|
|
73580
|
+
});
|
|
73581
|
+
const pinnedKeys = sort.pinned ? [numberKey(sql`${posts.pinnedAt}`, "desc")] : [];
|
|
73582
|
+
const time = listAxisExpr(sort.axis, status);
|
|
73583
|
+
switch (sort.order) {
|
|
73584
|
+
case "oldest": return [
|
|
73585
|
+
...pinnedKeys,
|
|
73586
|
+
numberKey(time, "asc"),
|
|
73587
|
+
idKey("asc")
|
|
73588
|
+
];
|
|
73589
|
+
case "rating_desc": return [
|
|
73590
|
+
...pinnedKeys,
|
|
73591
|
+
numberKey(sql`${posts.rating}`, "desc"),
|
|
73592
|
+
numberKey(time, "desc"),
|
|
73593
|
+
idKey("desc")
|
|
73594
|
+
];
|
|
73595
|
+
case "newest": return [
|
|
73596
|
+
...pinnedKeys,
|
|
73597
|
+
numberKey(time, "desc"),
|
|
73598
|
+
idKey("desc")
|
|
73599
|
+
];
|
|
73600
|
+
}
|
|
73601
|
+
}
|
|
73602
|
+
function listOrderBy(keys) {
|
|
73603
|
+
return keys.map((key) => key.direction === "desc" ? desc(key.expr) : asc(key.expr));
|
|
73604
|
+
}
|
|
73605
|
+
/** The sort keys as select fields, `k0`, `k1`, …, in ORDER BY order. */ function listSortKeyFields(keys) {
|
|
73606
|
+
return Object.fromEntries(keys.map((key, index) => [`k${index}`, key.expr]));
|
|
73607
|
+
}
|
|
73608
|
+
/** Read back the tuple {@link listSortKeyFields} selected. */ function readListSortKeyValues(keys, fields) {
|
|
73609
|
+
return keys.map((key, index) => {
|
|
73610
|
+
const value = fields[`k${index}`];
|
|
73611
|
+
if (key.kind === "number") {
|
|
73612
|
+
if (typeof value === "number" && Number.isSafeInteger(value)) return value;
|
|
73613
|
+
} else if (typeof value === "string") return value;
|
|
73614
|
+
throw new Error(`Sort key ${index} read back as ${String(value)}`);
|
|
73615
|
+
});
|
|
73396
73616
|
}
|
|
73397
73617
|
function buildLexicographicCursorCondition(keys) {
|
|
73398
73618
|
const [first, ...rest] = keys;
|
|
@@ -73403,82 +73623,40 @@ function createPostService(db, config, siteId, paths, databaseSchema = sqliteSch
|
|
|
73403
73623
|
OR (${first.expr} = ${first.value} AND ${buildLexicographicCursorCondition(rest)})
|
|
73404
73624
|
)`;
|
|
73405
73625
|
}
|
|
73406
|
-
|
|
73407
|
-
|
|
73408
|
-
|
|
73409
|
-
|
|
73410
|
-
|
|
73411
|
-
|
|
73412
|
-
|
|
73413
|
-
|
|
73414
|
-
|
|
73415
|
-
|
|
73416
|
-
|
|
73417
|
-
|
|
73418
|
-
|
|
73419
|
-
|
|
73420
|
-
|
|
73421
|
-
|
|
73422
|
-
|
|
73423
|
-
|
|
73424
|
-
|
|
73425
|
-
|
|
73426
|
-
|
|
73427
|
-
|
|
73428
|
-
|
|
73429
|
-
|
|
73430
|
-
|
|
73431
|
-
|
|
73432
|
-
|
|
73433
|
-
|
|
73434
|
-
|
|
73435
|
-
|
|
73436
|
-
|
|
73437
|
-
|
|
73438
|
-
|
|
73439
|
-
|
|
73440
|
-
switch (filters.sortOrder ?? "newest") {
|
|
73441
|
-
case "oldest": return buildLexicographicCursorCondition(withPinnedSortKey([{
|
|
73442
|
-
direction: "asc",
|
|
73443
|
-
expr: sortTimestampSortExpr,
|
|
73444
|
-
value: cursorSortTimestamp
|
|
73445
|
-
}, {
|
|
73446
|
-
direction: "asc",
|
|
73447
|
-
expr: posts.id,
|
|
73448
|
-
value: cursorPost.id
|
|
73449
|
-
}]));
|
|
73450
|
-
case "rating_desc": return buildLexicographicCursorCondition(withPinnedSortKey([
|
|
73451
|
-
{
|
|
73452
|
-
direction: "desc",
|
|
73453
|
-
expr: ratingPresenceExpr,
|
|
73454
|
-
value: cursorRatingPresence
|
|
73455
|
-
},
|
|
73456
|
-
{
|
|
73457
|
-
direction: "desc",
|
|
73458
|
-
expr: ratingSortExpr,
|
|
73459
|
-
value: cursorRating
|
|
73460
|
-
},
|
|
73461
|
-
{
|
|
73462
|
-
direction: "desc",
|
|
73463
|
-
expr: sortTimestampSortExpr,
|
|
73464
|
-
value: cursorSortTimestamp
|
|
73465
|
-
},
|
|
73466
|
-
{
|
|
73467
|
-
direction: "desc",
|
|
73468
|
-
expr: posts.id,
|
|
73469
|
-
value: cursorPost.id
|
|
73470
|
-
}
|
|
73471
|
-
]));
|
|
73472
|
-
case "newest": return buildLexicographicCursorCondition(withPinnedSortKey([{
|
|
73473
|
-
direction: "desc",
|
|
73474
|
-
expr: sortTimestampSortExpr,
|
|
73475
|
-
value: cursorSortTimestamp
|
|
73476
|
-
}, {
|
|
73477
|
-
direction: "desc",
|
|
73478
|
-
expr: posts.id,
|
|
73479
|
-
value: cursorPost.id
|
|
73480
|
-
}]));
|
|
73481
|
-
}
|
|
73626
|
+
/** Rows strictly after `values` in the order `keys` describe. */ function buildListKeysetCondition(keys, values) {
|
|
73627
|
+
const [first, ...rest] = keys.map((key, index) => {
|
|
73628
|
+
const value = values[index];
|
|
73629
|
+
if (value === void 0) throw new Error(`Cursor holds no value for sort key ${index}`);
|
|
73630
|
+
return {
|
|
73631
|
+
direction: key.direction,
|
|
73632
|
+
expr: key.expr,
|
|
73633
|
+
value
|
|
73634
|
+
};
|
|
73635
|
+
});
|
|
73636
|
+
if (!first) throw new Error("A list has at least one sort key");
|
|
73637
|
+
return buildLexicographicCursorCondition([first, ...rest]);
|
|
73638
|
+
}
|
|
73639
|
+
/**
|
|
73640
|
+
* The position a cursor names, as the tuple of sort-key values after which
|
|
73641
|
+
* the page starts.
|
|
73642
|
+
*
|
|
73643
|
+
* A bare post ID, the cursor earlier releases returned, is looked up — but
|
|
73644
|
+
* only among Posts the caller could have been shown: the request's status,
|
|
73645
|
+
* and nothing private when the request excludes it. A deleted Post, a draft,
|
|
73646
|
+
* and a private Post all get the same rejection, so the lookup can't be used
|
|
73647
|
+
* to learn whether a Post exists or when it was published. Its values come
|
|
73648
|
+
* from the same key expressions as the ORDER BY.
|
|
73649
|
+
*/ async function resolveListCursor(cursor, sort, keys, filters) {
|
|
73650
|
+
if (!isLegacyPostListCursor(cursor)) return decodePostListCursor(cursor, {
|
|
73651
|
+
mode: listSortMode(sort),
|
|
73652
|
+
kinds: keys.map((key) => key.kind)
|
|
73653
|
+
});
|
|
73654
|
+
const row = (await db.select(listSortKeyFields(keys)).from(posts).where(and(eq(posts.siteId, siteId), eq(posts.id, cursor), ...buildReaderVisibilityConditions(posts, siteId, {
|
|
73655
|
+
status: filters.status,
|
|
73656
|
+
excludePrivate: filters.excludePrivate
|
|
73657
|
+
}))).limit(1))[0];
|
|
73658
|
+
if (!row) throw new ValidationError(MISSING_LEGACY_CURSOR_MESSAGE);
|
|
73659
|
+
return readListSortKeyValues(keys, row);
|
|
73482
73660
|
}
|
|
73483
73661
|
function toPost(row, slug, visibility) {
|
|
73484
73662
|
return {
|
|
@@ -73633,31 +73811,99 @@ function createPostService(db, config, siteId, paths, databaseSchema = sqliteSch
|
|
|
73633
73811
|
)
|
|
73634
73812
|
)`.as(alias);
|
|
73635
73813
|
}
|
|
73636
|
-
|
|
73814
|
+
/**
|
|
73815
|
+
* The sort mode a collection cursor records. Distinct from every
|
|
73816
|
+
* {@link listSortMode}: a collection orders Threads by its own pins, so a
|
|
73817
|
+
* position in `list()` never resumes a collection or the other way round.
|
|
73818
|
+
*/ function collectionThreadSortMode(order) {
|
|
73819
|
+
return `collection:${order}`;
|
|
73820
|
+
}
|
|
73821
|
+
/**
|
|
73822
|
+
* A collection's matching Threads, one row per Thread with its sort keys as
|
|
73823
|
+
* columns, those keys in ORDER BY order, and the sort mode a cursor taken
|
|
73824
|
+
* in that order records — the one definition of how a collection orders
|
|
73825
|
+
* its Threads. `options.sortOrder` defaults to `newest`.
|
|
73826
|
+
*
|
|
73827
|
+
* The keys are aggregates over the Thread's matching members, computed once
|
|
73828
|
+
* in the grouped subquery; the ORDER BY, the keyset condition that resumes
|
|
73829
|
+
* after a cursor, and the values a cursor records all read the subquery's
|
|
73830
|
+
* columns through `keys`. As in {@link listSortKeys}, no key is ever NULL,
|
|
73831
|
+
* so SQLite and Postgres order and compare alike: a missing pin, rating, or
|
|
73832
|
+
* publication time folds to -1, and Thread activity falls back to the
|
|
73833
|
+
* member's own times.
|
|
73834
|
+
*
|
|
73835
|
+
* - `newest`: pinned in the collection first, then Thread activity, newest
|
|
73836
|
+
* first.
|
|
73837
|
+
* - `oldest`: pinned first, then the Thread's first publication, oldest
|
|
73838
|
+
* first. A new reply doesn't move a Thread.
|
|
73839
|
+
* - `rating_desc`: pinned first, then the Thread's highest rating (unrated
|
|
73840
|
+
* last, since ratings run 1 to 5), then Thread activity.
|
|
73841
|
+
*
|
|
73842
|
+
* The Thread root ID ends every order, so no two rows share a tuple.
|
|
73843
|
+
*/ function buildCollectionThreadSort(collectionIds, options) {
|
|
73844
|
+
const order = options.sortOrder ?? "newest";
|
|
73637
73845
|
const conditions = [...buildThreadRootPageConditions(options), buildCollectionMembershipCondition(collectionIds)];
|
|
73638
|
-
const
|
|
73639
|
-
|
|
73640
|
-
|
|
73641
|
-
|
|
73642
|
-
|
|
73643
|
-
|
|
73644
|
-
|
|
73645
|
-
|
|
73646
|
-
|
|
73647
|
-
|
|
73648
|
-
|
|
73846
|
+
const sortedThreads = db.select({
|
|
73847
|
+
threadId: posts.threadId,
|
|
73848
|
+
collectionPinnedAt: sql`MAX(coalesce(${threadCollections.pinnedAt}, -1))`.as("collection_pinned_at"),
|
|
73849
|
+
firstPublishedAt: sql`coalesce(MIN(${posts.publishedAt}), -1)`.as("first_published_at"),
|
|
73850
|
+
threadActivityAt: buildCollectionThreadActivityExpr("thread_activity_at"),
|
|
73851
|
+
ratingValue: sql`MAX(coalesce(${posts.rating}, -1))`.as("rating_value")
|
|
73852
|
+
}).from(posts).innerJoin(threadCollections, and(eq(threadCollections.siteId, posts.siteId), eq(threadCollections.threadId, posts.threadId))).where(and(...conditions)).groupBy(posts.threadId).as("collection_thread_sort");
|
|
73853
|
+
const numberKey = (column, direction) => ({
|
|
73854
|
+
expr: sql`${column}`.mapWith(Number),
|
|
73855
|
+
direction,
|
|
73856
|
+
kind: "number"
|
|
73857
|
+
});
|
|
73858
|
+
const idKey = (direction) => ({
|
|
73859
|
+
expr: sql`${sortedThreads.threadId}`,
|
|
73860
|
+
direction,
|
|
73861
|
+
kind: "id"
|
|
73862
|
+
});
|
|
73863
|
+
const pinned = numberKey(sortedThreads.collectionPinnedAt, "desc");
|
|
73864
|
+
const activity = numberKey(sortedThreads.threadActivityAt, "desc");
|
|
73649
73865
|
return {
|
|
73650
|
-
|
|
73651
|
-
|
|
73652
|
-
|
|
73653
|
-
|
|
73654
|
-
|
|
73655
|
-
|
|
73656
|
-
|
|
73657
|
-
|
|
73658
|
-
|
|
73866
|
+
sortedThreads,
|
|
73867
|
+
keys: (() => {
|
|
73868
|
+
switch (order) {
|
|
73869
|
+
case "oldest": return [
|
|
73870
|
+
pinned,
|
|
73871
|
+
numberKey(sortedThreads.firstPublishedAt, "asc"),
|
|
73872
|
+
idKey("asc")
|
|
73873
|
+
];
|
|
73874
|
+
case "rating_desc": return [
|
|
73875
|
+
pinned,
|
|
73876
|
+
numberKey(sortedThreads.ratingValue, "desc"),
|
|
73877
|
+
activity,
|
|
73878
|
+
idKey("desc")
|
|
73879
|
+
];
|
|
73880
|
+
case "newest": return [
|
|
73881
|
+
pinned,
|
|
73882
|
+
activity,
|
|
73883
|
+
idKey("desc")
|
|
73884
|
+
];
|
|
73885
|
+
}
|
|
73886
|
+
})(),
|
|
73887
|
+
mode: collectionThreadSortMode(order)
|
|
73659
73888
|
};
|
|
73660
73889
|
}
|
|
73890
|
+
/**
|
|
73891
|
+
* The position a collection cursor names, as the tuple of sort-key values
|
|
73892
|
+
* after which the page starts.
|
|
73893
|
+
*
|
|
73894
|
+
* A bare root ID, the cursor earlier releases returned, is looked up in the
|
|
73895
|
+
* request's own `sortedThreads`, so only among Threads this request could
|
|
73896
|
+
* list. A Thread that is gone, private, a draft, or no longer in the
|
|
73897
|
+
* collection gets the same rejection as an ID that never existed.
|
|
73898
|
+
*/ async function resolveCollectionThreadCursor(cursor, sort) {
|
|
73899
|
+
if (!isLegacyPostListCursor(cursor)) return decodePostListCursor(cursor, {
|
|
73900
|
+
mode: sort.mode,
|
|
73901
|
+
kinds: sort.keys.map((key) => key.kind)
|
|
73902
|
+
});
|
|
73903
|
+
const row = (await db.select(listSortKeyFields(sort.keys)).from(sort.sortedThreads).where(eq(sort.sortedThreads.threadId, cursor)).limit(1))[0];
|
|
73904
|
+
if (!row) throw new ValidationError(MISSING_LEGACY_CURSOR_MESSAGE);
|
|
73905
|
+
return readListSortKeyValues(sort.keys, row);
|
|
73906
|
+
}
|
|
73661
73907
|
function isMediaAttachmentInput(attachment) {
|
|
73662
73908
|
return attachment.type === "media";
|
|
73663
73909
|
}
|
|
@@ -73789,52 +74035,29 @@ function createPostService(db, config, siteId, paths, databaseSchema = sqliteSch
|
|
|
73789
74035
|
return isSlugAvailableForPost(slug, excludePostId);
|
|
73790
74036
|
},
|
|
73791
74037
|
async list(filters = {}) {
|
|
74038
|
+
const keys = listSortKeys(resolveListSort(filters), filters.status);
|
|
73792
74039
|
const conditions = buildFilterConditions(filters);
|
|
73793
|
-
|
|
73794
|
-
if (filters.cursor && !cursorCondition) return [];
|
|
73795
|
-
const sortTimestamp = buildSortTimestampExpr(filters);
|
|
73796
|
-
if (cursorCondition) conditions.push(cursorCondition);
|
|
73797
|
-
const ratingPresence = sql`CASE
|
|
73798
|
-
WHEN ${posts.rating} IS NULL THEN 0
|
|
73799
|
-
ELSE 1
|
|
73800
|
-
END`;
|
|
73801
|
-
const pinnedSortExpr = sql`coalesce(${posts.pinnedAt}, -1)`;
|
|
73802
|
-
const featuredPublishedSortExpr = sql`coalesce(
|
|
73803
|
-
${posts.publishedAt}, ${posts.createdAt}, -1
|
|
73804
|
-
)`;
|
|
73805
|
-
const sortTimestampSortExpr = sql`coalesce(${sortTimestamp}, -1)`;
|
|
73806
|
-
const pinnedOrder = filters.ignorePinnedSort ? [] : [desc(pinnedSortExpr)];
|
|
73807
|
-
const baseQuery = db.select().from(posts).where(conditions.length > 0 ? and(...conditions) : void 0).limit(filters.limit ?? 100);
|
|
73808
|
-
const buildOrderBy = () => {
|
|
73809
|
-
if (filters.featured) return [
|
|
73810
|
-
...pinnedOrder,
|
|
73811
|
-
desc(featuredPublishedSortExpr),
|
|
73812
|
-
desc(posts.id)
|
|
73813
|
-
];
|
|
73814
|
-
switch (filters.sortOrder ?? "newest") {
|
|
73815
|
-
case "oldest": return [
|
|
73816
|
-
...pinnedOrder,
|
|
73817
|
-
asc(sortTimestampSortExpr),
|
|
73818
|
-
asc(posts.id)
|
|
73819
|
-
];
|
|
73820
|
-
case "rating_desc": return [
|
|
73821
|
-
...pinnedOrder,
|
|
73822
|
-
desc(ratingPresence),
|
|
73823
|
-
desc(posts.rating),
|
|
73824
|
-
desc(sortTimestampSortExpr),
|
|
73825
|
-
desc(posts.id)
|
|
73826
|
-
];
|
|
73827
|
-
case "newest": return [
|
|
73828
|
-
...pinnedOrder,
|
|
73829
|
-
desc(sortTimestampSortExpr),
|
|
73830
|
-
desc(posts.id)
|
|
73831
|
-
];
|
|
73832
|
-
}
|
|
73833
|
-
};
|
|
73834
|
-
let query = baseQuery.orderBy(...buildOrderBy());
|
|
74040
|
+
let query = db.select().from(posts).where(conditions.length > 0 ? and(...conditions) : void 0).orderBy(...listOrderBy(keys)).limit(filters.limit ?? 100);
|
|
73835
74041
|
if (filters.offset !== void 0) query = query.offset(filters.offset);
|
|
73836
74042
|
return hydratePosts(await query);
|
|
73837
74043
|
},
|
|
74044
|
+
async listPage(filters, { cursor, limit }) {
|
|
74045
|
+
const sort = resolveListSort(filters);
|
|
74046
|
+
const keys = listSortKeys(sort, filters.status);
|
|
74047
|
+
const conditions = buildFilterConditions(filters);
|
|
74048
|
+
if (cursor) conditions.push(buildListKeysetCondition(keys, await resolveListCursor(cursor, sort, keys, filters)));
|
|
74049
|
+
const rows = await db.select({
|
|
74050
|
+
post: posts,
|
|
74051
|
+
sortKey: listSortKeyFields(keys)
|
|
74052
|
+
}).from(posts).where(conditions.length > 0 ? and(...conditions) : void 0).orderBy(...listOrderBy(keys)).limit(limit + 1);
|
|
74053
|
+
const pageRows = rows.slice(0, limit);
|
|
74054
|
+
const lastRow = pageRows[pageRows.length - 1];
|
|
74055
|
+
const nextCursor = rows.length > limit && lastRow ? encodePostListCursor(listSortMode(sort), readListSortKeyValues(keys, lastRow.sortKey)) : null;
|
|
74056
|
+
return {
|
|
74057
|
+
posts: await hydratePosts(pageRows.map((row) => row.post)),
|
|
74058
|
+
nextCursor
|
|
74059
|
+
};
|
|
74060
|
+
},
|
|
73838
74061
|
async listForSitemap({ afterId, limit }) {
|
|
73839
74062
|
const conditions = buildFilterConditions({
|
|
73840
74063
|
status: "published",
|
|
@@ -74944,77 +75167,32 @@ function createPostService(db, config, siteId, paths, databaseSchema = sqliteSch
|
|
|
74944
75167
|
return this.listCollectionThreadRootIdsForCollections([collectionId], options);
|
|
74945
75168
|
},
|
|
74946
75169
|
async listCollectionThreadRootIdsForCollections(collectionIds, options = {}) {
|
|
74947
|
-
const {
|
|
74948
|
-
let
|
|
74949
|
-
if (options.cursor) {
|
|
74950
|
-
const cursorRow = (await db.select().from(sortedThreads).where(eq(sortedThreads.threadId, options.cursor)).limit(1))[0];
|
|
74951
|
-
if (!cursorRow) return [];
|
|
74952
|
-
const pinnedKey = {
|
|
74953
|
-
direction: "desc",
|
|
74954
|
-
expr: sortedThreads.collectionPinnedAt,
|
|
74955
|
-
value: cursorRow.collectionPinnedAt
|
|
74956
|
-
};
|
|
74957
|
-
cursorCondition = sortOrder === "oldest" ? buildLexicographicCursorCondition([
|
|
74958
|
-
pinnedKey,
|
|
74959
|
-
{
|
|
74960
|
-
direction: "asc",
|
|
74961
|
-
expr: sortedThreads.publishedAt,
|
|
74962
|
-
value: cursorRow.publishedAt
|
|
74963
|
-
},
|
|
74964
|
-
{
|
|
74965
|
-
direction: "asc",
|
|
74966
|
-
expr: sortedThreads.threadId,
|
|
74967
|
-
value: cursorRow.threadId
|
|
74968
|
-
}
|
|
74969
|
-
]) : sortOrder === "rating_desc" ? buildLexicographicCursorCondition([
|
|
74970
|
-
pinnedKey,
|
|
74971
|
-
{
|
|
74972
|
-
direction: "desc",
|
|
74973
|
-
expr: sortedThreads.ratingPresence,
|
|
74974
|
-
value: cursorRow.ratingPresence
|
|
74975
|
-
},
|
|
74976
|
-
{
|
|
74977
|
-
direction: "desc",
|
|
74978
|
-
expr: sortedThreads.ratingValue,
|
|
74979
|
-
value: cursorRow.ratingValue
|
|
74980
|
-
},
|
|
74981
|
-
{
|
|
74982
|
-
direction: "desc",
|
|
74983
|
-
expr: sortedThreads.threadActivityAt,
|
|
74984
|
-
value: cursorRow.threadActivityAt
|
|
74985
|
-
},
|
|
74986
|
-
{
|
|
74987
|
-
direction: "desc",
|
|
74988
|
-
expr: sortedThreads.threadId,
|
|
74989
|
-
value: cursorRow.threadId
|
|
74990
|
-
}
|
|
74991
|
-
]) : buildLexicographicCursorCondition([
|
|
74992
|
-
pinnedKey,
|
|
74993
|
-
{
|
|
74994
|
-
direction: "desc",
|
|
74995
|
-
expr: sortedThreads.threadActivityAt,
|
|
74996
|
-
value: cursorRow.threadActivityAt
|
|
74997
|
-
},
|
|
74998
|
-
{
|
|
74999
|
-
direction: "desc",
|
|
75000
|
-
expr: sortedThreads.threadId,
|
|
75001
|
-
value: cursorRow.threadId
|
|
75002
|
-
}
|
|
75003
|
-
]);
|
|
75004
|
-
}
|
|
75005
|
-
const baseQuery = db.select().from(sortedThreads).where(cursorCondition);
|
|
75006
|
-
let query = sortOrder === "oldest" ? baseQuery.orderBy(desc(sortedThreads.collectionPinnedAt), asc(sortedThreads.publishedAt), asc(sortedThreads.threadId)) : sortOrder === "rating_desc" ? baseQuery.orderBy(desc(sortedThreads.collectionPinnedAt), desc(sortedThreads.ratingPresence), desc(sortedThreads.ratingValue), desc(sortedThreads.threadActivityAt), desc(sortedThreads.threadId)) : baseQuery.orderBy(desc(sortedThreads.collectionPinnedAt), desc(sortedThreads.threadActivityAt), desc(sortedThreads.threadId));
|
|
75170
|
+
const { sortedThreads, keys } = buildCollectionThreadSort(collectionIds, options);
|
|
75171
|
+
let query = db.select({ threadId: sortedThreads.threadId }).from(sortedThreads).orderBy(...listOrderBy(keys));
|
|
75007
75172
|
if (options.limit !== void 0) query = query.limit(options.limit);
|
|
75008
75173
|
if (options.offset !== void 0) query = query.offset(options.offset);
|
|
75009
75174
|
return (await query).map((row) => row.threadId);
|
|
75010
75175
|
},
|
|
75011
|
-
async
|
|
75012
|
-
const
|
|
75176
|
+
async listCollectionThreadRootPage(collectionIds, options, { cursor, limit }) {
|
|
75177
|
+
const sort = buildCollectionThreadSort(collectionIds, options);
|
|
75178
|
+
const { sortedThreads, keys } = sort;
|
|
75179
|
+
const after = cursor ? buildListKeysetCondition(keys, await resolveCollectionThreadCursor(cursor, sort)) : void 0;
|
|
75180
|
+
const rows = await db.select({
|
|
75181
|
+
threadId: sortedThreads.threadId,
|
|
75182
|
+
sortKey: listSortKeyFields(keys)
|
|
75183
|
+
}).from(sortedThreads).where(after).orderBy(...listOrderBy(keys)).limit(limit + 1);
|
|
75184
|
+
const pageRows = rows.slice(0, limit);
|
|
75185
|
+
const lastRow = pageRows[pageRows.length - 1];
|
|
75186
|
+
const nextCursor = rows.length > limit && lastRow ? encodePostListCursor(sort.mode, readListSortKeyValues(keys, lastRow.sortKey)) : null;
|
|
75187
|
+
const rootIds = pageRows.map((row) => row.threadId);
|
|
75013
75188
|
const rootsById = await hydratePostsById(rootIds);
|
|
75014
|
-
return
|
|
75015
|
-
|
|
75016
|
-
|
|
75017
|
-
|
|
75189
|
+
return {
|
|
75190
|
+
posts: rootIds.flatMap((rootId) => {
|
|
75191
|
+
const root = rootsById.get(rootId);
|
|
75192
|
+
return root ? [root] : [];
|
|
75193
|
+
}),
|
|
75194
|
+
nextCursor
|
|
75195
|
+
};
|
|
75018
75196
|
},
|
|
75019
75197
|
async listCollectionFeedEntries(collectionId, options = {}) {
|
|
75020
75198
|
return this.listCollectionFeedEntriesForCollections([collectionId], options);
|
|
@@ -77102,30 +77280,32 @@ publicPostsApiRoutes.get("/", async (c) => {
|
|
|
77102
77280
|
}, 2));
|
|
77103
77281
|
sortOrder = resolveCollectionSortOrder(sort, resolveCollectionSortOrder(void 0, requestedDefaultSort, showRatingSort), showRatingSort);
|
|
77104
77282
|
}
|
|
77105
|
-
const posts = collectionIds ? await c.var.services.posts.
|
|
77283
|
+
const { posts, nextCursor } = collectionIds ? await c.var.services.posts.listCollectionThreadRootPage(collectionIds, {
|
|
77106
77284
|
status: "published",
|
|
77107
77285
|
excludePrivate: true,
|
|
77108
77286
|
excludeLatestHidden: true,
|
|
77109
77287
|
rootFormat: format,
|
|
77110
77288
|
lang,
|
|
77111
|
-
sortOrder
|
|
77112
|
-
|
|
77289
|
+
sortOrder
|
|
77290
|
+
}, {
|
|
77291
|
+
cursor,
|
|
77113
77292
|
limit
|
|
77114
|
-
}) : await c.var.services.posts.
|
|
77293
|
+
}) : await c.var.services.posts.listPage({
|
|
77115
77294
|
format,
|
|
77116
77295
|
lang,
|
|
77117
77296
|
status: "published",
|
|
77118
|
-
cursor: cursor ?? void 0,
|
|
77119
|
-
limit,
|
|
77120
77297
|
excludePrivate: true,
|
|
77121
77298
|
excludeLatestHidden: true,
|
|
77122
77299
|
excludeReplies: true
|
|
77300
|
+
}, {
|
|
77301
|
+
cursor,
|
|
77302
|
+
limit
|
|
77123
77303
|
});
|
|
77124
77304
|
const postIds = posts.map((post) => post.id);
|
|
77125
77305
|
const [mediaMap, collectionsMap] = await Promise.all([c.var.services.media.getByPostIds(postIds), c.var.services.collections.getCollectionsByPostIds(postIds)]);
|
|
77126
77306
|
return c.json({
|
|
77127
77307
|
posts: posts.map((post) => toPublicPost(post, mediaMap.get(post.id) ?? [], collectionsMap.get(post.id) ?? [], c.var.appConfig, { content })),
|
|
77128
|
-
nextCursor
|
|
77308
|
+
nextCursor
|
|
77129
77309
|
});
|
|
77130
77310
|
});
|
|
77131
77311
|
publicPostsApiRoutes.get("/:slug", async (c) => {
|
|
@@ -77174,22 +77354,24 @@ publicArchiveApiRoutes.get("/", async (c) => {
|
|
|
77174
77354
|
}
|
|
77175
77355
|
const visibility = parsed.selection.visibility;
|
|
77176
77356
|
if (visibility !== void 0 && !PUBLIC_ARCHIVE_VISIBILITIES.includes(visibility)) throw new ValidationError(INVALID_VISIBILITY_MESSAGE);
|
|
77177
|
-
const posts = await c.var.services.posts.
|
|
77357
|
+
const { posts, nextCursor } = await c.var.services.posts.listPage({
|
|
77178
77358
|
lang,
|
|
77179
77359
|
status: "published",
|
|
77180
|
-
cursor: cursor ?? void 0,
|
|
77181
|
-
limit,
|
|
77182
77360
|
excludePrivate: true,
|
|
77183
77361
|
excludeLatestHidden: false,
|
|
77184
77362
|
excludeReplies: true,
|
|
77185
77363
|
...toPostFilters(parsed.selection, { yearAxis: "published" }),
|
|
77364
|
+
sortBy: "published",
|
|
77186
77365
|
ignorePinnedSort: true
|
|
77366
|
+
}, {
|
|
77367
|
+
cursor,
|
|
77368
|
+
limit
|
|
77187
77369
|
});
|
|
77188
77370
|
const postIds = posts.map((post) => post.id);
|
|
77189
77371
|
const [mediaMap, collectionsMap] = await Promise.all([c.var.services.media.getByPostIds(postIds), c.var.services.collections.getCollectionsByPostIds(postIds)]);
|
|
77190
77372
|
return c.json({
|
|
77191
77373
|
posts: posts.map((post) => toPublicPost(post, mediaMap.get(post.id) ?? [], collectionsMap.get(post.id) ?? [], c.var.appConfig, { content })),
|
|
77192
|
-
nextCursor
|
|
77374
|
+
nextCursor
|
|
77193
77375
|
});
|
|
77194
77376
|
});
|
|
77195
77377
|
//#endregion
|