@cloudhal/mcp-server 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -4
- package/dist/src/collection-fields.d.ts +24 -0
- package/dist/src/collection-fields.js +107 -0
- package/dist/src/collection-listings.d.ts +48 -0
- package/dist/src/collection-listings.js +280 -0
- package/dist/src/collection-tools.js +55 -12
- package/dist/src/common.js +3 -0
- package/dist/src/entry-fields.d.ts +35 -0
- package/dist/src/entry-fields.js +188 -0
- package/dist/src/entry-list.d.ts +17 -0
- package/dist/src/entry-list.js +98 -0
- package/dist/src/entry-tools.js +57 -18
- package/dist/src/field-hints.d.ts +8 -0
- package/dist/src/field-hints.js +56 -0
- package/dist/src/field-tools.d.ts +6 -0
- package/dist/src/field-tools.js +360 -0
- package/dist/src/page-tools.js +7 -0
- package/dist/src/release-risk.d.ts +22 -0
- package/dist/src/release-risk.js +95 -0
- package/dist/src/schedules.d.ts +2 -5
- package/dist/src/schedules.js +5 -38
- package/dist/src/section-queries.d.ts +10 -0
- package/dist/src/section-queries.js +52 -0
- package/dist/src/server-instructions.js +5 -1
- package/dist/src/structured-data-tools.d.ts +8 -0
- package/dist/src/structured-data-tools.js +111 -0
- package/dist/src/tools.js +18 -4
- package/dist/src/translation-fields.d.ts +32 -0
- package/dist/src/translation-fields.js +68 -0
- package/dist/src/translation-tools.js +56 -6
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ import { createCloudhalMcpHandler } from "@cloudhal/mcp-server/http"; // fet
|
|
|
21
21
|
## Tool reference
|
|
22
22
|
|
|
23
23
|
<!-- tools:start (generated by scripts/mcp-tools-doc.ts; do not edit) -->
|
|
24
|
-
**
|
|
24
|
+
**110 tools**, in the order the server lists them.
|
|
25
25
|
|
|
26
26
|
| Tool | Scopes | Kind | Approval | What it does |
|
|
27
27
|
|---|---|---|---|---|
|
|
@@ -39,12 +39,12 @@ import { createCloudhalMcpHandler } from "@cloudhal/mcp-server/http"; // fet
|
|
|
39
39
|
| `list_entries` | `content:read` | read | — | Content entries, newest first. |
|
|
40
40
|
| `get_entry` | `content:read` | read | — | One content entry with its body and current revision. |
|
|
41
41
|
| `create_entry` | `content:write` | write | by the key's mode | Create a draft content entry (markdown body) in an existing collection (list_collections; a new one needs create_collection first), optionally filed under existing terms (`terms`;… |
|
|
42
|
-
| `update_entry` | `content:write` | write | by the key's mode | Update title, summary, body, slug, status (draft → review → published)
|
|
42
|
+
| `update_entry` | `content:write` | write | by the key's mode | Update title, summary, body, slug, status (draft → review → published), terms (`terms`: add, remove or set categories and tags by id, slug or name) or typed custom fields (`fields`… |
|
|
43
43
|
| `add_correction` | `content:write` | write | by the key's mode | Append a correction, clarification or update notice to an article (RFC-0019 §2) when a published story changed in substance. |
|
|
44
44
|
| `delete_entry` | `content:write` | write (destructive) | by the key's mode | Delete a content entry. |
|
|
45
45
|
| `list_translations` | `content:read` | read | — | Every language version of a page or entry (its translation group): locale, status, method (original, human, machine, machine-reviewed), whether it is stale (its source changed sin… |
|
|
46
46
|
| `list_stale_translations` | `content:read` | read | — | Translations whose source changed since they were made (or whose source is gone), optionally in one locale: the work queue for keeping languages in step. |
|
|
47
|
-
| `get_translation_source` | `content:read` | read | — | What you need to translate a page or entry into `locale`: the source (translate its title, text, summary and SEO; keep section ids, kinds, links, numbers, images and bindings),
|
|
47
|
+
| `get_translation_source` | `content:read` | read | — | What you need to translate a page or entry into `locale`: the source (translate its title, text, summary and SEO; keep section ids, kinds, links, numbers, images and bindings), fo… |
|
|
48
48
|
| `save_translation` | `content:write` | write | by the key's mode | Save your translation of a page or entry into `locale` as a draft linked to the source's current revision, with your model as its provenance. |
|
|
49
49
|
| `search_site` | `content:read` | read | — | Find nodes by words instead of listing everything. |
|
|
50
50
|
| `get_theme_settings` | `content:read` | read | — | The theme's design settings (RFC-0017): their schema (colors as #rrggbb, enums, numbers; per-locale titles), the contrast rules colors must meet, and the site's current values. |
|
|
@@ -79,7 +79,12 @@ import { createCloudhalMcpHandler } from "@cloudhal/mcp-server/http"; // fet
|
|
|
79
79
|
| `delete_redirect` | `site:write` | write (destructive) | always a person | Delete a redirect; its old path then answers 404 unless something serves it. |
|
|
80
80
|
| `list_collections` | `content:read` | read | — | The site's collections (RFC-0040): declared ones, ones that already have entries, and posts. |
|
|
81
81
|
| `create_collection` | `site:write` | write | always a person | Declare a new collection (RFC-0040), e.g. events, team or jobs, with its names in the site's default locale (labels), an optional icon, permalink (/<prefix>/{slug}, default /<key>… |
|
|
82
|
-
| `update_collection` | `site:write` | write | always a person | Change a collection's names (merged per locale), icon, feed, sitemap
|
|
82
|
+
| `update_collection` | `site:write` | write | always a person | Change a collection's names (merged per locale), icon, feed, sitemap, default sort (RFC-0040) or its typed custom fields (`fields`, the whole list; RFC-0041), list fields, date-dr… |
|
|
83
|
+
| `preview_structured_data` | `content:read` | read | — | The JSON-LD document an entry's page emits under its collection's structured-data preset (RFC-0042: Event, JobPosting, Product, Recipe), built exactly as the site builds it, with… |
|
|
84
|
+
| `rename_field` | `site:write`, `content:write` | write | always a person | Rename a typed custom field's key (RFC-0041 §6): every entry's value moves from `from` to `to`; nothing is converted. |
|
|
85
|
+
| `change_field_type` | `site:write`, `content:write` | write (destructive) | always a person | Change a typed custom field's type, or a select's multiple (RFC-0041 §6), converting every value by a closed table (text↔richText, text↔number, text↔select, text↔url, date↔datetim… |
|
|
86
|
+
| `set_field_localized` | `site:write`, `content:write` | write | always a person | Make a typed custom field localized (each language version has its own value; translations fall back to the original's) or shared (only the original holds it; translations' own co… |
|
|
87
|
+
| `remove_field` | `site:write`, `content:write` | write (destructive) | always a person | Remove a typed custom field (RFC-0041 §6): its value is deleted from every entry, then its definition. |
|
|
83
88
|
| `set_collection_permalink` | `site:write` | write | always a person | Move where a collection's entries live (RFC-0038): permalink "/blog/{slug}" puts collection "posts" at /blog/<slug>; null goes back to the default /<collection>/{slug}. |
|
|
84
89
|
| `list_menus` | `site:read` | read | — | The site's navigation menus (primary = header, footer, sidebar, custom keys) with id, rev, maxDepth, item count and how many items are hidden on the site. |
|
|
85
90
|
| `get_menu` | `site:read` | read | — | One menu: the stored tree (send its rev back when writing) and, per item for a locale, whether the site shows it (`state`), why not (`reason`: missing, unpublished, other-locale,… |
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC-0041 §8 for the collection tools: `list_collections` shows each collection's field
|
|
3
|
+
* definitions and the JSON Schema of its values (in the caller's locale), and `update_collection`
|
|
4
|
+
* takes the whole `fields` list for free edits (§6). Changes that could lose values are refused by
|
|
5
|
+
* the store's guard (`field_change_needs_operation`) and go through the operation tools instead.
|
|
6
|
+
*/
|
|
7
|
+
import type { CollectionSettings, FieldDefinition, Site } from "@cloudhal/core-contracts";
|
|
8
|
+
import { type JsonSchema } from "./common.js";
|
|
9
|
+
/** `update_collection`'s `fields`: the contract's definitions, minus the operation marker. */
|
|
10
|
+
export declare const FIELD_DEFINITIONS_INPUT: JsonSchema;
|
|
11
|
+
/**
|
|
12
|
+
* The settings with `fields` replaced by the agent's list. A running operation's marker stays on
|
|
13
|
+
* its field (agents never write it), so editing labels meanwhile is not read as touching it.
|
|
14
|
+
*/
|
|
15
|
+
export declare function withFields(current: CollectionSettings, next: CollectionSettings, fields: FieldDefinition[]): CollectionSettings;
|
|
16
|
+
/** JSON with sorted keys: stored definitions may list properties in another order. */
|
|
17
|
+
export declare function canonical(value: unknown): string;
|
|
18
|
+
/** One line for the approval prompt: which fields are added, changed, removed or reordered. */
|
|
19
|
+
export declare function describeFieldEdits(before: readonly FieldDefinition[], after: readonly FieldDefinition[], locale: string): string | undefined;
|
|
20
|
+
/** What `list_collections` adds per collection that has definitions. */
|
|
21
|
+
export declare function fieldsView(site: Site, key: string, locale: string): {
|
|
22
|
+
fields: FieldDefinition[];
|
|
23
|
+
fieldsSchema: JsonSchema;
|
|
24
|
+
} | Record<string, never>;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC-0041 §8 for the collection tools: `list_collections` shows each collection's field
|
|
3
|
+
* definitions and the JSON Schema of its values (in the caller's locale), and `update_collection`
|
|
4
|
+
* takes the whole `fields` list for free edits (§6). Changes that could lose values are refused by
|
|
5
|
+
* the store's guard (`field_change_needs_operation`) and go through the operation tools instead.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { SiteSchema } from "@cloudhal/core-contracts";
|
|
9
|
+
import { fieldLabel, fieldsJsonSchema } from "@cloudhal/core-ts/fields";
|
|
10
|
+
import { quote } from "./common.js";
|
|
11
|
+
|
|
12
|
+
const DEFS = SiteSchema.$defs ;
|
|
13
|
+
const VARIANTS = (DEFS.FieldDefinition ).oneOf ;
|
|
14
|
+
|
|
15
|
+
/** A definition variant without `migration`: only field operations write the marker. */
|
|
16
|
+
function withoutMarker(variant ) {
|
|
17
|
+
const { migration: _m, ...properties } = variant.properties ;
|
|
18
|
+
return { ...variant, properties };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** `update_collection`'s `fields`: the contract's definitions, minus the operation marker. */
|
|
22
|
+
export const FIELD_DEFINITIONS_INPUT = {
|
|
23
|
+
type: "array",
|
|
24
|
+
maxItems: 30,
|
|
25
|
+
description:
|
|
26
|
+
"The collection's typed custom fields, the whole list in form order ([] removes them all). Free edits only: add fields, reorder, change labels and help, add select options or change their labels, toggle multiline, searchable or requiredToPublish, change maxLength/minimum/maximum. Renaming a key, changing a type, localized or multiple, and dropping a key or option still in use need rename_field, change_field_type, set_field_localized or remove_field.",
|
|
27
|
+
items: { $ref: "#/$defs/FieldDefinition" },
|
|
28
|
+
$defs: {
|
|
29
|
+
FieldDefinition: {
|
|
30
|
+
...DEFS.FieldDefinition,
|
|
31
|
+
oneOf: VARIANTS.map(withoutMarker),
|
|
32
|
+
},
|
|
33
|
+
FieldKey: DEFS.FieldKey,
|
|
34
|
+
FieldLabel: DEFS.FieldLabel,
|
|
35
|
+
FieldLabels: DEFS.FieldLabels,
|
|
36
|
+
FieldOption: DEFS.FieldOption,
|
|
37
|
+
Slug: DEFS.Slug,
|
|
38
|
+
Locale: DEFS.Locale,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The settings with `fields` replaced by the agent's list. A running operation's marker stays on
|
|
44
|
+
* its field (agents never write it), so editing labels meanwhile is not read as touching it.
|
|
45
|
+
*/
|
|
46
|
+
export function withFields(
|
|
47
|
+
current ,
|
|
48
|
+
next ,
|
|
49
|
+
fields ,
|
|
50
|
+
) {
|
|
51
|
+
const markers = new Map((current.fields ?? []).map((d) => [d.key, d.migration]));
|
|
52
|
+
const { fields: _old, ...rest } = next;
|
|
53
|
+
if (fields.length === 0) return rest;
|
|
54
|
+
return {
|
|
55
|
+
...rest,
|
|
56
|
+
fields: fields.map((d) => {
|
|
57
|
+
const { migration: _m, ...def } = d;
|
|
58
|
+
const marker = markers.get(d.key);
|
|
59
|
+
return (marker ? { ...def, migration: marker } : def) ;
|
|
60
|
+
}) ,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** JSON with sorted keys: stored definitions may list properties in another order. */
|
|
65
|
+
export function canonical(value ) {
|
|
66
|
+
return JSON.stringify(value, (_k, v ) =>
|
|
67
|
+
v && typeof v === "object" && !Array.isArray(v)
|
|
68
|
+
? Object.fromEntries(Object.entries(v).sort(([x], [y]) => x.localeCompare(y)))
|
|
69
|
+
: v,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** One line for the approval prompt: which fields are added, changed, removed or reordered. */
|
|
74
|
+
export function describeFieldEdits(
|
|
75
|
+
before ,
|
|
76
|
+
after ,
|
|
77
|
+
locale ,
|
|
78
|
+
) {
|
|
79
|
+
const old = new Map(before.map((d) => [d.key, d]));
|
|
80
|
+
const now = new Map(after.map((d) => [d.key, d]));
|
|
81
|
+
const name = (d ) => `"${quote(fieldLabel(d, locale, locale), 40)}" (${d.key})`;
|
|
82
|
+
const parts = [];
|
|
83
|
+
for (const d of after) {
|
|
84
|
+
const was = old.get(d.key);
|
|
85
|
+
if (!was) parts.push(`add ${name(d)}, ${d.type}${d.localized ? ", localized" : ""}`);
|
|
86
|
+
else if (canonical(was) !== canonical(d)) parts.push(`change ${name(d)}`);
|
|
87
|
+
}
|
|
88
|
+
for (const d of before) if (!now.has(d.key)) parts.push(`remove ${name(d)}`);
|
|
89
|
+
const kept = (list , other ) =>
|
|
90
|
+
list.filter((d) => other.has(d.key)).map((d) => d.key);
|
|
91
|
+
if (kept(before, now).join() !== kept(after, old).join()) parts.push("reorder");
|
|
92
|
+
return parts.length ? ` fields: ${parts.join("; ")}` : undefined;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** What `list_collections` adds per collection that has definitions. */
|
|
96
|
+
export function fieldsView(
|
|
97
|
+
site ,
|
|
98
|
+
key ,
|
|
99
|
+
locale ,
|
|
100
|
+
) {
|
|
101
|
+
const fields = site.collections?.[key]?.fields;
|
|
102
|
+
if (!fields?.length) return {};
|
|
103
|
+
return {
|
|
104
|
+
fields,
|
|
105
|
+
fieldsSchema: fieldsJsonSchema(fields, locale, site.defaultLocale) ,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC-0042 §7 for the collection tools: `update_collection` takes a collection's `listFields`,
|
|
3
|
+
* `expiry` and `structuredData` (null removes one), the store's dry run checks them in precheck
|
|
4
|
+
* (`unknown_field`, `invalid_expiry`, `structured_data_invalid`, `list_field_in_use`,
|
|
5
|
+
* `gates_unsupported`), and the approval prompt says in words what changes, e.g. "Events leave
|
|
6
|
+
* listings, feeds and search 1 hour after "Ends at" (endsAt); 2 published entries are already past
|
|
7
|
+
* it". `list_collections` shows each list field's operators and the preset's paths.
|
|
8
|
+
*/
|
|
9
|
+
import type { CollectionSettings, FieldDefinition, Site, StructuredDataSource } from "@cloudhal/core-contracts";
|
|
10
|
+
import { type FieldQueryOp } from "@cloudhal/core-ts/fields";
|
|
11
|
+
import { type PresetType, type StructuredDataIssue } from "@cloudhal/core-ts/structured-data";
|
|
12
|
+
import { type JsonSchema, type ToolContext } from "./common.js";
|
|
13
|
+
/** `update_collection`'s stage 3 settings (RFC-0042), each removable with null. */
|
|
14
|
+
export declare const LISTINGS_INPUT: Record<string, JsonSchema>;
|
|
15
|
+
/** `next` with the agent's stage 3 settings applied: a value sets it, null removes it. */
|
|
16
|
+
export declare function withListings(next: CollectionSettings, a: Record<string, unknown>): CollectionSettings;
|
|
17
|
+
/** The warnings (not refusals) of the collection's preset: select options outside a vocabulary. */
|
|
18
|
+
export declare function presetWarnings(site: Site, key: string): StructuredDataIssue[];
|
|
19
|
+
/** Approval lines for the stage 3 settings that change between `before` and `next`. */
|
|
20
|
+
export declare function describeListings(ctx: ToolContext, next: Site, key: string, before: CollectionSettings | undefined): Promise<string[]>;
|
|
21
|
+
interface ListFieldView {
|
|
22
|
+
key: string;
|
|
23
|
+
type: FieldDefinition["type"];
|
|
24
|
+
ops: readonly FieldQueryOp[];
|
|
25
|
+
sortable: boolean;
|
|
26
|
+
}
|
|
27
|
+
interface PathView {
|
|
28
|
+
path: string;
|
|
29
|
+
required?: true;
|
|
30
|
+
/** "At least one of" this group is required. */
|
|
31
|
+
group?: string;
|
|
32
|
+
default?: StructuredDataSource;
|
|
33
|
+
fields: readonly string[];
|
|
34
|
+
entry: readonly string[];
|
|
35
|
+
site: readonly string[];
|
|
36
|
+
constant: boolean;
|
|
37
|
+
vocabulary?: string[];
|
|
38
|
+
}
|
|
39
|
+
/** What `list_collections` adds per collection for listings and structured data. */
|
|
40
|
+
export declare function listingsView(site: Site, key: string): {
|
|
41
|
+
listFields?: ListFieldView[];
|
|
42
|
+
structuredData?: {
|
|
43
|
+
type: PresetType;
|
|
44
|
+
paths: PathView[];
|
|
45
|
+
warnings: StructuredDataIssue[];
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC-0042 §7 for the collection tools: `update_collection` takes a collection's `listFields`,
|
|
3
|
+
* `expiry` and `structuredData` (null removes one), the store's dry run checks them in precheck
|
|
4
|
+
* (`unknown_field`, `invalid_expiry`, `structured_data_invalid`, `list_field_in_use`,
|
|
5
|
+
* `gates_unsupported`), and the approval prompt says in words what changes, e.g. "Events leave
|
|
6
|
+
* listings, feeds and search 1 hour after "Ends at" (endsAt); 2 published entries are already past
|
|
7
|
+
* it". `list_collections` shows each list field's operators and the preset's paths.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
import { SiteSchema } from "@cloudhal/core-contracts";
|
|
18
|
+
import {
|
|
19
|
+
canOrderBy,
|
|
20
|
+
derivedGate,
|
|
21
|
+
FIELD_QUERY_OPS,
|
|
22
|
+
|
|
23
|
+
fieldLabel,
|
|
24
|
+
originalsOf,
|
|
25
|
+
} from "@cloudhal/core-ts/fields";
|
|
26
|
+
import {
|
|
27
|
+
checkStructuredData,
|
|
28
|
+
KIND_SOURCES,
|
|
29
|
+
PRESET_TYPES,
|
|
30
|
+
PRESETS,
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
VOCABULARIES,
|
|
34
|
+
} from "@cloudhal/core-ts/structured-data";
|
|
35
|
+
import { canonical } from "./collection-fields.js";
|
|
36
|
+
import { quote, } from "./common.js";
|
|
37
|
+
|
|
38
|
+
const DEFS = SiteSchema.$defs ;
|
|
39
|
+
const SETTINGS_PROPS = (DEFS.CollectionSettings )
|
|
40
|
+
.properties;
|
|
41
|
+
const nullable = (ref , description , $defs ) => ({
|
|
42
|
+
anyOf: [{ $ref: `#/$defs/${ref}` }, { type: "null" }],
|
|
43
|
+
description,
|
|
44
|
+
$defs,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
/** One line per preset type: its paths, required ones marked with `*`. */
|
|
48
|
+
function presetSummary() {
|
|
49
|
+
return PRESET_TYPES.map((type) => {
|
|
50
|
+
const paths = Object.entries(PRESETS[type].paths).map(
|
|
51
|
+
([path, spec]) => `${path}${spec.required ? "*" : ""}`,
|
|
52
|
+
);
|
|
53
|
+
return `${type}: ${paths.join(", ")}`;
|
|
54
|
+
}).join(". ");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** `update_collection`'s stage 3 settings (RFC-0042), each removable with null. */
|
|
58
|
+
export const LISTINGS_INPUT = {
|
|
59
|
+
listFields: {
|
|
60
|
+
anyOf: [SETTINGS_PROPS.listFields, { type: "null" }],
|
|
61
|
+
description:
|
|
62
|
+
"Up to 4 field keys that listings (contentList where/orderBy, list_entries) may filter and sort by, in column order; null removes them. A field contentList sections still use cannot be dropped (list_field_in_use)",
|
|
63
|
+
$defs: { FieldKey: DEFS.FieldKey },
|
|
64
|
+
},
|
|
65
|
+
expiry: nullable(
|
|
66
|
+
"CollectionExpiry",
|
|
67
|
+
'A time gate every entry derives from a date or datetime field: {"field":"endsAt","action":"unlist"} (the page stays, the entry leaves listings, feeds, the sitemap and search) or "hide" (404 everywhere), afterMinutes of grace. Needs a site Worker that enforces derived gates (gates_unsupported otherwise). null removes it: expired entries come back at the next publish',
|
|
68
|
+
{ CollectionExpiry: DEFS.CollectionExpiry, FieldKey: DEFS.FieldKey },
|
|
69
|
+
),
|
|
70
|
+
structuredData: nullable(
|
|
71
|
+
"StructuredDataPreset",
|
|
72
|
+
`A JSON-LD preset the entry pages emit instead of BlogPosting: a type and its properties, each mapped to a source ({"kind":"field","field":"startsAt"}, {"kind":"entry","property":"title"}, {"kind":"site","property":"name"} or {"kind":"constant","value":"EUR"}). Unmapped paths with a default read it; required values (*) come from the entry, never a constant. Paths: ${presetSummary()}. Check an entry's output with preview_structured_data. null removes it`,
|
|
73
|
+
{
|
|
74
|
+
StructuredDataPreset: DEFS.StructuredDataPreset,
|
|
75
|
+
StructuredDataSource: DEFS.StructuredDataSource,
|
|
76
|
+
EntryValueProperty: DEFS.EntryValueProperty,
|
|
77
|
+
SiteValueProperty: DEFS.SiteValueProperty,
|
|
78
|
+
FieldKey: DEFS.FieldKey,
|
|
79
|
+
},
|
|
80
|
+
),
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const KEYS = ["listFields", "expiry", "structuredData"] ;
|
|
84
|
+
|
|
85
|
+
/** `next` with the agent's stage 3 settings applied: a value sets it, null removes it. */
|
|
86
|
+
export function withListings(
|
|
87
|
+
next ,
|
|
88
|
+
a ,
|
|
89
|
+
) {
|
|
90
|
+
const out = { ...next };
|
|
91
|
+
for (const k of KEYS) {
|
|
92
|
+
if (a[k] === undefined) continue;
|
|
93
|
+
if (a[k] === null) delete out[k];
|
|
94
|
+
else out[k] = a[k];
|
|
95
|
+
}
|
|
96
|
+
return out ;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** "30 minutes", "1 hour", "2 days". */
|
|
100
|
+
function duration(minutes ) {
|
|
101
|
+
const unit = (n , one ) => `${n} ${one}${n === 1 ? "" : "s"}`;
|
|
102
|
+
if (minutes % 1440 === 0) return unit(minutes / 1440, "day");
|
|
103
|
+
if (minutes % 60 === 0) return unit(minutes / 60, "hour");
|
|
104
|
+
return unit(minutes, "minute");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Published entries of the collection whose derived gate under `site` has already passed. */
|
|
108
|
+
async function pastCount(ctx , site , key ) {
|
|
109
|
+
const entries = await ctx.store.listContentEntries(site.id, {
|
|
110
|
+
collection: key,
|
|
111
|
+
status: ["published"],
|
|
112
|
+
});
|
|
113
|
+
const original = originalsOf(entries);
|
|
114
|
+
const now = (ctx.now?.() ?? new Date()).getTime();
|
|
115
|
+
return entries.filter((e) => {
|
|
116
|
+
const gate = derivedGate(site, e, original(e));
|
|
117
|
+
return gate !== undefined && gate.at <= now;
|
|
118
|
+
}).length;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function fieldName(defs , key , locale ) {
|
|
122
|
+
const def = defs?.find((d) => d.key === key);
|
|
123
|
+
return def ? `"${quote(fieldLabel(def, locale, locale), 40)}" (${key})` : key;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async function expiryLine(
|
|
127
|
+
ctx ,
|
|
128
|
+
site ,
|
|
129
|
+
key ,
|
|
130
|
+
rule ,
|
|
131
|
+
) {
|
|
132
|
+
const settings = site.collections?.[key];
|
|
133
|
+
const plural = settings?.labels?.[site.defaultLocale]?.plural;
|
|
134
|
+
const who = plural ? quote(plural, 40) : `Entries of ${key}`;
|
|
135
|
+
const when = rule.afterMinutes ? `${duration(rule.afterMinutes)} after` : "at";
|
|
136
|
+
const field = fieldName(settings?.fields, rule.field, site.defaultLocale);
|
|
137
|
+
const what =
|
|
138
|
+
rule.action === "hide"
|
|
139
|
+
? `disappear from the site (404 on every route)`
|
|
140
|
+
: "leave listings, feeds, the sitemap and search (their pages stay)";
|
|
141
|
+
const past = await pastCount(ctx, site, key);
|
|
142
|
+
const already =
|
|
143
|
+
past === 0
|
|
144
|
+
? ""
|
|
145
|
+
: `; ${past} published ${past === 1 ? "entry is" : "entries are"} already past it`;
|
|
146
|
+
return ` expiry: ${who} ${what} ${when} ${field}${already}`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function sourceText(source ) {
|
|
150
|
+
switch (source.kind) {
|
|
151
|
+
case "field":
|
|
152
|
+
return `field ${source.field}`;
|
|
153
|
+
case "entry":
|
|
154
|
+
return `entry ${source.property}`;
|
|
155
|
+
case "site":
|
|
156
|
+
return `site ${source.property}`;
|
|
157
|
+
case "constant":
|
|
158
|
+
return `"${quote(source.value, 30)}"`;
|
|
159
|
+
default:
|
|
160
|
+
return "?";
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function presetLine(preset ) {
|
|
165
|
+
const maps = Object.entries(preset.properties)
|
|
166
|
+
.filter((e) => e[1] !== undefined)
|
|
167
|
+
.map(([path, source]) => `${path} ← ${sourceText(source)}`);
|
|
168
|
+
const shown = maps.slice(0, 8).join(", ");
|
|
169
|
+
const more = maps.length > 8 ? ` and ${maps.length - 8} more` : "";
|
|
170
|
+
return ` structured data: ${preset.type}, maps ${shown}${more}; entries without a required value keep BlogPosting`;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** The warnings (not refusals) of the collection's preset: select options outside a vocabulary. */
|
|
174
|
+
export function presetWarnings(site , key ) {
|
|
175
|
+
const only = site.collections?.[key];
|
|
176
|
+
if (!only?.structuredData) return [];
|
|
177
|
+
return checkStructuredData({ ...site, collections: { [key]: only } }).filter((i) => i.warning);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Approval lines for the stage 3 settings that change between `before` and `next`. */
|
|
181
|
+
export async function describeListings(
|
|
182
|
+
ctx ,
|
|
183
|
+
next ,
|
|
184
|
+
key ,
|
|
185
|
+
before ,
|
|
186
|
+
) {
|
|
187
|
+
const after = next.collections?.[key] ?? {};
|
|
188
|
+
const changed = (k ) => canonical(before?.[k]) !== canonical(after[k]);
|
|
189
|
+
const lines = [];
|
|
190
|
+
if (changed("listFields"))
|
|
191
|
+
lines.push(
|
|
192
|
+
after.listFields
|
|
193
|
+
? ` list fields: ${after.listFields.map((f) => fieldName(after.fields, f, next.defaultLocale)).join(", ")}`
|
|
194
|
+
: " list fields: removed",
|
|
195
|
+
);
|
|
196
|
+
if (changed("expiry"))
|
|
197
|
+
lines.push(
|
|
198
|
+
after.expiry
|
|
199
|
+
? await expiryLine(ctx, next, key, after.expiry)
|
|
200
|
+
: " expiry: removed; entries past it come back at the next publish",
|
|
201
|
+
);
|
|
202
|
+
if (changed("structuredData")) {
|
|
203
|
+
lines.push(
|
|
204
|
+
after.structuredData
|
|
205
|
+
? presetLine(after.structuredData)
|
|
206
|
+
: " structured data: removed; entry pages go back to BlogPosting",
|
|
207
|
+
);
|
|
208
|
+
for (const w of presetWarnings(next, key).slice(0, 3))
|
|
209
|
+
lines.push(` structured data warning: ${w.message}`);
|
|
210
|
+
}
|
|
211
|
+
return lines;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
function pathsOf(type ) {
|
|
235
|
+
return Object.entries(PRESETS[type].paths).map(([path, spec]) => {
|
|
236
|
+
const sources = KIND_SOURCES[spec.kind];
|
|
237
|
+
return {
|
|
238
|
+
path,
|
|
239
|
+
...(spec.required ? { required: true } : {}),
|
|
240
|
+
...(spec.group ? { group: spec.group } : {}),
|
|
241
|
+
...(spec.default ? { default: spec.default } : {}),
|
|
242
|
+
fields: [...sources.fields, ...(spec.alsoFields ?? [])],
|
|
243
|
+
entry: sources.entry,
|
|
244
|
+
site: sources.site,
|
|
245
|
+
constant: sources.constant && !spec.required,
|
|
246
|
+
...(spec.vocabulary ? { vocabulary: VOCABULARIES[spec.vocabulary].map((v) => v.key) } : {}),
|
|
247
|
+
};
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** What `list_collections` adds per collection for listings and structured data. */
|
|
252
|
+
export function listingsView(
|
|
253
|
+
site ,
|
|
254
|
+
key ,
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
{
|
|
259
|
+
const settings = site.collections?.[key];
|
|
260
|
+
const defs = new Map((settings?.fields ?? []).map((d) => [d.key, d]));
|
|
261
|
+
const listFields = (settings?.listFields ?? []).flatMap((k) => {
|
|
262
|
+
const def = defs.get(k);
|
|
263
|
+
return def
|
|
264
|
+
? [{ key: k, type: def.type, ops: FIELD_QUERY_OPS[def.type], sortable: canOrderBy(def.type) }]
|
|
265
|
+
: [];
|
|
266
|
+
});
|
|
267
|
+
const preset = settings?.structuredData;
|
|
268
|
+
return {
|
|
269
|
+
...(listFields.length ? { listFields } : {}),
|
|
270
|
+
...(preset && PRESETS[preset.type]
|
|
271
|
+
? {
|
|
272
|
+
structuredData: {
|
|
273
|
+
type: preset.type,
|
|
274
|
+
paths: pathsOf(preset.type),
|
|
275
|
+
warnings: presetWarnings(site, key),
|
|
276
|
+
},
|
|
277
|
+
}
|
|
278
|
+
: {}),
|
|
279
|
+
};
|
|
280
|
+
}
|