create-ailk 0.43.0 → 0.44.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 +11 -10
- package/component-catalog.json +23 -0
- package/dist/lib/import-mdx.d.ts +12 -15
- package/dist/lib/import-mdx.js +168 -193
- package/dist/migrate-content.d.ts +9 -16
- package/dist/migrate-content.js +43 -81
- package/package.json +3 -3
- package/templates/apps/api/CLAUDE.md +11 -6
- package/templates/apps/mcp/CLAUDE.md +8 -2
- package/templates/apps/web/package.json +1 -1
- package/versions.json +50 -50
package/dist/lib/import-mdx.js
CHANGED
|
@@ -3,24 +3,25 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Reads a site's default-locale MDX pages through the site's own MDX adapter
|
|
5
5
|
* and writes each one as a `text/page` Artifact through the tenant-guarded
|
|
6
|
-
* workspace content routes. Per page (D3): read the draft
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* workspace content routes. Per page (D3, #11843 D1): read the draft, then
|
|
7
|
+
* save once — `save_page` (`PUT …/content/:type/:slug`) for a page and
|
|
8
|
+
* `save_document` (`POST …/documents/save`) for a `Document`, with
|
|
9
|
+
* `version: null` on a 404 and the read's version and layout token otherwise
|
|
10
|
+
* — or write nothing when the read already holds what the save would store,
|
|
11
|
+
* so a second run over the same files creates nothing and reports every page
|
|
12
|
+
* `unchanged` (#11843 D4). A file the adapter rejects is `failed` with its path
|
|
10
13
|
* and reason and the run goes on. The seed step (U6b) and `migrate-content`
|
|
11
14
|
* (U6c) both call it; this module adds no command.
|
|
12
15
|
*
|
|
13
|
-
* A page whose frontmatter carries `sections` is
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* and sends the layout once more (#11749 D2), so the live page does not change
|
|
23
|
-
* until it is published. A second refusal fails the page with that reason.
|
|
16
|
+
* A page whose frontmatter carries `sections` is saved in the section form
|
|
17
|
+
* (#10534, #11843 D1): the sections are `save_page`'s words, and the hub
|
|
18
|
+
* builds the body from them, so the text before the first section — which
|
|
19
|
+
* nothing renders — is not sent (D3). Any other page's words are its body.
|
|
20
|
+
* The importer compares the read with what the save would store, its words
|
|
21
|
+
* as the codec (`sectionsToMarkdown`, ADR 0038) writes them, so a page the
|
|
22
|
+
* earlier importer stored after a lead is still `unchanged`. An edit to a
|
|
23
|
+
* live page appends a draft, so the live page does not change until it is
|
|
24
|
+
* published.
|
|
24
25
|
*
|
|
25
26
|
* A section string that holds inline HTML is converted first (#10804) — a
|
|
26
27
|
* link to `[label](href)`, a line break to a newline, a block to a blank
|
|
@@ -28,7 +29,9 @@
|
|
|
28
29
|
* carry no tag, which the hub's structure write refuses. The layout is then
|
|
29
30
|
* checked against the hub's section-string rules before any write, so a page
|
|
30
31
|
* the hub would refuse fails with the rule and the path, and a page whose
|
|
31
|
-
* draft holds no layout yet is never reported `unchanged`.
|
|
32
|
+
* draft holds no layout yet is never reported `unchanged`. A page that fails
|
|
33
|
+
* its type's checks is refused `422 invalid` by the save, and nothing is
|
|
34
|
+
* stored (#11843 D2).
|
|
32
35
|
*
|
|
33
36
|
* create-ailk ships one runtime dependency, so the adapter is never imported:
|
|
34
37
|
* the caller injects it, and `loadSiteMdxAdapter` resolves the SITE's
|
|
@@ -44,11 +47,9 @@
|
|
|
44
47
|
* vocabulary does not name rides in `siteFields`, and a blog post's tags are
|
|
45
48
|
* sent (#10806); a key the store cannot keep is named with its reason.
|
|
46
49
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* the site's contract members (`publishCheck`), each written page's outcome
|
|
51
|
-
* carries the verdict the hub's publish gate will give it (D6).
|
|
50
|
+
* No page carries the hub's live-source mark: no save keeps it (#11843 D7).
|
|
51
|
+
* With the site's contract members (`publishCheck`), each written page's
|
|
52
|
+
* outcome carries the verdict the hub's publish gate will give it (#10898 D6).
|
|
52
53
|
*
|
|
53
54
|
* Given `publish` (#10659 D2), each page with no Live version is set Live
|
|
54
55
|
* after it is written (`POST …/publish`, the draft tip); a page already Live
|
|
@@ -61,9 +62,9 @@
|
|
|
61
62
|
*
|
|
62
63
|
* Spec: docs/specs/10203-import-mdx-one-mdx-artifact-spec.md; the editorial
|
|
63
64
|
* walk docs/specs/10701-import-mdx-walks-the-editorial-spec.md; its site
|
|
64
|
-
* fields docs/specs/10806-the-editorial-import-drops-blog-spec.md
|
|
65
|
+
* fields docs/specs/10806-the-editorial-import-drops-blog-spec.md; the saves
|
|
66
|
+
* docs/specs/11843-the-scaffold-s-importer-saves-spec.md.
|
|
65
67
|
*/
|
|
66
|
-
import { createHash } from "node:crypto";
|
|
67
68
|
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
68
69
|
import { createRequire } from "node:module";
|
|
69
70
|
import { dirname, join, resolve } from "node:path";
|
|
@@ -80,10 +81,18 @@ const VALIDATION_PACKAGE = "@working-theory/validation";
|
|
|
80
81
|
const FRONTMATTER_PACKAGE = "gray-matter";
|
|
81
82
|
/** The page-type registry: a dependency of the adapter package (#10898 D6). */
|
|
82
83
|
const PAGE_TYPES_PACKAGE = "@working-theory/schema/page-types";
|
|
83
|
-
/** The hub's live-source content key (`LIVE_SOURCE_KEY`, api-content-write `content.ts`), restated:
|
|
84
|
+
/** The hub's live-source content key (`LIVE_SOURCE_KEY`, api-content-write `content.ts`), restated: never sent (#11843 D7). */
|
|
84
85
|
const LIVE_SOURCE_KEY = "liveSource";
|
|
85
86
|
/** The hub's written-from record (`WRITTEN_FROM_KEY`, same file), restated: never taken from a file (#11707 D9). */
|
|
86
87
|
const WRITTEN_FROM_KEY = "writtenFrom";
|
|
88
|
+
/** `DOCUMENT_TYPE` (the validation package's `content-draft.ts`), restated: saved with `save_document` (#11843 D10). */
|
|
89
|
+
const DOCUMENT_TYPE = "Document";
|
|
90
|
+
/**
|
|
91
|
+
* The frontmatter keys never sent in `fields` (#11843 D2): the ones the save
|
|
92
|
+
* takes from the address and the words, and the two hub records a file never
|
|
93
|
+
* supplies (#10898 D5, #11707 D9).
|
|
94
|
+
*/
|
|
95
|
+
const NOT_FIELDS = new Set(["sections", "type", "slug", "locale", LIVE_SOURCE_KEY, WRITTEN_FROM_KEY]);
|
|
87
96
|
/** `EDITORIAL_FIELDS` (api-content-write `derive-publish.ts`): the editorial structure publish's repair builds. */
|
|
88
97
|
const EDITORIAL_STRUCTURE_FIELDS = ["author", "tags", "order", "parent"];
|
|
89
98
|
/** The adapter's locale shape (`BCP47_RE` in its `mdx/adapter.ts`). */
|
|
@@ -532,7 +541,7 @@ function retryAfterSeconds(header) {
|
|
|
532
541
|
? seconds
|
|
533
542
|
: RATE_LIMIT_WAIT_MAX_S;
|
|
534
543
|
}
|
|
535
|
-
async function call(t, method, url, body
|
|
544
|
+
async function call(t, method, url, body) {
|
|
536
545
|
for (let retry = 0;; retry++) {
|
|
537
546
|
let response;
|
|
538
547
|
try {
|
|
@@ -541,10 +550,6 @@ async function call(t, method, url, body, ifMatch) {
|
|
|
541
550
|
headers: {
|
|
542
551
|
authorization: `Bearer ${t.key}`,
|
|
543
552
|
...(body !== undefined && { "content-type": "application/json" }),
|
|
544
|
-
// #10264 — the version rides `x-draft-version`; `if-match` rides
|
|
545
|
-
// beside it for one release so this importer still saves against an
|
|
546
|
-
// API that predates the new header (the route prefers the new one).
|
|
547
|
-
...(ifMatch !== undefined && { "x-draft-version": ifMatch, "if-match": ifMatch }),
|
|
548
553
|
},
|
|
549
554
|
...(body !== undefined && { body: JSON.stringify(body) }),
|
|
550
555
|
// A redirect would re-send the key and the body to another URL.
|
|
@@ -596,126 +601,121 @@ function refusedAnswer(at, answer) {
|
|
|
596
601
|
}
|
|
597
602
|
/**
|
|
598
603
|
* A success answered for another locale: the API does not serve `locale`. A
|
|
599
|
-
* success with no locale at all is not the API's answer shape: that page
|
|
604
|
+
* success with no locale at all is not the API's answer shape: that page
|
|
605
|
+
* fails. A read names its locale at `data.locale`, a save at
|
|
606
|
+
* `data.address.locale` (#11843 D1).
|
|
600
607
|
*/
|
|
601
|
-
function wrongLocale(at, answer, locale) {
|
|
602
|
-
if ("network" in answer
|
|
608
|
+
function wrongLocale(at, answer, locale, of) {
|
|
609
|
+
if ("network" in answer)
|
|
610
|
+
return undefined;
|
|
611
|
+
const address = answer.data["address"];
|
|
612
|
+
const answered = of === "read"
|
|
613
|
+
? answer.data["locale"]
|
|
614
|
+
: address !== null && typeof address === "object"
|
|
615
|
+
? address["locale"]
|
|
616
|
+
: undefined;
|
|
617
|
+
if (answered === locale)
|
|
603
618
|
return undefined;
|
|
604
|
-
if (typeof
|
|
619
|
+
if (typeof answered !== "string") {
|
|
605
620
|
return failed(at, `${answer.status} unknown`);
|
|
606
621
|
}
|
|
607
622
|
return failed(at, `the API does not serve locale ${locale}`, `not sent: the API does not serve locale ${locale}`);
|
|
608
623
|
}
|
|
609
|
-
/**
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
624
|
+
/**
|
|
625
|
+
* Records a save carries forward when the file sends none (#11843 D4): never
|
|
626
|
+
* compared unless the file sends it, or every run would save again. The
|
|
627
|
+
* live-source mark is never kept, so never compared.
|
|
628
|
+
*/
|
|
629
|
+
const CARRIED_RECORDS = [WRITTEN_FROM_KEY, "pageChange", "reader", "narrator"];
|
|
630
|
+
/** The stored content's fields, as compared with the fields a save sends. */
|
|
631
|
+
function storedFields(stored, fields) {
|
|
632
|
+
if (stored === null || typeof stored !== "object" || Array.isArray(stored))
|
|
633
|
+
return {};
|
|
634
|
+
const { type: _t, slug: _s, body: _b, locale: _l, [LIVE_SOURCE_KEY]: _m, ...rest } = stored;
|
|
635
|
+
for (const key of CARRIED_RECORDS)
|
|
636
|
+
if (!Object.hasOwn(fields, key))
|
|
637
|
+
delete rest[key];
|
|
614
638
|
return rest;
|
|
615
639
|
}
|
|
616
|
-
|
|
640
|
+
/**
|
|
641
|
+
* Whether the stored body holds the page's words (#11843 D4): exactly, or —
|
|
642
|
+
* for a layout — after a lead, as the earlier importer stored it.
|
|
643
|
+
*/
|
|
644
|
+
function sameWords(storedBody, save) {
|
|
645
|
+
if (typeof storedBody !== "string")
|
|
646
|
+
return false;
|
|
647
|
+
return (storedBody === save.body ||
|
|
648
|
+
(save.layout !== undefined && storedBody.endsWith(`\n\n${save.body}`)));
|
|
649
|
+
}
|
|
650
|
+
async function writePage(t, page, locale, save, publicTags) {
|
|
617
651
|
const { root, path, type, slug } = page;
|
|
618
|
-
const pagePath = `${t.base}/content/${encodeURIComponent(type)}/${encodeURIComponent(slug)}`;
|
|
619
652
|
const query = `?locale=${encodeURIComponent(locale)}`;
|
|
620
|
-
const address = `${
|
|
653
|
+
const address = `${t.base}/content/${encodeURIComponent(type)}/${encodeURIComponent(slug)}${query}`;
|
|
654
|
+
const document = type === DOCUMENT_TYPE;
|
|
621
655
|
// The route's `statusOf`: anything but `draft` has a Live version.
|
|
622
656
|
let live = false;
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
const outcome = (result, layoutOnly = false) => ({
|
|
657
|
+
const sent = { ...save.fields, type };
|
|
658
|
+
const outcome = (result, stored, layoutOnly = false) => ({
|
|
626
659
|
outcome: { root, path, result, type, slug, ...(layoutOnly && { layoutOnly: true }) },
|
|
627
660
|
live,
|
|
628
|
-
stored,
|
|
629
|
-
sent,
|
|
661
|
+
...(stored !== undefined && { stored }),
|
|
630
662
|
});
|
|
631
|
-
//
|
|
632
|
-
//
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
663
|
+
// #11843 D1 — one save: `save_document` for a Document, else `save_page`,
|
|
664
|
+
// with the sections as a layout's words and `{ body }` for the rest.
|
|
665
|
+
const write = (version, structureToken) => document
|
|
666
|
+
? call(t, "POST", `${t.base}/documents/save`, {
|
|
667
|
+
address: { type, slug, locale },
|
|
668
|
+
version,
|
|
669
|
+
fields: save.fields,
|
|
670
|
+
words: { body: save.body },
|
|
671
|
+
})
|
|
672
|
+
: call(t, "PUT", address, {
|
|
673
|
+
version,
|
|
638
674
|
structureToken,
|
|
639
|
-
|
|
675
|
+
fields: save.fields,
|
|
676
|
+
words: save.layout === undefined ? { body: save.body } : save.layout.sections,
|
|
640
677
|
});
|
|
641
|
-
let put = await writeLayout();
|
|
642
|
-
// #11749 D2 — the hub refuses a layout on a live tip and names the remedy:
|
|
643
|
-
// save a draft (the same words, under the version read), then write the
|
|
644
|
-
// layout once more. A save carries the structure token forward (§1).
|
|
645
|
-
const redraft = version !== undefined &&
|
|
646
|
-
!("network" in put) &&
|
|
647
|
-
put.status === 409 &&
|
|
648
|
-
put.code === "draft_is_live";
|
|
649
|
-
if (redraft) {
|
|
650
|
-
const saved = await call(t, "PATCH", address, content, version);
|
|
651
|
-
if ("network" in saved || saved.status !== 200)
|
|
652
|
-
return refusedAnswer(page, saved);
|
|
653
|
-
stored = saved.data["content"];
|
|
654
|
-
sent = true;
|
|
655
|
-
const mismatch = wrongLocale(page, saved, locale);
|
|
656
|
-
if (mismatch !== undefined)
|
|
657
|
-
return mismatch;
|
|
658
|
-
put = await writeLayout();
|
|
659
|
-
}
|
|
660
|
-
if ("network" in put || put.status !== 200)
|
|
661
|
-
return refusedAnswer(page, put);
|
|
662
|
-
// #10804 D6 — with no token the hub writes the layout (or refuses a
|
|
663
|
-
// live tip), so a dry run's `written: false` never makes it unchanged.
|
|
664
|
-
const layoutOnly = result === "unchanged" &&
|
|
665
|
-
(redraft || structureToken === null || put.data["written"] === true);
|
|
666
|
-
return (wrongLocale(page, put, locale) ??
|
|
667
|
-
outcome(layoutOnly ? "updated" : result, layoutOnly));
|
|
668
|
-
};
|
|
669
678
|
for (let reread = false;; reread = true) {
|
|
670
679
|
const read = await call(t, "GET", address);
|
|
671
680
|
if ("network" in read)
|
|
672
681
|
return refusedAnswer(page, read);
|
|
682
|
+
let version = null;
|
|
683
|
+
let structureToken = null;
|
|
684
|
+
let layoutOnly = false;
|
|
673
685
|
if (read.status === 200) {
|
|
674
|
-
const mismatch = wrongLocale(page, read, locale);
|
|
686
|
+
const mismatch = wrongLocale(page, read, locale, "read");
|
|
675
687
|
if (mismatch !== undefined)
|
|
676
688
|
return mismatch;
|
|
677
|
-
const
|
|
678
|
-
if (typeof
|
|
689
|
+
const readVersion = read.data["version"];
|
|
690
|
+
if (typeof readVersion !== "string")
|
|
679
691
|
return failed(page, "200 unknown");
|
|
692
|
+
version = readVersion;
|
|
680
693
|
live = read.data["status"] !== "draft";
|
|
681
694
|
const token = read.data["structureToken"];
|
|
682
|
-
|
|
683
|
-
stored = read.data["content"];
|
|
684
|
-
// #
|
|
685
|
-
const
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
const saved = await call(t, "PATCH", address, content, version);
|
|
693
|
-
if ("network" in saved || saved.status !== 200)
|
|
694
|
-
return refusedAnswer(page, saved);
|
|
695
|
-
stored = saved.data["content"];
|
|
696
|
-
sent = true;
|
|
697
|
-
// A save carries the structure token forward (#10330 D5).
|
|
698
|
-
return (wrongLocale(page, saved, locale) ?? done("updated", structureToken));
|
|
695
|
+
structureToken = typeof token === "string" ? token : null;
|
|
696
|
+
const stored = read.data["content"];
|
|
697
|
+
// #11843 D4 — one comparison, before any write.
|
|
698
|
+
const sameFields = canonical(compared(storedFields(stored, save.fields), sent, publicTags)) ===
|
|
699
|
+
canonical(compared(save.fields, sent, publicTags));
|
|
700
|
+
const sameBody = sameWords(stored?.["body"], save);
|
|
701
|
+
const sameLayout = save.layout === undefined || canonical(read.data["structure"]) === canonical(save.layout);
|
|
702
|
+
if (sameFields && sameBody && sameLayout)
|
|
703
|
+
return outcome("unchanged");
|
|
704
|
+
layoutOnly = sameFields && sameBody;
|
|
699
705
|
}
|
|
700
|
-
if (read.status !== 404 || reread)
|
|
706
|
+
else if (read.status !== 404 || reread) {
|
|
701
707
|
return refusedAnswer(page, read);
|
|
702
|
-
const created = await call(t, "POST", `${t.base}/content`, {
|
|
703
|
-
...content,
|
|
704
|
-
locale,
|
|
705
|
-
});
|
|
706
|
-
if ("network" in created)
|
|
707
|
-
return refusedAnswer(page, created);
|
|
708
|
-
if (created.status === 201) {
|
|
709
|
-
stored = created.data["content"];
|
|
710
|
-
sent = true;
|
|
711
|
-
return wrongLocale(page, created, locale) ?? done("created");
|
|
712
|
-
}
|
|
713
|
-
// 409 slug_taken: another page holds this page's registry link (#10268
|
|
714
|
-
// D5) — reported as it is, since a re-read at this address finds nothing.
|
|
715
|
-
// Any other 409: created by someone else since the read — read it once more.
|
|
716
|
-
if (created.status !== 409 || created.code === "slug_taken") {
|
|
717
|
-
return refusedAnswer(page, created);
|
|
718
708
|
}
|
|
709
|
+
const saved = await write(version, structureToken);
|
|
710
|
+
if ("network" in saved)
|
|
711
|
+
return refusedAnswer(page, saved);
|
|
712
|
+
// #11843 D5 — created by someone else since the read: read it once more.
|
|
713
|
+
if (version === null && saved.status === 409 && saved.code === "stale" && !reread)
|
|
714
|
+
continue;
|
|
715
|
+
if (saved.status !== (version === null ? 201 : 200))
|
|
716
|
+
return refusedAnswer(page, saved);
|
|
717
|
+
return (wrongLocale(page, saved, locale, "save") ??
|
|
718
|
+
outcome(version === null ? "created" : "updated", saved.data["fields"], layoutOnly));
|
|
719
719
|
}
|
|
720
720
|
}
|
|
721
721
|
// ── The report (D6) ─────────────────────────────────────────────────────────
|
|
@@ -1060,19 +1060,19 @@ function adapterReason(err, stage = "adapter") {
|
|
|
1060
1060
|
return `${stage}: ${message.replace(/\s+/g, " ").trim().slice(0, ADAPTER_REASON_MAX)}`;
|
|
1061
1061
|
}
|
|
1062
1062
|
/**
|
|
1063
|
-
* What the page
|
|
1064
|
-
* the
|
|
1065
|
-
*
|
|
1063
|
+
* What the page saves (#10534, #11843 D1–D3): its fields — the frontmatter
|
|
1064
|
+
* less the keys the address and the words own, and the two hub records a file
|
|
1065
|
+
* never supplies (#10898 D5, #11707 D9) — and, with `sections` and a codec,
|
|
1066
|
+
* the sections as its layout and the codec's words as the body the hub will
|
|
1067
|
+
* build from them; else the file's body. The text before a page's first
|
|
1068
|
+
* section is not sent: nothing renders it (D3). Both come from one array, its
|
|
1069
|
+
* inline HTML converted (#10804 D2).
|
|
1066
1070
|
*/
|
|
1067
1071
|
function convert(source, codec) {
|
|
1068
|
-
const
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
return {
|
|
1073
|
-
content: { ...source.frontmatter, body: source.body },
|
|
1074
|
-
notCarried: [],
|
|
1075
|
-
};
|
|
1072
|
+
const fields = Object.fromEntries(Object.entries(source.frontmatter).filter(([key]) => !NOT_FIELDS.has(key)));
|
|
1073
|
+
const authored = source.frontmatter["sections"];
|
|
1074
|
+
if (!Array.isArray(authored) || authored.length === 0 || codec === undefined) {
|
|
1075
|
+
return { fields, body: source.body, notCarried: [] };
|
|
1076
1076
|
}
|
|
1077
1077
|
const { sections, notCarried } = sectionsWithoutHtml(authored);
|
|
1078
1078
|
let words;
|
|
@@ -1082,15 +1082,7 @@ function convert(source, codec) {
|
|
|
1082
1082
|
catch (err) {
|
|
1083
1083
|
return { reason: adapterReason(err, "codec") };
|
|
1084
1084
|
}
|
|
1085
|
-
|
|
1086
|
-
return {
|
|
1087
|
-
content: {
|
|
1088
|
-
...frontmatter,
|
|
1089
|
-
body: lead === "" ? words : `${lead}\n\n${words}`,
|
|
1090
|
-
},
|
|
1091
|
-
layout: { kind: "sections", sections },
|
|
1092
|
-
notCarried,
|
|
1093
|
-
};
|
|
1085
|
+
return { fields, body: words, layout: { kind: "sections", sections }, notCarried };
|
|
1094
1086
|
}
|
|
1095
1087
|
export async function importMdx(opts) {
|
|
1096
1088
|
const defaultLocale = opts.defaultLocale ?? "en";
|
|
@@ -1114,7 +1106,7 @@ export async function importMdx(opts) {
|
|
|
1114
1106
|
const rules = opts.adapters.siteFields;
|
|
1115
1107
|
// #10701 D3 — one route path holds one page, so an editorial index the run
|
|
1116
1108
|
// will write supersedes the content page of its type at the surface's own
|
|
1117
|
-
// slug (the scaffold's teaser), which the
|
|
1109
|
+
// slug (the scaffold's teaser), which the save would refuse at `address.slug`.
|
|
1118
1110
|
// Any other slug of the type has a link of its own (#10805 D5).
|
|
1119
1111
|
const indexTypes = new Set(parseFrontmatter === undefined
|
|
1120
1112
|
? []
|
|
@@ -1149,10 +1141,11 @@ export async function importMdx(opts) {
|
|
|
1149
1141
|
// first in processing order wins and the rest fail. Two pages of different
|
|
1150
1142
|
// types may share a slug (#10268 D7): the store addresses by type too.
|
|
1151
1143
|
const addresses = new Map();
|
|
1152
|
-
// #11793 D7 (Q7) — an older site's packages cannot say which
|
|
1153
|
-
// out in sections, so its pages without sections are
|
|
1144
|
+
// #11793 D7 (Q7), #11843 D6 — an older site's packages cannot say which
|
|
1145
|
+
// types are laid out in sections, so its pages without sections are sent
|
|
1146
|
+
// as their body, and the hub refuses one of a sections type.
|
|
1154
1147
|
if (opts.adapters.laidOutInSections === undefined) {
|
|
1155
|
-
onLine("import-mdx: the site's packages cannot say which page types are laid out in sections; pages without sections
|
|
1148
|
+
onLine("import-mdx: the site's packages cannot say which page types are laid out in sections; pages without sections are sent as their body; the hub refuses one of a type laid out in sections");
|
|
1156
1149
|
}
|
|
1157
1150
|
let halt;
|
|
1158
1151
|
let publishRefused;
|
|
@@ -1216,36 +1209,29 @@ export async function importMdx(opts) {
|
|
|
1216
1209
|
}
|
|
1217
1210
|
const authored = source.frontmatter["sections"];
|
|
1218
1211
|
const hasSections = Array.isArray(authored) && authored.length > 0;
|
|
1219
|
-
|
|
1220
|
-
//
|
|
1221
|
-
|
|
1222
|
-
|
|
1212
|
+
const sectionsRule = opts.adapters.laidOutInSections?.(page.type);
|
|
1213
|
+
// #11843 D6, D10 — an editorial page's words, and a document's, are its
|
|
1214
|
+
// body: a file of either with sections is never stored as markers with no layout.
|
|
1215
|
+
if (hasSections && (page.type === DOCUMENT_TYPE || sectionsRule === false)) {
|
|
1216
|
+
fail(page.type === DOCUMENT_TYPE
|
|
1217
|
+
? "sections: a Document's words are its body (save_document takes { body }), and this file has sections; move their words into the body"
|
|
1218
|
+
: `sections: a ${page.type} page's words are its body, and this file has sections; move their words into the body`);
|
|
1219
|
+
continue;
|
|
1220
|
+
}
|
|
1221
|
+
// #11793 D7 — a page laid out in sections is never stored with no layout,
|
|
1222
|
+
// and (#11843) a file's sections are never dropped: each fails here,
|
|
1223
|
+
// naming why, before anything is sent for it.
|
|
1224
|
+
if (converted.layout === undefined && (hasSections || sectionsRule === true)) {
|
|
1223
1225
|
fail(hasSections
|
|
1224
1226
|
? `sections: the site's ${VALIDATION_PACKAGE} has no words codec — update its dependencies and re-run`
|
|
1225
1227
|
: `sections: a ${page.type} page is laid out in sections, and this file has none — move its words into frontmatter sections`);
|
|
1226
1228
|
continue;
|
|
1227
1229
|
}
|
|
1228
|
-
// #10898 D5 — a file never supplies the mark; the importer computes it.
|
|
1229
|
-
// #11707 D9 — nor the written-from record: a file is never its source.
|
|
1230
|
-
const { [LIVE_SOURCE_KEY]: _fileMark, [WRITTEN_FROM_KEY]: _fileRecord, ...words } = converted.content;
|
|
1231
|
-
const body = words["body"];
|
|
1232
|
-
converted.content =
|
|
1233
|
-
opts.liveSource === true && typeof body === "string"
|
|
1234
|
-
? {
|
|
1235
|
-
...words,
|
|
1236
|
-
[LIVE_SOURCE_KEY]: {
|
|
1237
|
-
bodySha256: createHash("sha256").update(body, "utf8").digest("hex"),
|
|
1238
|
-
},
|
|
1239
|
-
}
|
|
1240
|
-
: words;
|
|
1241
1230
|
if (converted.notCarried.length > 0) {
|
|
1242
1231
|
onLine(`${outcomePath(page)}: inline HTML not carried — ${converted.notCarried.join(", ")} (the layout holds no HTML; their text is kept)`);
|
|
1243
1232
|
}
|
|
1244
|
-
if (converted.layout === undefined && hasSections) {
|
|
1245
|
-
onLine(`${page.path}: keeps its words in sections — the site's ${VALIDATION_PACKAGE} has no words codec; update its dependencies and re-run`);
|
|
1246
|
-
}
|
|
1247
1233
|
// #10804 D5 — a layout the hub would refuse fails here, in a dry run and
|
|
1248
|
-
// under --apply alike, before
|
|
1234
|
+
// under --apply alike, before anything is saved.
|
|
1249
1235
|
const refusal = converted.layout === undefined
|
|
1250
1236
|
? undefined
|
|
1251
1237
|
: layoutRefusal(converted.layout);
|
|
@@ -1253,34 +1239,25 @@ export async function importMdx(opts) {
|
|
|
1253
1239
|
fail(`layout: ${refusal}`);
|
|
1254
1240
|
continue;
|
|
1255
1241
|
}
|
|
1256
|
-
const result = await writePage(t, page, defaultLocale, converted
|
|
1242
|
+
const result = await writePage(t, page, defaultLocale, converted, rules?.publicPageTags);
|
|
1257
1243
|
halt = result.halt;
|
|
1258
|
-
// #10898
|
|
1259
|
-
//
|
|
1260
|
-
|
|
1261
|
-
if (opts.liveSource === true &&
|
|
1262
|
-
result.sent === true &&
|
|
1263
|
-
result.stored !== null &&
|
|
1264
|
-
typeof result.stored === "object" &&
|
|
1265
|
-
!Object.hasOwn(result.stored, LIVE_SOURCE_KEY)) {
|
|
1266
|
-
onLine(`${outcomePath(page)}: not kept by the hub: ${LIVE_SOURCE_KEY} (the hub predates the live-source mark; update it and re-run)`);
|
|
1267
|
-
}
|
|
1268
|
-
// #10898 D6 — what the hub's publish gate will answer for these words.
|
|
1269
|
-
const check = opts.liveSource === true ? opts.adapters.publishCheck : undefined;
|
|
1244
|
+
// #10898 D6, #11843 D7 — what the hub's publish gate will answer for the
|
|
1245
|
+
// page as it is now stored, with no live-source mark.
|
|
1246
|
+
const check = opts.adapters.publishCheck;
|
|
1270
1247
|
if (check !== undefined && !("reason" in result.outcome)) {
|
|
1271
|
-
const verdict = check(page.type, converted.
|
|
1248
|
+
const verdict = check(page.type, { ...converted.fields, type: page.type, slug: page.slug, body: converted.body }, converted.layout);
|
|
1272
1249
|
if (verdict !== undefined)
|
|
1273
1250
|
result.outcome = { ...result.outcome, publishVerdict: verdict };
|
|
1274
1251
|
}
|
|
1275
1252
|
// #10806 D4 — an older hub strips what it has no member for; say so.
|
|
1276
|
-
// An answer that carries no
|
|
1253
|
+
// An answer that carries no fields says nothing about what was kept.
|
|
1277
1254
|
const dropped = rules === undefined ||
|
|
1278
1255
|
page.root !== "editorial" ||
|
|
1279
1256
|
"reason" in result.outcome ||
|
|
1280
1257
|
result.stored === null ||
|
|
1281
1258
|
typeof result.stored !== "object"
|
|
1282
1259
|
? []
|
|
1283
|
-
: notKept(converted.
|
|
1260
|
+
: notKept({ ...converted.fields, type: page.type }, result.stored, rules);
|
|
1284
1261
|
if (dropped.length > 0) {
|
|
1285
1262
|
onLine(`${page.path}: not kept by the hub: ${dropped.join(", ")} (the hub predates site fields; update it and re-run)`);
|
|
1286
1263
|
}
|
|
@@ -1328,12 +1305,12 @@ export async function importMdx(opts) {
|
|
|
1328
1305
|
};
|
|
1329
1306
|
}
|
|
1330
1307
|
/**
|
|
1331
|
-
* The hub's publish gate over a
|
|
1332
|
-
*
|
|
1333
|
-
*
|
|
1334
|
-
*
|
|
1335
|
-
*
|
|
1336
|
-
* so only the rest block.
|
|
1308
|
+
* The hub's publish gate over a page, as the site's contract reads it: the
|
|
1309
|
+
* page's words checked against its type's template and the structure
|
|
1310
|
+
* publish's repair would build — the layout when the page converts, an
|
|
1311
|
+
* editorial template's frontmatter quartet, else none. No live-source split
|
|
1312
|
+
* is applied: no save keeps the mark (#11843 D7). Publish repairs every
|
|
1313
|
+
* `script` finding, so only the rest block.
|
|
1337
1314
|
*/
|
|
1338
1315
|
export function publishCheckOf(members) {
|
|
1339
1316
|
return (type, content, layout) => {
|
|
@@ -1351,13 +1328,13 @@ export function publishCheckOf(members) {
|
|
|
1351
1328
|
frontmatter: Object.fromEntries(EDITORIAL_STRUCTURE_FIELDS.filter((field) => content[field] !== undefined).map((field) => [field, content[field]])),
|
|
1352
1329
|
}
|
|
1353
1330
|
: null);
|
|
1354
|
-
const report = members.
|
|
1331
|
+
const report = members.checkPage({
|
|
1355
1332
|
template,
|
|
1356
1333
|
title: text("title"),
|
|
1357
1334
|
description: text("description"),
|
|
1358
1335
|
slug: text("slug"),
|
|
1359
1336
|
body: text("body"),
|
|
1360
|
-
}, structure)
|
|
1337
|
+
}, structure);
|
|
1361
1338
|
const blocking = report.issues.filter((issue) => issue.fixer !== "script");
|
|
1362
1339
|
return blocking.length === 0
|
|
1363
1340
|
? { publishable: true, advisory: report.advisory ?? [] }
|
|
@@ -1447,8 +1424,8 @@ export async function loadSiteMdxAdapter(siteRoot) {
|
|
|
1447
1424
|
// Not resolvable from the adapter: no parser.
|
|
1448
1425
|
}
|
|
1449
1426
|
// #10898 D6 — the site's own page-type registry, beside its contract; a
|
|
1450
|
-
// validation package
|
|
1451
|
-
//
|
|
1427
|
+
// validation package with no content check, or no registry, leaves the dry
|
|
1428
|
+
// run's publish verdict unchecked, and the run says so.
|
|
1452
1429
|
let registry;
|
|
1453
1430
|
try {
|
|
1454
1431
|
const path = createRequire(entry).resolve(PAGE_TYPES_PACKAGE);
|
|
@@ -1457,7 +1434,7 @@ export async function loadSiteMdxAdapter(siteRoot) {
|
|
|
1457
1434
|
catch {
|
|
1458
1435
|
// Not resolvable from the adapter: no registry.
|
|
1459
1436
|
}
|
|
1460
|
-
const { checkPage,
|
|
1437
|
+
const { checkPage, PAGE_TEMPLATES: templates } = validation;
|
|
1461
1438
|
return {
|
|
1462
1439
|
...mod,
|
|
1463
1440
|
...(typeof codec === "function" && {
|
|
@@ -1475,13 +1452,11 @@ export async function loadSiteMdxAdapter(siteRoot) {
|
|
|
1475
1452
|
},
|
|
1476
1453
|
}),
|
|
1477
1454
|
...(typeof checkPage === "function" &&
|
|
1478
|
-
typeof liveSourceReport === "function" &&
|
|
1479
1455
|
templates !== null &&
|
|
1480
1456
|
typeof templates === "object" &&
|
|
1481
1457
|
Array.isArray(registry) && {
|
|
1482
1458
|
publishCheck: publishCheckOf({
|
|
1483
1459
|
checkPage: checkPage,
|
|
1484
|
-
liveSourceReport: liveSourceReport,
|
|
1485
1460
|
templates: templates,
|
|
1486
1461
|
registry: registry,
|
|
1487
1462
|
}),
|
|
@@ -28,24 +28,17 @@ export interface MigrateContentOptions {
|
|
|
28
28
|
onLine?: (line: string) => void;
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
* A fetch that sends `GET`s through `inner` and never sends a write
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* address, and a `PUT` to that address's `/structure` URL answers
|
|
39
|
-
* `written: true` when its body's `structure` is not `isDeepStrictEqual` to
|
|
40
|
-
* it — the hub's own comparison. Any other `PUT` (an equal layout, an address
|
|
41
|
-
* never read, a read with no `structure` member, no string body, a `Request`
|
|
42
|
-
* input) answers `written: false`. It never answers 409: a live tip with a
|
|
43
|
-
* changed layout is planned `update`, what `--apply` reports after its
|
|
44
|
-
* re-draft. The memory lasts one run, as the transport does.
|
|
31
|
+
* A fetch that sends `GET`s through `inner` and never sends a write (#11843
|
|
32
|
+
* D9): a `PUT` or `POST` is answered locally — `201` when its JSON body's
|
|
33
|
+
* `version` is `null`, else `200` — with the members of a save's answer the
|
|
34
|
+
* importer reads (`data.address.locale`, and `data.locale` for the Language
|
|
35
|
+
* pass). A `PATCH`, or any other method, throws, so a stray call on a retired
|
|
36
|
+
* route is visible in a dry run too. The importer decides `created`,
|
|
37
|
+
* `updated` and `unchanged` from its read alone, before it writes.
|
|
45
38
|
*/
|
|
46
39
|
export declare function readOnlyFetch(inner: typeof globalThis.fetch, locale: string): typeof globalThis.fetch;
|
|
47
40
|
/** What a dry run prints when the site's contract cannot give a verdict. */
|
|
48
|
-
export declare const PUBLISH_NOT_CHECKED = "publish: not checked \u2014 the site's @working-theory/validation has no
|
|
41
|
+
export declare const PUBLISH_NOT_CHECKED = "publish: not checked \u2014 the site's @working-theory/validation has no content check; update the site's dependencies and re-run";
|
|
49
42
|
export declare function migrateContent(opts: MigrateContentOptions): Promise<{
|
|
50
43
|
result: ImportMdxResult;
|
|
51
44
|
exitCode: 0 | 1;
|
|
@@ -60,5 +53,5 @@ export interface MigrateContentArgs {
|
|
|
60
53
|
languageSeed: string | undefined;
|
|
61
54
|
help: boolean;
|
|
62
55
|
}
|
|
63
|
-
export declare const MIGRATE_CONTENT_HELP = "create-ailk migrate-content \u2014 import an existing site's pages into its workspace.\n\nUsage:\n AILK_AGENT_KEY=<key> create-ailk migrate-content [<dir>] [--apply] [--api-url <origin>] [--workspace <wksp_id>] [--language-seed <file>]\n\nArguments:\n <dir> The site. Defaults to the current dir.\n\nOptions:\n --apply Write the pages. Without it the command reads the\n workspace, prints what it would do, and writes\n nothing.\n --api-url <origin> The API origin that holds the workspace \u2014 on a\n spoke, its hub's. Else AILK_API_URL. https: only\n (http: on localhost or 127.0.0.1).\n --workspace <wksp_id> The workspace the pages are written to. Else\n AILK_WORKSPACE_ID.\n --language-seed <file> A Language seed file (language/<entity>.json).\n Each of its topics becomes one Topic holding all\n its keywords. Its items are not read.\n -h, --help Show this help.\n\nEach content/en/<Type>/<slug>.mdx page (and each legacy\ncontent/<Type>/<slug>.mdx) is written to the workspace as a draft through\nthe API's content routes, with the agent key, which is read from\nAILK_AGENT_KEY only and needs the content-edit grant. Nothing is published,\nso the live site does not change. The site needs no .ailk-site-manifest.json\nand may be a spoke; its dependencies must be installed. A page whose\nfrontmatter carries sections is converted: its words are written to the\npage's Markdown and its sections to its layout.\n\nEach FAQ item and glossary-index term becomes one Language item of its kind,\nset Live when the run creates it, and its section pins the items in the\norder the file lists them. A question on several pages is one item, with\nthe FAQ page's words (the glossary page's, for a term). Lines prefixed\nlanguage: report each item, and each page the database read will not show\nas its file does. An API with no Language collection leaves them inline.\n\nWith --language-seed, each topic in the seed file is written after the\npages as one Topic: its name, its pillar page, and every keyword with its\nmonthly searches and as-of date, its primary marked. A Topic the workspace\nalready holds keeps its spelling, notes and newer numbers, and gains what it\nlacks. Lines prefixed language: topic/ report each one; a second --apply\nreports every topic unchanged. A seed file that is not readable, or whose\ntopics the hub would refuse, is refused before anything is sent.\n\nWhen the site has apps/web/content, each blog post and docs page in it is\nwritten too: apps/web/content/en/blog/<slug>.mdx (or <slug>/index.mdx) as a\nBlogPosting, or one series down, blog/<series>/<post>.mdx, as a BlogPosting\nwhose parent is the series; the same under docs as a DocsDetail, and each\ndirectory's own index.mdx as its BlogList or DocsList index. A file the walk\nskips is listed with the rule it failed. Their lines are prefixed\neditorial: \u2014 each outcome's root is content or editorial.\n\nA dry run prints create, update, unchanged, skipped or failed per page. It\ncannot see a write the API would refuse at --apply (a conflict
|
|
56
|
+
export declare const MIGRATE_CONTENT_HELP = "create-ailk migrate-content \u2014 import an existing site's pages into its workspace.\n\nUsage:\n AILK_AGENT_KEY=<key> create-ailk migrate-content [<dir>] [--apply] [--api-url <origin>] [--workspace <wksp_id>] [--language-seed <file>]\n\nArguments:\n <dir> The site. Defaults to the current dir.\n\nOptions:\n --apply Write the pages. Without it the command reads the\n workspace, prints what it would do, and writes\n nothing.\n --api-url <origin> The API origin that holds the workspace \u2014 on a\n spoke, its hub's. Else AILK_API_URL. https: only\n (http: on localhost or 127.0.0.1).\n --workspace <wksp_id> The workspace the pages are written to. Else\n AILK_WORKSPACE_ID.\n --language-seed <file> A Language seed file (language/<entity>.json).\n Each of its topics becomes one Topic holding all\n its keywords. Its items are not read.\n -h, --help Show this help.\n\nEach content/en/<Type>/<slug>.mdx page (and each legacy\ncontent/<Type>/<slug>.mdx) is written to the workspace as a draft through\nthe API's content routes, with the agent key, which is read from\nAILK_AGENT_KEY only and needs the content-edit grant. Nothing is published,\nso the live site does not change. The site needs no .ailk-site-manifest.json\nand may be a spoke; its dependencies must be installed. A page whose\nfrontmatter carries sections is converted: its words are written to the\npage's Markdown and its sections to its layout.\n\nEach FAQ item and glossary-index term becomes one Language item of its kind,\nset Live when the run creates it, and its section pins the items in the\norder the file lists them. A question on several pages is one item, with\nthe FAQ page's words (the glossary page's, for a term). Lines prefixed\nlanguage: report each item, and each page the database read will not show\nas its file does. An API with no Language collection leaves them inline.\n\nWith --language-seed, each topic in the seed file is written after the\npages as one Topic: its name, its pillar page, and every keyword with its\nmonthly searches and as-of date, its primary marked. A Topic the workspace\nalready holds keeps its spelling, notes and newer numbers, and gains what it\nlacks. Lines prefixed language: topic/ report each one; a second --apply\nreports every topic unchanged. A seed file that is not readable, or whose\ntopics the hub would refuse, is refused before anything is sent.\n\nWhen the site has apps/web/content, each blog post and docs page in it is\nwritten too: apps/web/content/en/blog/<slug>.mdx (or <slug>/index.mdx) as a\nBlogPosting, or one series down, blog/<series>/<post>.mdx, as a BlogPosting\nwhose parent is the series; the same under docs as a DocsDetail, and each\ndirectory's own index.mdx as its BlogList or DocsList index. A file the walk\nskips is listed with the rule it failed. Their lines are prefixed\neditorial: \u2014 each outcome's root is content or editorial.\n\nA dry run prints create, update, unchanged, skipped or failed per page. It\ncannot see a write the API would refuse at --apply (a conflict, a server\nerror, or a page whose content fails its page type, which the save refuses\n422 invalid and stores nothing; fix its file and re-run). An update whose\nwords already match the workspace prints \"update \u2014 layout only\". A change to\na page that is live is saved as a new draft, so the live site does not\nchange until the page is published. --apply prints created, updated,\nunchanged, skipped or failed per page, so a re-run is safe. Exit 0 when no\npage failed, 1 when any did, 2 on a refusal (nothing is sent).\n\nNo page is written with a live-source mark, so a heading the page type's\ntemplate asks for and the page lacks stops its publish, as on any page. A\ndry run prints a publish line after each page: publishable, the advisory\nfindings the hub will list, or the status and findings that will stop the\npublish. The verdict is the site's installed @working-theory/validation's,\nnot the hub's; it sees no library-file finding and no layout the hub repairs\ndifferently. A site whose validation has no content check prints one\n\"publish: not checked\" line instead.\n";
|
|
64
57
|
export declare function parseMigrateContentArgs(argv: string[]): MigrateContentArgs;
|