@volvel/docs-engine 0.0.0-stage → 0.7.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/LICENSE +202 -0
- package/THIRD_PARTY_NOTICES.md +23036 -0
- package/dist/among.d.ts +44 -0
- package/dist/among.js +128 -0
- package/dist/changelog.d.ts +54 -0
- package/dist/changelog.js +88 -0
- package/dist/diataxis.d.ts +52 -0
- package/dist/diataxis.js +155 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +14 -0
- package/dist/ops.d.ts +111 -0
- package/dist/ops.js +529 -0
- package/dist/output.d.ts +57 -0
- package/dist/output.js +56 -0
- package/dist/package.d.ts +34 -0
- package/dist/package.js +129 -0
- package/dist/page.d.ts +75 -0
- package/dist/page.js +189 -0
- package/dist/redirects.d.ts +27 -0
- package/dist/redirects.js +79 -0
- package/dist/schema.d.ts +210 -0
- package/dist/schema.js +238 -0
- package/dist/search-query.d.ts +103 -0
- package/dist/search-query.js +197 -0
- package/dist/search.d.ts +17 -0
- package/dist/search.js +98 -0
- package/dist/set.d.ts +198 -0
- package/dist/set.js +566 -0
- package/dist/stack.d.ts +45 -0
- package/dist/stack.js +73 -0
- package/dist/workspace.d.ts +122 -0
- package/dist/workspace.js +207 -0
- package/package.json +34 -3
- package/README.md +0 -3
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { type DocIssue } from "./page.js";
|
|
2
|
+
import { ABOUT_KINDS, type AboutKind } from "./schema.js";
|
|
3
|
+
import { type BuildOptions, type DocSet } from "./set.js";
|
|
4
|
+
/**
|
|
5
|
+
* A workspace's documentation, worked out from its resources: which pages
|
|
6
|
+
* each docs app serves, and whether they hold together. The control plane
|
|
7
|
+
* runs this on every bundle before it is stored, and the CLI runs it when it
|
|
8
|
+
* builds, so a page that does not read, a link that leads nowhere and a term
|
|
9
|
+
* defined twice all stop a deploy and never reach a reader.
|
|
10
|
+
*
|
|
11
|
+
* It is given resources as plain objects and knows nothing else about them.
|
|
12
|
+
*/
|
|
13
|
+
/** A resource, as much of it as documentation needs. */
|
|
14
|
+
export interface ResourceLike {
|
|
15
|
+
kind: string;
|
|
16
|
+
/** The resource's key, which a rename keeps, if whoever gives it knows. */
|
|
17
|
+
key?: string | undefined;
|
|
18
|
+
path: string;
|
|
19
|
+
title?: string | null | undefined;
|
|
20
|
+
body: unknown;
|
|
21
|
+
/** When the resource last changed, if whoever gives it knows. A served page says it. */
|
|
22
|
+
updated?: string | Date | null | undefined;
|
|
23
|
+
}
|
|
24
|
+
/** An app that serves a folder of pages. */
|
|
25
|
+
export interface DocsApp {
|
|
26
|
+
/** The app's own path. */
|
|
27
|
+
path: string;
|
|
28
|
+
/** The app's key, which a rename keeps. Set where a bundle says it. */
|
|
29
|
+
key?: string;
|
|
30
|
+
title: string;
|
|
31
|
+
/** The folder of pages it serves: every page whose path is under it. */
|
|
32
|
+
docs: string;
|
|
33
|
+
/** The table its readers' answers to "Was this page helpful?" are kept in, when it asks. */
|
|
34
|
+
feedback?: string;
|
|
35
|
+
/** False when the site is not served: its pages and the app are kept. Absent means served. */
|
|
36
|
+
published?: false;
|
|
37
|
+
}
|
|
38
|
+
/** The one table of a workspace in which every docs site keeps its readers' answers. */
|
|
39
|
+
export declare const FEEDBACK_TABLE = "docs-feedback";
|
|
40
|
+
/**
|
|
41
|
+
* The columns of that table, and of what type: what the console makes, what a
|
|
42
|
+
* served site writes, and what a doc writer's deploy is held to.
|
|
43
|
+
*/
|
|
44
|
+
export declare const FEEDBACK_COLUMNS: {
|
|
45
|
+
readonly site_key: {
|
|
46
|
+
readonly type: "text";
|
|
47
|
+
readonly required: true;
|
|
48
|
+
readonly description: "The key of the site's app, which a rename keeps.";
|
|
49
|
+
};
|
|
50
|
+
readonly site: {
|
|
51
|
+
readonly type: "text";
|
|
52
|
+
readonly required: false;
|
|
53
|
+
readonly description: "The site's name when the reader said so.";
|
|
54
|
+
};
|
|
55
|
+
readonly page: {
|
|
56
|
+
readonly type: "text";
|
|
57
|
+
readonly required: true;
|
|
58
|
+
readonly description: "The page, by its path in the site.";
|
|
59
|
+
};
|
|
60
|
+
readonly helpful: {
|
|
61
|
+
readonly type: "boolean";
|
|
62
|
+
readonly required: true;
|
|
63
|
+
readonly description: "Whether it helped.";
|
|
64
|
+
};
|
|
65
|
+
readonly version: {
|
|
66
|
+
readonly type: "text";
|
|
67
|
+
readonly required: false;
|
|
68
|
+
readonly description: "The deployed version they read.";
|
|
69
|
+
};
|
|
70
|
+
readonly at: {
|
|
71
|
+
readonly type: "timestamp";
|
|
72
|
+
readonly required: false;
|
|
73
|
+
readonly description: "When they said so.";
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
/** Whether a table's body has exactly the feedback columns, of the same types. */
|
|
77
|
+
export declare function hasFeedbackColumns(body: unknown): boolean;
|
|
78
|
+
/** Whether a resource is the workspace's table of readers' answers, as it should be made. */
|
|
79
|
+
export declare const isFeedbackTable: (kind: string, path: string, body: unknown) => boolean;
|
|
80
|
+
/** The apps of a workspace that serve documentation. */
|
|
81
|
+
export declare function docsApps(resources: readonly ResourceLike[]): DocsApp[];
|
|
82
|
+
/** The pages a docs app serves, each by its path under the app's folder. */
|
|
83
|
+
export declare function pagesOf(app: Pick<DocsApp, "docs">, resources: readonly ResourceLike[]): {
|
|
84
|
+
path: string;
|
|
85
|
+
resource: ResourceLike;
|
|
86
|
+
}[];
|
|
87
|
+
/** The docs app a page belongs to, if any: the one whose folder holds it. */
|
|
88
|
+
export declare function appOf(apps: readonly DocsApp[], docPath: string): DocsApp | undefined;
|
|
89
|
+
/** Whether resources of a workspace say a resource is there, for `about:` and for a term that names one. */
|
|
90
|
+
export declare function resourceChecker(resources: readonly ResourceLike[]): NonNullable<BuildOptions["resource"]>;
|
|
91
|
+
export interface BuiltApp {
|
|
92
|
+
app: DocsApp;
|
|
93
|
+
set: DocSet;
|
|
94
|
+
issues: DocIssue[];
|
|
95
|
+
}
|
|
96
|
+
export interface WorkspaceOptions {
|
|
97
|
+
/** The product's own terms and topics. A tenant's page may use and extend them, and not take their names. */
|
|
98
|
+
product?: {
|
|
99
|
+
terms: readonly string[];
|
|
100
|
+
topics: readonly string[];
|
|
101
|
+
} | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* Whether a docs app has a picture, by the app's path and the picture's path
|
|
104
|
+
* under the app's folder of pages. Left out, pictures are not checked.
|
|
105
|
+
*/
|
|
106
|
+
asset?: ((app: string, file: string) => boolean) | undefined;
|
|
107
|
+
}
|
|
108
|
+
/** Reads a docs app's pages and builds its set. Each issue names its page by the page's path in the workspace. */
|
|
109
|
+
export declare function buildApp(app: DocsApp, resources: readonly ResourceLike[], options?: WorkspaceOptions & Pick<BuildOptions, "knownTerms">): BuiltApp;
|
|
110
|
+
/**
|
|
111
|
+
* Everything wrong with a workspace's documentation, each as one line that
|
|
112
|
+
* names its resource first: `support/refunds (doc): line 12: …`. An empty
|
|
113
|
+
* list means it can be deployed.
|
|
114
|
+
*/
|
|
115
|
+
export declare function checkWorkspaceDocs(resources: readonly ResourceLike[], options?: WorkspaceOptions): string[];
|
|
116
|
+
/**
|
|
117
|
+
* What is worth knowing about a workspace's documentation that stops nothing:
|
|
118
|
+
* each warning as a line that names its page. A deploy is never refused for one.
|
|
119
|
+
*/
|
|
120
|
+
export declare function workspaceDocsWarnings(resources: readonly ResourceLike[], options?: WorkspaceOptions): string[];
|
|
121
|
+
export { ABOUT_KINDS, type AboutKind };
|
|
122
|
+
//# sourceMappingURL=workspace.d.ts.map
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { readPage } from "./page.js";
|
|
2
|
+
import { ABOUT_KINDS } from "./schema.js";
|
|
3
|
+
import { buildDocSet, PRODUCT_PREFIX } from "./set.js";
|
|
4
|
+
import { clashes } from "./stack.js";
|
|
5
|
+
/** The one table of a workspace in which every docs site keeps its readers' answers. */
|
|
6
|
+
export const FEEDBACK_TABLE = "docs-feedback";
|
|
7
|
+
/**
|
|
8
|
+
* The columns of that table, and of what type: what the console makes, what a
|
|
9
|
+
* served site writes, and what a doc writer's deploy is held to.
|
|
10
|
+
*/
|
|
11
|
+
export const FEEDBACK_COLUMNS = {
|
|
12
|
+
site_key: {
|
|
13
|
+
type: "text",
|
|
14
|
+
required: true,
|
|
15
|
+
description: "The key of the site's app, which a rename keeps.",
|
|
16
|
+
},
|
|
17
|
+
site: { type: "text", required: false, description: "The site's name when the reader said so." },
|
|
18
|
+
page: { type: "text", required: true, description: "The page, by its path in the site." },
|
|
19
|
+
helpful: { type: "boolean", required: true, description: "Whether it helped." },
|
|
20
|
+
version: { type: "text", required: false, description: "The deployed version they read." },
|
|
21
|
+
at: { type: "timestamp", required: false, description: "When they said so." },
|
|
22
|
+
};
|
|
23
|
+
/** Whether a table's body has exactly the feedback columns, of the same types. */
|
|
24
|
+
export function hasFeedbackColumns(body) {
|
|
25
|
+
const columns = body
|
|
26
|
+
?.columns;
|
|
27
|
+
if (!columns || typeof columns !== "object")
|
|
28
|
+
return false;
|
|
29
|
+
const names = Object.keys(columns).sort();
|
|
30
|
+
if (names.join() !== Object.keys(FEEDBACK_COLUMNS).sort().join())
|
|
31
|
+
return false;
|
|
32
|
+
return names.every((name) => {
|
|
33
|
+
const want = FEEDBACK_COLUMNS[name];
|
|
34
|
+
const have = columns[name];
|
|
35
|
+
return have?.type === want.type && (have?.required === true) === want.required;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/** Whether a resource is the workspace's table of readers' answers, as it should be made. */
|
|
39
|
+
export const isFeedbackTable = (kind, path, body) => kind === "table" && path === FEEDBACK_TABLE && hasFeedbackColumns(body);
|
|
40
|
+
/** The apps of a workspace that serve documentation. */
|
|
41
|
+
export function docsApps(resources) {
|
|
42
|
+
return resources
|
|
43
|
+
.filter((one) => one.kind === "app")
|
|
44
|
+
.flatMap((one) => {
|
|
45
|
+
const body = one.body;
|
|
46
|
+
const feedback = body.feedback?.table;
|
|
47
|
+
return typeof body.docs === "string"
|
|
48
|
+
? [
|
|
49
|
+
{
|
|
50
|
+
path: one.path,
|
|
51
|
+
...(one.key !== undefined ? { key: one.key } : {}),
|
|
52
|
+
title: typeof body.title === "string" ? body.title : one.path,
|
|
53
|
+
docs: body.docs,
|
|
54
|
+
...(typeof feedback === "string" ? { feedback } : {}),
|
|
55
|
+
...(body.published === false ? { published: false } : {}),
|
|
56
|
+
},
|
|
57
|
+
]
|
|
58
|
+
: [];
|
|
59
|
+
})
|
|
60
|
+
.sort((a, b) => a.path.localeCompare(b.path));
|
|
61
|
+
}
|
|
62
|
+
const sourceOf = (resource) => String(resource.body?.source ?? "");
|
|
63
|
+
/** The pages a docs app serves, each by its path under the app's folder. */
|
|
64
|
+
export function pagesOf(app, resources) {
|
|
65
|
+
const prefix = `${app.docs}/`;
|
|
66
|
+
return resources
|
|
67
|
+
.filter((one) => one.kind === "doc" && one.path.startsWith(prefix))
|
|
68
|
+
.map((resource) => ({ path: resource.path.slice(prefix.length), resource }))
|
|
69
|
+
.sort((a, b) => a.path.localeCompare(b.path));
|
|
70
|
+
}
|
|
71
|
+
/** The docs app a page belongs to, if any: the one whose folder holds it. */
|
|
72
|
+
export function appOf(apps, docPath) {
|
|
73
|
+
return apps.find((app) => docPath.startsWith(`${app.docs}/`));
|
|
74
|
+
}
|
|
75
|
+
/** Whether resources of a workspace say a resource is there, for `about:` and for a term that names one. */
|
|
76
|
+
export function resourceChecker(resources) {
|
|
77
|
+
const byPath = new Map(resources.map((one) => [one.path, one]));
|
|
78
|
+
return (kind, path, column) => {
|
|
79
|
+
const found = byPath.get(path);
|
|
80
|
+
if (found?.kind !== kind)
|
|
81
|
+
return false;
|
|
82
|
+
if (column === undefined)
|
|
83
|
+
return true;
|
|
84
|
+
const columns = found.body?.columns ?? {};
|
|
85
|
+
return Object.hasOwn(columns, column) || ["id", "created_at", "updated_at"].includes(column);
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/** Reads a docs app's pages and builds its set. Each issue names its page by the page's path in the workspace. */
|
|
89
|
+
export function buildApp(app, resources, options = {}) {
|
|
90
|
+
const has = options.asset;
|
|
91
|
+
const issues = [];
|
|
92
|
+
const entries = [];
|
|
93
|
+
for (const { path, resource } of pagesOf(app, resources)) {
|
|
94
|
+
const updated = resource.updated instanceof Date ? resource.updated.toISOString() : resource.updated;
|
|
95
|
+
const read = readPage(path, sourceOf(resource), updated ? { updated } : {});
|
|
96
|
+
entries.push(read.entry);
|
|
97
|
+
issues.push(...read.issues);
|
|
98
|
+
}
|
|
99
|
+
const built = buildDocSet(entries, {
|
|
100
|
+
resource: resourceChecker(resources),
|
|
101
|
+
reservedPrefix: PRODUCT_PREFIX,
|
|
102
|
+
...(options.product
|
|
103
|
+
? { reservedTerms: options.product.terms, reservedTopics: options.product.topics }
|
|
104
|
+
: {}),
|
|
105
|
+
...(options.knownTerms ? { knownTerms: options.knownTerms } : {}),
|
|
106
|
+
...(has ? { asset: (file) => has(app.path, file) } : {}),
|
|
107
|
+
});
|
|
108
|
+
issues.push(...built.issues);
|
|
109
|
+
return {
|
|
110
|
+
app,
|
|
111
|
+
set: built.set,
|
|
112
|
+
issues: issues
|
|
113
|
+
.map((issue) => ({ ...issue, path: `${app.docs}/${issue.path}` }))
|
|
114
|
+
// One page's problems together, in the order they are met reading it.
|
|
115
|
+
.sort((a, b) => a.path.localeCompare(b.path) || a.line - b.line || a.column - b.column),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function definedTerms(resources) {
|
|
119
|
+
const defined = new Set();
|
|
120
|
+
for (const resource of resources) {
|
|
121
|
+
if (resource.kind !== "doc")
|
|
122
|
+
continue;
|
|
123
|
+
for (const term of readPage(resource.path, sourceOf(resource)).entry.frontmatter.terms ?? []) {
|
|
124
|
+
defined.add(term.id);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return defined;
|
|
128
|
+
}
|
|
129
|
+
const said = (issue) => `${issue.path} (doc): ${issue.line > 1 ? `line ${issue.line}: ` : ""}${issue.message.replace(/\n/g, " ")}`;
|
|
130
|
+
/**
|
|
131
|
+
* Everything wrong with a workspace's documentation, each as one line that
|
|
132
|
+
* names its resource first: `support/refunds (doc): line 12: …`. An empty
|
|
133
|
+
* list means it can be deployed.
|
|
134
|
+
*/
|
|
135
|
+
export function checkWorkspaceDocs(resources, options = {}) {
|
|
136
|
+
const problems = [];
|
|
137
|
+
const apps = docsApps(resources);
|
|
138
|
+
// A site is a folder of the documentation's own: a top-level one.
|
|
139
|
+
for (const app of apps) {
|
|
140
|
+
if (app.docs.includes("/")) {
|
|
141
|
+
problems.push(`${app.path} (app): serves "${app.docs}", which is inside another folder. A docs app serves a top-level folder: move its pages to a folder of their own, or serve "${app.docs.split("/")[0]}".`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// Readers' answers are kept in a table that is there, and holds what an answer is.
|
|
145
|
+
for (const app of apps) {
|
|
146
|
+
if (app.feedback === undefined)
|
|
147
|
+
continue;
|
|
148
|
+
const table = resources.find((one) => one.kind === "table" && one.path === app.feedback);
|
|
149
|
+
if (!table) {
|
|
150
|
+
problems.push(`${app.path} (app): keeps its readers' answers in the table ${app.feedback}, and there is no such table.`);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
const columns = (table.body.columns ??
|
|
154
|
+
{});
|
|
155
|
+
const wrong = Object.entries(FEEDBACK_COLUMNS).filter(([name, column]) => columns[name]?.type !== column.type);
|
|
156
|
+
if (wrong.length > 0) {
|
|
157
|
+
problems.push(`${app.path} (app): the table ${app.feedback} keeps its readers' answers, and needs ${wrong
|
|
158
|
+
.map(([name, column]) => `a ${column.type} column ${name}`)
|
|
159
|
+
.join(", ")}.`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// Two apps may not serve the same page.
|
|
163
|
+
for (const [index, app] of apps.entries()) {
|
|
164
|
+
for (const other of apps.slice(index + 1)) {
|
|
165
|
+
if (app.docs === other.docs ||
|
|
166
|
+
app.docs.startsWith(`${other.docs}/`) ||
|
|
167
|
+
other.docs.startsWith(`${app.docs}/`)) {
|
|
168
|
+
problems.push(`${other.path} (app): its pages are under "${other.docs}", and the app ${app.path} serves "${app.docs}". A page belongs to one docs app: give them folders that do not hold each other.`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// A term of one app can be used on a page of another: terms are the workspace's.
|
|
173
|
+
const defined = definedTerms(resources);
|
|
174
|
+
const built = [];
|
|
175
|
+
for (const app of apps) {
|
|
176
|
+
const one = buildApp(app, resources, { ...options, knownTerms: defined });
|
|
177
|
+
if (one.set.pages.size === 0) {
|
|
178
|
+
problems.push(`${app.path} (app): serves the pages under "${app.docs}", and there are none. A page is a Markdown file there, or a page made in the console.`);
|
|
179
|
+
}
|
|
180
|
+
built.push(one);
|
|
181
|
+
problems.push(...one.issues.filter((issue) => issue.severity === "error").map(said));
|
|
182
|
+
}
|
|
183
|
+
for (const clash of clashes(built.map((one) => ({ id: one.app.path, set: one.set })))) {
|
|
184
|
+
problems.push(`${clash.layers[1]} (app): the ${clash.kind} "${clash.id}" is also defined in the docs app ${clash.layers[0]}. A ${clash.kind} belongs to the workspace: define it once.`);
|
|
185
|
+
}
|
|
186
|
+
// A page no app serves is still a page: it has to read.
|
|
187
|
+
for (const resource of resources) {
|
|
188
|
+
if (resource.kind !== "doc" || appOf(apps, resource.path))
|
|
189
|
+
continue;
|
|
190
|
+
problems.push(...readPage(resource.path, sourceOf(resource))
|
|
191
|
+
.issues.filter((issue) => issue.severity === "error")
|
|
192
|
+
.map(said));
|
|
193
|
+
}
|
|
194
|
+
return problems;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* What is worth knowing about a workspace's documentation that stops nothing:
|
|
198
|
+
* each warning as a line that names its page. A deploy is never refused for one.
|
|
199
|
+
*/
|
|
200
|
+
export function workspaceDocsWarnings(resources, options = {}) {
|
|
201
|
+
const defined = definedTerms(resources);
|
|
202
|
+
return docsApps(resources).flatMap((app) => buildApp(app, resources, { ...options, knownTerms: defined })
|
|
203
|
+
.issues.filter((issue) => issue.severity === "warning")
|
|
204
|
+
.map(said));
|
|
205
|
+
}
|
|
206
|
+
export { ABOUT_KINDS };
|
|
207
|
+
//# sourceMappingURL=workspace.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volvel/docs-engine",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "A set of documentation pages: folders become collections and navigation, and terms, topics, links and search are worked out across them.",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/volveldev/Volvel.git",
|
|
10
|
+
"directory": "packages/docs-engine"
|
|
11
|
+
},
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./search-query": {
|
|
19
|
+
"types": "./dist/search-query.d.ts",
|
|
20
|
+
"default": "./dist/search-query.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"!dist/**/*.test.*",
|
|
26
|
+
"!dist/**/*.map",
|
|
27
|
+
"THIRD_PARTY_NOTICES.md"
|
|
28
|
+
],
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"minisearch": "^7.2.0",
|
|
34
|
+
"yaml": "^2.9.1",
|
|
35
|
+
"@volvel/markup": "0.7.0"
|
|
36
|
+
}
|
|
6
37
|
}
|
package/README.md
DELETED