@caelo-cms/shared 0.11.8 → 0.11.9

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.
Files changed (58) hide show
  1. package/dist/ai-tools.d.ts +2 -2
  2. package/dist/build-page.d.ts +4 -4
  3. package/dist/change-journal.d.ts.map +1 -1
  4. package/dist/change-journal.js +1 -0
  5. package/dist/change-journal.js.map +1 -1
  6. package/dist/content.d.ts +6 -6
  7. package/dist/content.d.ts.map +1 -1
  8. package/dist/content.js +8 -1
  9. package/dist/content.js.map +1 -1
  10. package/dist/lists/fields.d.ts +6 -0
  11. package/dist/lists/fields.d.ts.map +1 -1
  12. package/dist/lists/fields.js +70 -7
  13. package/dist/lists/fields.js.map +1 -1
  14. package/dist/lists/index.d.ts +1 -0
  15. package/dist/lists/index.d.ts.map +1 -1
  16. package/dist/lists/index.js +1 -0
  17. package/dist/lists/index.js.map +1 -1
  18. package/dist/lists/list-type.d.ts +28 -6
  19. package/dist/lists/list-type.d.ts.map +1 -1
  20. package/dist/lists/list-type.js +43 -15
  21. package/dist/lists/list-type.js.map +1 -1
  22. package/dist/lists/overlay-scope.d.ts +68 -0
  23. package/dist/lists/overlay-scope.d.ts.map +1 -0
  24. package/dist/lists/overlay-scope.js +56 -0
  25. package/dist/lists/overlay-scope.js.map +1 -0
  26. package/dist/lists/query-merge.d.ts +27 -0
  27. package/dist/lists/query-merge.d.ts.map +1 -0
  28. package/dist/lists/query-merge.js +53 -0
  29. package/dist/lists/query-merge.js.map +1 -0
  30. package/dist/lists/resolve.d.ts +1 -0
  31. package/dist/lists/resolve.d.ts.map +1 -1
  32. package/dist/lists/resolve.js +11 -25
  33. package/dist/lists/resolve.js.map +1 -1
  34. package/dist/lists/scope.d.ts +4 -1
  35. package/dist/lists/scope.d.ts.map +1 -1
  36. package/dist/template-engine.d.ts.map +1 -1
  37. package/dist/template-engine.js +4 -1
  38. package/dist/template-engine.js.map +1 -1
  39. package/dist/version.d.ts +2 -2
  40. package/dist/version.js +1 -1
  41. package/package.json +1 -1
  42. package/src/change-journal.ts +1 -0
  43. package/src/content.test.ts +54 -0
  44. package/src/content.ts +10 -1
  45. package/src/lists/fields.ts +88 -7
  46. package/src/lists/index.ts +1 -0
  47. package/src/lists/list-type.ts +53 -18
  48. package/src/lists/lists.test.ts +70 -0
  49. package/src/lists/overlay-scope.test.ts +140 -0
  50. package/src/lists/overlay-scope.ts +120 -0
  51. package/src/lists/pagination.test.ts +15 -0
  52. package/src/lists/query-merge.ts +84 -0
  53. package/src/lists/resolve.test.ts +24 -4
  54. package/src/lists/resolve.ts +12 -33
  55. package/src/lists/scope.ts +4 -2
  56. package/src/template-engine-lists.test.ts +27 -1
  57. package/src/template-engine.ts +4 -1
  58. package/src/version.ts +1 -1
@@ -34,8 +34,6 @@ import {
34
34
  type ListTypeDef,
35
35
  type NodeDef,
36
36
  type PageQuery,
37
- pageQuerySchema,
38
- type QueryKnob,
39
37
  type SourceDef,
40
38
  type SystemSourceName,
41
39
  } from "./list-type.js";
@@ -49,6 +47,7 @@ import {
49
47
  pagedUrl,
50
48
  splitPaginationValue,
51
49
  } from "./pagination.js";
50
+ import { mergeQuerySource } from "./query-merge.js";
52
51
  import { parseListRef } from "./refs.js";
53
52
  import type {
54
53
  ListPageRecord,
@@ -107,7 +106,7 @@ export interface ListFieldSpec {
107
106
  /** Result of resolving one list field for one page. */
108
107
  export type ListFieldResolution =
109
108
  | { readonly ok: true; readonly entries: readonly ScopeEntry[] }
110
- | { readonly ok: false; readonly marker: string };
109
+ | { readonly ok: false; readonly marker: string; readonly detail?: string };
111
110
 
112
111
  /**
113
112
  * Where a local list is stored: the content instance holding the module
@@ -1098,29 +1097,6 @@ function createPageContext(
1098
1097
  );
1099
1098
  };
1100
1099
 
1101
- /** Merge a source's query defaults with the knobs an entry / placement may set. */
1102
- const mergedQuery = (
1103
- source: Extract<SourceDef, { kind: "query" }>,
1104
- overrides: unknown,
1105
- field: string,
1106
- path: string,
1107
- ): PageQuery | { marker: string } => {
1108
- const merged: Record<string, unknown> = { ...source.defaults };
1109
- if (overrides !== undefined && overrides !== null) {
1110
- if (typeof overrides !== "object" || Array.isArray(overrides)) {
1111
- return { marker: `list-malformed:${field}[${path}]` };
1112
- }
1113
- for (const [k, v] of Object.entries(overrides)) {
1114
- if (!(source.editable as readonly string[]).includes(k as QueryKnob)) {
1115
- return { marker: `list-malformed:${field}[${path}.${k}]` };
1116
- }
1117
- merged[k] = v;
1118
- }
1119
- }
1120
- const parsed = pageQuerySchema.safeParse(merged);
1121
- return parsed.success ? parsed.data : { marker: `list-malformed:${field}[${path}]` };
1122
- };
1123
-
1124
1100
  /** Generated entries of a source node (`{{#items}}`). */
1125
1101
  const sourceItems = (
1126
1102
  source: SourceDef,
@@ -1130,8 +1106,10 @@ function createPageContext(
1130
1106
  ): ScopeValue => {
1131
1107
  switch (source.kind) {
1132
1108
  case "query": {
1133
- const q = mergedQuery(source, item.query, field, `${item.id}.query`);
1134
- return "marker" in q ? { kind: "failed", marker: q.marker } : runQuery(q, field);
1109
+ const q = mergeQuerySource(source, item.query, field, `${item.id}.query`);
1110
+ return "marker" in q
1111
+ ? { kind: "failed", marker: q.marker, detail: q.detail }
1112
+ : runQuery(q, field);
1135
1113
  }
1136
1114
  case "system": {
1137
1115
  const termFields = node.fields.filter((f) => f.type === "term");
@@ -1153,7 +1131,7 @@ function createPageContext(
1153
1131
 
1154
1132
  const fromValue = (v: ScopeValue): ListFieldResolution =>
1155
1133
  v.kind === "failed"
1156
- ? { ok: false, marker: v.marker }
1134
+ ? { ok: false, marker: v.marker, ...(v.detail !== undefined ? { detail: v.detail } : {}) }
1157
1135
  : { ok: true, entries: v.kind === "list" ? v.entries : [] };
1158
1136
 
1159
1137
  /**
@@ -1172,13 +1150,14 @@ function createPageContext(
1172
1150
  if (eff === null) return { ok: false, marker: `list-malformed:${field.name}[paginate]` };
1173
1151
  const source = field.source;
1174
1152
  if (source?.kind === "query") {
1175
- const q = mergedQuery(
1153
+ const q = mergeQuerySource(
1176
1154
  { ...source, defaults: { ...source.defaults, limit: eff.perPage } },
1177
1155
  rest,
1178
1156
  field.name,
1179
1157
  "query",
1158
+ true,
1180
1159
  );
1181
- if ("marker" in q) return { ok: false, marker: q.marker };
1160
+ if ("marker" in q) return { ok: false, marker: q.marker, detail: q.detail };
1182
1161
  const key = JSON.stringify(["query", { ...q, limit: null }]);
1183
1162
  return fromValue(paginate(field.name, key, queryHits(q), eff));
1184
1163
  }
@@ -1207,9 +1186,9 @@ function createPageContext(
1207
1186
  if (!source) return { ok: false, marker: `list-malformed:${field.name}[source]` };
1208
1187
  switch (source.kind) {
1209
1188
  case "query": {
1210
- const q = mergedQuery(source, value, field.name, "query");
1189
+ const q = mergeQuerySource(source, value, field.name, "query");
1211
1190
  return "marker" in q
1212
- ? { ok: false, marker: q.marker }
1191
+ ? { ok: false, marker: q.marker, detail: q.detail }
1213
1192
  : fromValue(runQuery(q, field.name));
1214
1193
  }
1215
1194
  case "system": {
@@ -42,9 +42,11 @@ export type ScopeValue =
42
42
  /**
43
43
  * A value that could not resolve (a list source of an inactive plugin,
44
44
  * a malformed query). The engine renders the tag raw and reports
45
- * `marker` — loud, never silently empty (CLAUDE.md §2).
45
+ * `marker` — loud, never silently empty (CLAUDE.md §2). `detail`, when
46
+ * set, says what is wrong and how to fix it (shown to the AI by
47
+ * `preview_list_source`, #1281).
46
48
  */
47
- | { readonly kind: "failed"; readonly marker: string };
49
+ | { readonly kind: "failed"; readonly marker: string; readonly detail?: string };
48
50
 
49
51
  /** One entry a list section iterates. */
50
52
  export interface ScopeEntry {
@@ -19,7 +19,7 @@ import {
19
19
  TERM,
20
20
  } from "./lists/list-fixtures.test.js";
21
21
  import { createListRenderContext, type ListPageContext } from "./lists/resolve.js";
22
- import { renderTemplate, type TemplateField } from "./template-engine.js";
22
+ import { renderTemplate, type TemplateField, templateFieldsFromJson } from "./template-engine.js";
23
23
 
24
24
  function ctx(
25
25
  pageId: string | null = PAGE.home,
@@ -397,6 +397,32 @@ describe("lists — {{page.*}}", () => {
397
397
  '<img src="/_caelo/media/hero" alt="Hero">We launched.|4;<img src="" alt="">|5;',
398
398
  );
399
399
  });
400
+
401
+ // #1304 — a stored `modules.fields` jsonb whose query source omits
402
+ // `editable` renders through the parsed source (editable: []), never a
403
+ // raw one the resolver would read `editable` off.
404
+ it("a stored query source without editable renders (#1304)", () => {
405
+ const fields = templateFieldsFromJson([
406
+ {
407
+ name: "latest",
408
+ kind: "list",
409
+ listType: "links",
410
+ bind: "source",
411
+ source: {
412
+ kind: "query",
413
+ defaults: { page_type: "news", order: "prop_asc:rating", limit: 5 },
414
+ },
415
+ },
416
+ ]);
417
+ expect(fields[0]?.source).toEqual({
418
+ kind: "query",
419
+ editable: [],
420
+ defaults: { page_type: "news", order: "prop_asc:rating", limit: 5 },
421
+ });
422
+ const r = render("{{#latest}}{{props.rating}};{{/latest}}", fields, {}, ctx(PAGE.home));
423
+ expect(r.html).toBe("4;5;");
424
+ expect(r.missingSlots).toEqual([]);
425
+ });
400
426
  });
401
427
 
402
428
  describe("lists — terms", () => {
@@ -140,6 +140,9 @@ export function templateFieldsFromJson(raw: unknown): TemplateField[] {
140
140
  if (!f || typeof f !== "object") continue;
141
141
  const o = f as Record<string, unknown>;
142
142
  if (typeof o.name !== "string") continue;
143
+ // The parsed source, not the stored one: parsing fills defaults
144
+ // (`editable: []` when the source omits it, #1304).
145
+ const source = sourceDefSchema.safeParse(o.source);
143
146
  out.push({
144
147
  name: o.name,
145
148
  kind: (typeof o.kind === "string" ? o.kind : "text") as ModuleFieldKind,
@@ -149,7 +152,7 @@ export function templateFieldsFromJson(raw: unknown): TemplateField[] {
149
152
  ...(typeof o.list === "string" ? { list: o.list } : {}),
150
153
  // A source that fails its schema stays absent: the resolver then
151
154
  // reports `list-malformed:<field>[source]` instead of guessing.
152
- ...(sourceDefSchema.safeParse(o.source).success ? { source: o.source as SourceDef } : {}),
155
+ ...(source.success ? { source: source.data } : {}),
153
156
  // Passed as stored: the resolver validates it and reports a
154
157
  // malformed one as `list-malformed:<field>[paginate]`.
155
158
  ...(o.paginate !== undefined ? { paginate: o.paginate as ListPaginationSettings } : {}),
package/src/version.ts CHANGED
@@ -22,7 +22,7 @@
22
22
  * follow standard SemVer.
23
23
  */
24
24
 
25
- export const CAELO_VERSION = "0.11.8";
25
+ export const CAELO_VERSION = "0.11.9";
26
26
 
27
27
  /**
28
28
  * Deprecated alias for back-compat — early P17 work spelled this