@kidecms/core 0.25.1 → 0.26.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/internals/mcp.ts CHANGED
@@ -199,7 +199,7 @@ server.registerTool(
199
199
  {
200
200
  title: "List documents",
201
201
  description:
202
- "List documents in a collection with optional filters, search, sort, locale, status, limit, and offset.",
202
+ "List documents in a collection with optional filters, search, sort, locale, status, limit, and offset. With locale, availability 'exact' lists only documents that exist in that locale (their _sourceLocale or a translation); the default 'fallback' lists every document.",
203
203
  inputSchema: {
204
204
  collection: z.string().min(1),
205
205
  where: jsonObjectSchema.optional(),
@@ -209,6 +209,7 @@ server.registerTool(
209
209
  offset: z.number().int().min(0).default(0),
210
210
  status: statusSchema.optional(),
211
211
  locale: z.string().min(1).optional(),
212
+ availability: z.enum(["fallback", "exact"]).optional(),
212
213
  },
213
214
  },
214
215
  async (args) => toResult(await workerCall("listDocuments", args)),
@@ -225,6 +226,7 @@ server.registerTool(
225
226
  search: z.string().optional(),
226
227
  status: statusSchema.optional(),
227
228
  locale: z.string().min(1).optional(),
229
+ availability: z.enum(["fallback", "exact"]).optional(),
228
230
  },
229
231
  },
230
232
  async (args) => toResult(await workerCall("countDocuments", args)),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kidecms/core",
3
- "version": "0.25.1",
3
+ "version": "0.26.1",
4
4
  "description": "Kide CMS runtime — core library, admin UI, routes, and middleware for Astro. Shipped as TypeScript source.",
5
5
  "keywords": [
6
6
  "cms",
@@ -90,7 +90,7 @@ const extractDataFromForm = async (request: Request) => {
90
90
  data: Object.fromEntries(
91
91
  entries.filter(
92
92
  ([key]) =>
93
- (!key.startsWith("_") || key === "_publishAt" || key === "_unpublishAt") &&
93
+ (!key.startsWith("_") || key === "_publishAt" || key === "_unpublishAt" || key === "_sourceLocale") &&
94
94
  key !== "redirectTo" &&
95
95
  key !== "locale" &&
96
96
  key !== "version",
@@ -74,6 +74,9 @@ export const GET: APIRoute = async ({ url, locals }) => {
74
74
  (c) => requested.includes(c.slug) && !HIDDEN_FROM_SEARCH.has(c.slug),
75
75
  );
76
76
  const results: SearchResult[] = [];
77
+ // Pickers say so when the list is cut off, so 20 rows don't read as "all
78
+ // there is" — one extra row tells us without a count query.
79
+ let hasMore = false;
77
80
 
78
81
  for (const collection of collections) {
79
82
  const api = cmsAny[collection.slug];
@@ -92,15 +95,20 @@ export const GET: APIRoute = async ({ url, locals }) => {
92
95
  // Recently-updated first in both modes — without a sort, LIMIT keeps an
93
96
  // arbitrary subset of the matches.
94
97
  const sort = { field: "_updatedAt", direction: "desc" } as const;
95
- if (q.length >= MIN_QUERY_LENGTH) return api.find({ search: q, status: "any", sort, limit }, context);
96
- return api.find({ status: "any", sort, limit }, context);
98
+ const probe = limit + 1;
99
+ const found =
100
+ q.length >= MIN_QUERY_LENGTH
101
+ ? await api.find({ search: q, status: "any", sort, limit: probe }, context)
102
+ : await api.find({ status: "any", sort, limit: probe }, context);
103
+ if (found.length > limit) hasMore = true;
104
+ return found.slice(0, limit);
97
105
  })().catch(() => null);
98
106
 
99
107
  if (!docs) continue;
100
108
  for (const doc of docs) results.push(toResult(collection, doc));
101
109
  }
102
110
 
103
- return Response.json({ results });
111
+ return Response.json({ results, hasMore });
104
112
  }
105
113
 
106
114
  // Palette mode: everything, a few hits per collection.
@@ -0,0 +1,51 @@
1
+ ---
2
+ // Live-preview render endpoint: the preview tab POSTs unsaved rich text /
3
+ // blocks / content JSON and swaps the returned HTML into `[data-cms]` slots.
4
+ //
5
+ // A page partial rather than an API route on purpose: rendering Astro
6
+ // components from an endpoint needs the Container API, which leans on Vite
7
+ // internals and doesn't bundle for production (Cloudflare Workers in
8
+ // particular). A partial is an ordinary on-demand page — no doctype, no
9
+ // layout, just the component's HTML — so it works identically in dev and in
10
+ // every adapter's production build.
11
+ import BlockRenderer from "virtual:kide/block-renderer";
12
+ import ContentRenderer from "virtual:kide/content-renderer";
13
+ import { parseBlocks, renderRichText } from "../../../core";
14
+
15
+ export const prerender = false;
16
+ export const partial = true;
17
+
18
+ if (Astro.request.method !== "POST") {
19
+ return new Response(null, { status: 405, headers: { Allow: "POST" } });
20
+ }
21
+
22
+ let type: unknown;
23
+ let data: unknown;
24
+ try {
25
+ ({ type, data } = await Astro.request.json());
26
+ } catch {
27
+ return new Response("Invalid JSON body", { status: 400 });
28
+ }
29
+
30
+ // Editors send rich text / content documents either as objects or as the
31
+ // serialized form-field string; blocks arrive serialized and parseBlocks
32
+ // handles both.
33
+ let parsed: unknown = data;
34
+ if ((type === "content" || type === "richText") && typeof data === "string") {
35
+ try {
36
+ parsed = JSON.parse(data);
37
+ } catch {
38
+ return new Response("Invalid document JSON", { status: 400 });
39
+ }
40
+ }
41
+
42
+ if (type !== "blocks" && type !== "content" && type !== "richText") {
43
+ return new Response("Unknown preview type", { status: 400 });
44
+ }
45
+
46
+ Astro.response.headers.set("Cache-Control", "no-store");
47
+ ---
48
+
49
+ {type === "blocks" && <BlockRenderer blocks={parseBlocks(data)} status="any" />}
50
+ {type === "content" && <ContentRenderer content={parsed as any} status="any" />}
51
+ {type === "richText" && <Fragment set:html={renderRichText(parsed as any) ?? ""} />}
@@ -1,41 +0,0 @@
1
- import type { APIRoute } from "astro";
2
- import { experimental_AstroContainer as AstroContainer } from "astro/container";
3
- import { loadRenderers } from "astro:container";
4
- import { getContainerRenderer } from "@astrojs/react/container-renderer";
5
-
6
- import BlockRenderer from "virtual:kide/block-renderer";
7
- import ContentRenderer from "virtual:kide/content-renderer";
8
- import { renderRichText, parseBlocks } from "../../../core";
9
-
10
- export const prerender = false;
11
-
12
- let containerPromise: Promise<AstroContainer> | null = null;
13
- const getContainer = () => {
14
- if (!containerPromise) {
15
- containerPromise = (async () => {
16
- const renderers = await loadRenderers([getContainerRenderer()]);
17
- return AstroContainer.create({ renderers });
18
- })();
19
- }
20
- return containerPromise;
21
- };
22
-
23
- export const POST: APIRoute = async ({ request }) => {
24
- const { type, data } = await request.json();
25
-
26
- let html = "";
27
- if (type === "blocks") {
28
- const blocks = parseBlocks(data);
29
- const container = await getContainer();
30
- html = await container.renderToString(BlockRenderer, { props: { blocks, status: "any" } });
31
- } else if (type === "content") {
32
- const parsed = typeof data === "string" ? JSON.parse(data) : data;
33
- const container = await getContainer();
34
- html = await container.renderToString(ContentRenderer, { props: { content: parsed, status: "any" } });
35
- } else if (type === "richText") {
36
- const parsed = typeof data === "string" ? JSON.parse(data) : data;
37
- html = renderRichText(parsed) ?? "";
38
- }
39
-
40
- return new Response(html, { headers: { "Content-Type": "text/html" } });
41
- };