@zudojs/docs 1.0.5 → 1.1.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 +4 -1
- package/dist/docsTypes/documentationContent.d.ts +0 -1
- package/dist/docsTypes/documentationContent.js +0 -1
- package/dist/docsTypes/documentationDocument.d.ts +0 -1
- package/dist/docsTypes/documentationDocument.js +0 -1
- package/dist/docsTypes/documentationMetadata.d.ts +5 -2
- package/dist/docsTypes/documentationMetadata.js +0 -1
- package/dist/docsTypes/documentationNavigation.d.ts +9 -3
- package/dist/docsTypes/documentationNavigation.js +0 -1
- package/dist/docsTypes/documentationProvider.d.ts +5 -2
- package/dist/docsTypes/documentationProvider.js +0 -1
- package/dist/docsTypes/index.d.ts +0 -1
- package/dist/docsTypes/index.js +0 -1
- package/dist/document/documentBuilder.convenience.d.ts +15 -0
- package/dist/document/documentBuilder.convenience.js +28 -0
- package/dist/document/documentBuilder.core.d.ts +18 -13
- package/dist/document/documentBuilder.core.js +16 -50
- package/dist/document/documentBuilder.normalize.d.ts +5 -1
- package/dist/document/documentBuilder.normalize.js +12 -1
- package/dist/document/documentBuilder.validate.d.ts +16 -0
- package/dist/document/documentBuilder.validate.js +36 -0
- package/dist/document/index.d.ts +2 -2
- package/dist/document/index.js +2 -2
- package/dist/errors/index.d.ts +0 -1
- package/dist/errors/index.js +0 -1
- package/dist/examples/examples.core.d.ts +0 -1
- package/dist/examples/examples.core.js +0 -1
- package/dist/examples/index.d.ts +0 -1
- package/dist/examples/index.js +0 -1
- package/dist/frontmatter/frontmatter.core.d.ts +0 -1
- package/dist/frontmatter/frontmatter.core.js +0 -1
- package/dist/frontmatter/frontmatter.parser.d.ts +0 -1
- package/dist/frontmatter/frontmatter.parser.js +0 -1
- package/dist/frontmatter/frontmatter.serializer.d.ts +0 -1
- package/dist/frontmatter/frontmatter.serializer.js +0 -1
- package/dist/frontmatter/frontmatter.types.d.ts +0 -1
- package/dist/frontmatter/frontmatter.types.js +0 -1
- package/dist/frontmatter/frontmatter.values.d.ts +0 -1
- package/dist/frontmatter/frontmatter.values.js +0 -1
- package/dist/frontmatter/index.d.ts +0 -1
- package/dist/frontmatter/index.js +0 -1
- package/dist/generator/generator.types.d.ts +0 -1
- package/dist/generator/generator.types.js +0 -1
- package/dist/generator/generatorJson.core.d.ts +0 -1
- package/dist/generator/generatorJson.core.js +0 -1
- package/dist/generator/generatorMarkdown.core.d.ts +0 -1
- package/dist/generator/generatorMarkdown.core.js +0 -1
- package/dist/generator/generatorMarkdownNodes.d.ts +0 -1
- package/dist/generator/generatorMarkdownNodes.js +0 -1
- package/dist/generator/index.d.ts +0 -1
- package/dist/generator/index.js +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/navigation/index.d.ts +3 -2
- package/dist/navigation/index.js +2 -2
- package/dist/navigation/navigation.adjacent.d.ts +32 -0
- package/dist/navigation/navigation.adjacent.js +60 -0
- package/dist/navigation/navigation.core.d.ts +0 -13
- package/dist/navigation/navigation.core.js +0 -51
- package/dist/registry/index.d.ts +0 -1
- package/dist/registry/index.js +0 -1
- package/dist/registry/registry.core.d.ts +0 -1
- package/dist/registry/registry.core.js +0 -1
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/utils.freeze.d.ts +0 -1
- package/dist/utils/utils.freeze.js +0 -1
- package/dist/utils/utils.helper.d.ts +0 -1
- package/dist/utils/utils.helper.js +0 -1
- package/dist/utils/utils.href.d.ts +0 -1
- package/dist/utils/utils.href.js +0 -1
- package/dist/utils/utils.markdownText.d.ts +0 -1
- package/dist/utils/utils.markdownText.js +0 -1
- package/dist/validator/index.d.ts +0 -1
- package/dist/validator/index.js +0 -1
- package/dist/validator/validator.types.d.ts +0 -1
- package/dist/validator/validator.types.js +0 -1
- package/dist/validator/validatorAll/index.d.ts +0 -1
- package/dist/validator/validatorAll/index.js +0 -1
- package/dist/validator/validatorAll/validatorAll.core.d.ts +11 -1
- package/dist/validator/validatorAll/validatorAll.core.js +6 -2
- package/dist/validator/validatorAll/validatorNavigation.core.d.ts +0 -1
- package/dist/validator/validatorAll/validatorNavigation.core.js +0 -1
- package/dist/validator/validatorDocument.core.d.ts +0 -1
- package/dist/validator/validatorDocument.core.js +0 -1
- package/dist/validator/validatorDuplicates.core.d.ts +0 -1
- package/dist/validator/validatorDuplicates.core.js +0 -1
- package/dist/validator/validatorLinks.core.d.ts +16 -6
- package/dist/validator/validatorLinks.core.js +18 -37
- package/dist/validator/validatorLinks.extract.d.ts +30 -0
- package/dist/validator/validatorLinks.extract.js +118 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -58,7 +58,10 @@ const index = generateIndex(registry.getAll()); // SERVER-only docs excluded
|
|
|
58
58
|
- Markdown and JSON generation with escaping for untrusted content: structured text is HTML-escaped and links are limited to http, https, mailto, tel, ftp and ftps (others are written as plain text)
|
|
59
59
|
- Fail-closed `visibility` filtering: only an unset or exactly `"CLIENT"` visibility reaches a client index
|
|
60
60
|
- `stripMarkdown` and link validation run in linear time on untrusted input
|
|
61
|
-
- Document, link and navigation validation with a single `valid` rule (errors only); `javascript:` and other non-allow-listed link schemes are `UNSAFE_LINK` errors
|
|
61
|
+
- Document, link and navigation validation with a single `valid` rule (errors only); `javascript:` and other non-allow-listed link schemes are `UNSAFE_LINK` errors in every link form — inline `[x](…)` (including targets with parentheses or a title), reference definitions `[x]: …`, raw `<a href="…">` and `<scheme:…>` autolinks
|
|
62
|
+
- `BROKEN_LINK` and `NAVIGATION_ORPHAN_DOCUMENT` are warnings by default; pass `{ brokenLinkSeverity: "error", orphanSeverity: "error" }` to `validateAll` (or `brokenLinkSeverity` to `validateLinks`) to fail on dead links or unreachable documents
|
|
63
|
+
- `createDocument({ …, strict: true })` rejects an unknown `category`, `status` or `visibility` at creation instead of leaving it to `validateDocument`; documents never carry explicit `undefined` keys
|
|
64
|
+
- `getAdjacent(id, nav, { scope: "tree" })` walks previous/next across section boundaries in reading order (the default stays within one level)
|
|
62
65
|
- Documentation error classes re-exported from `@zudojs/errors`
|
|
63
66
|
|
|
64
67
|
## Use Cases
|
|
@@ -50,11 +50,14 @@ export interface DocumentationMetadata {
|
|
|
50
50
|
readonly ticket?: string;
|
|
51
51
|
readonly tags?: readonly string[];
|
|
52
52
|
}
|
|
53
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* A version entry for versioned documentation. A contract only: the
|
|
55
|
+
* package provides no version switcher; hosts list their versions with
|
|
56
|
+
* this shape and select a registry per version.
|
|
57
|
+
*/
|
|
54
58
|
export interface DocumentationVersion {
|
|
55
59
|
readonly version: string;
|
|
56
60
|
readonly label?: string;
|
|
57
61
|
readonly deprecated?: boolean;
|
|
58
62
|
readonly latest?: boolean;
|
|
59
63
|
}
|
|
60
|
-
//# sourceMappingURL=documentationMetadata.d.ts.map
|
|
@@ -15,7 +15,11 @@ export interface DocumentationBreadcrumb {
|
|
|
15
15
|
readonly title: string;
|
|
16
16
|
readonly documentId?: string;
|
|
17
17
|
}
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Search document for indexing. A contract only: this package ships no
|
|
20
|
+
* search index; build `SearchDocument`s from a registry (for example with
|
|
21
|
+
* `stripMarkdown`) and feed them to the search engine of your choice.
|
|
22
|
+
*/
|
|
19
23
|
export interface SearchDocument {
|
|
20
24
|
readonly id: string;
|
|
21
25
|
readonly title: string;
|
|
@@ -23,7 +27,10 @@ export interface SearchDocument {
|
|
|
23
27
|
readonly tags: readonly string[];
|
|
24
28
|
readonly path: string;
|
|
25
29
|
}
|
|
26
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* Search result returned from a search query. A contract only; see
|
|
32
|
+
* `SearchDocument`.
|
|
33
|
+
*/
|
|
27
34
|
export interface SearchResult {
|
|
28
35
|
readonly id: string;
|
|
29
36
|
readonly title: string;
|
|
@@ -31,4 +38,3 @@ export interface SearchResult {
|
|
|
31
38
|
readonly excerpt?: string;
|
|
32
39
|
readonly score?: number;
|
|
33
40
|
}
|
|
34
|
-
//# sourceMappingURL=documentationNavigation.d.ts.map
|
|
@@ -10,7 +10,11 @@ export interface DocumentationProvider {
|
|
|
10
10
|
get(id: string): DocumentationDocument | undefined;
|
|
11
11
|
getAll(): readonly DocumentationDocument[];
|
|
12
12
|
}
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Loads content from a documentation source. A contract only: no loader
|
|
15
|
+
* ships with the package; implement it over the file system, a fetch or
|
|
16
|
+
* a database and pass the result to `parseFrontmatter` / `createDocument`.
|
|
17
|
+
*/
|
|
14
18
|
export interface DocumentationSourceLoader {
|
|
15
19
|
load(source: string): Promise<string>;
|
|
16
20
|
}
|
|
@@ -18,4 +22,3 @@ export interface DocumentationSourceLoader {
|
|
|
18
22
|
export interface DocumentationSanitizer {
|
|
19
23
|
sanitize(content: string): string;
|
|
20
24
|
}
|
|
21
|
-
//# sourceMappingURL=documentationProvider.d.ts.map
|
|
@@ -8,4 +8,3 @@ export type { DocumentationCategory, DocumentationStatus, APISymbolKind, SourceL
|
|
|
8
8
|
export type { DocumentationDocument } from "./documentationDocument.js";
|
|
9
9
|
export type { DocumentationNavigationItem, DocumentationBreadcrumb, SearchDocument, SearchResult, } from "./documentationNavigation.js";
|
|
10
10
|
export type { DocumentationProvider, DocumentationSourceLoader, DocumentationSanitizer, } from "./documentationProvider.js";
|
|
11
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/docsTypes/index.js
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convenience builders for markdown and structured documents.
|
|
3
|
+
*
|
|
4
|
+
* @module document/documentBuilder.convenience
|
|
5
|
+
*/
|
|
6
|
+
import type { DocumentationDocument, DocumentationNode } from "../docsTypes/index.js";
|
|
7
|
+
import { type DocumentBuilderExtras } from "./documentBuilder.core.js";
|
|
8
|
+
/**
|
|
9
|
+
* Creates a markdown document.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createMarkdownDocument(id: string, title: string, markdown: string, options?: DocumentBuilderExtras): DocumentationDocument;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a structured document from AST nodes.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createStructuredDocument(id: string, title: string, nodes: readonly DocumentationNode[], options?: DocumentBuilderExtras): DocumentationDocument;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convenience builders for markdown and structured documents.
|
|
3
|
+
*
|
|
4
|
+
* @module document/documentBuilder.convenience
|
|
5
|
+
*/
|
|
6
|
+
import { createDocument, } from "./documentBuilder.core.js";
|
|
7
|
+
/**
|
|
8
|
+
* Creates a markdown document.
|
|
9
|
+
*/
|
|
10
|
+
export function createMarkdownDocument(id, title, markdown, options) {
|
|
11
|
+
return createDocument({
|
|
12
|
+
...options,
|
|
13
|
+
id,
|
|
14
|
+
title,
|
|
15
|
+
content: { type: "markdown", value: markdown },
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Creates a structured document from AST nodes.
|
|
20
|
+
*/
|
|
21
|
+
export function createStructuredDocument(id, title, nodes, options) {
|
|
22
|
+
return createDocument({
|
|
23
|
+
...options,
|
|
24
|
+
id,
|
|
25
|
+
title,
|
|
26
|
+
content: { type: "structured", nodes },
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Provides a chainable API that validates inputs and
|
|
5
5
|
* produces immutable DocumentationDocument objects.
|
|
6
6
|
*/
|
|
7
|
-
import type { DocumentationContent, DocumentationDocument, DocumentationCategory, DocumentationMetadata,
|
|
7
|
+
import type { DocumentationContent, DocumentationDocument, DocumentationCategory, DocumentationMetadata, DocumentationStatus } from "../docsTypes/index.js";
|
|
8
8
|
/**
|
|
9
9
|
* Options for creating a document via the builder.
|
|
10
10
|
*/
|
|
@@ -21,6 +21,14 @@ export interface DocumentBuilderOptions {
|
|
|
21
21
|
readonly deprecated?: boolean;
|
|
22
22
|
readonly deprecatedMessage?: string;
|
|
23
23
|
readonly visibility?: "SERVER" | "CLIENT";
|
|
24
|
+
/**
|
|
25
|
+
* When true, the built document is also run through `validateDocument`
|
|
26
|
+
* and any error issue (unknown `category`, `status`, `visibility`,
|
|
27
|
+
* content type or structured node) throws a `DocumentValidationError`.
|
|
28
|
+
* Defaults to false: the builder checks only `id`, `title` and the
|
|
29
|
+
* presence of `content`, matching earlier releases.
|
|
30
|
+
*/
|
|
31
|
+
readonly strict?: boolean;
|
|
24
32
|
}
|
|
25
33
|
/**
|
|
26
34
|
* Options accepted by the convenience builders. The positional
|
|
@@ -32,10 +40,16 @@ export type DocumentBuilderExtras = Omit<Partial<DocumentBuilderOptions>, "id" |
|
|
|
32
40
|
*
|
|
33
41
|
* The returned document is a deep-frozen copy: later mutation of the
|
|
34
42
|
* options object (or of nested `content`, `metadata`, `tags`) does not
|
|
35
|
-
* affect it.
|
|
43
|
+
* affect it. Optional fields that were not supplied are absent from the
|
|
44
|
+
* document rather than present as `undefined`.
|
|
36
45
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
46
|
+
* Only `id`, `title` and `content` are checked here; `category`, `status`
|
|
47
|
+
* and the other enums are checked by `validateDocument`, or at creation
|
|
48
|
+
* time when `strict: true` is passed.
|
|
49
|
+
*
|
|
50
|
+
* @throws {DocumentValidationError} when `id`, `title` or `content` is missing,
|
|
51
|
+
* the ID is not a valid dot-separated identifier, or (`strict: true`)
|
|
52
|
+
* `validateDocument` reports an error.
|
|
39
53
|
*
|
|
40
54
|
* @example
|
|
41
55
|
* ```ts
|
|
@@ -49,12 +63,3 @@ export type DocumentBuilderExtras = Omit<Partial<DocumentBuilderOptions>, "id" |
|
|
|
49
63
|
* ```
|
|
50
64
|
*/
|
|
51
65
|
export declare function createDocument(options: DocumentBuilderOptions): DocumentationDocument;
|
|
52
|
-
/**
|
|
53
|
-
* Creates a markdown document.
|
|
54
|
-
*/
|
|
55
|
-
export declare function createMarkdownDocument(id: string, title: string, markdown: string, options?: DocumentBuilderExtras): DocumentationDocument;
|
|
56
|
-
/**
|
|
57
|
-
* Creates a structured document from AST nodes.
|
|
58
|
-
*/
|
|
59
|
-
export declare function createStructuredDocument(id: string, title: string, nodes: readonly DocumentationNode[], options?: DocumentBuilderExtras): DocumentationDocument;
|
|
60
|
-
//# sourceMappingURL=documentBuilder.core.d.ts.map
|
|
@@ -4,19 +4,24 @@
|
|
|
4
4
|
* Provides a chainable API that validates inputs and
|
|
5
5
|
* produces immutable DocumentationDocument objects.
|
|
6
6
|
*/
|
|
7
|
-
import { DocumentValidationError } from "@zudojs/errors";
|
|
8
7
|
import { deepFreezeClone } from "../utils/utils.freeze.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
8
|
+
import { toTagList, withoutUndefined } from "./documentBuilder.normalize.js";
|
|
9
|
+
import { assertValid, validateDocumentOptions } from "./documentBuilder.validate.js";
|
|
11
10
|
/**
|
|
12
11
|
* Creates a documentation document from structured options.
|
|
13
12
|
*
|
|
14
13
|
* The returned document is a deep-frozen copy: later mutation of the
|
|
15
14
|
* options object (or of nested `content`, `metadata`, `tags`) does not
|
|
16
|
-
* affect it.
|
|
15
|
+
* affect it. Optional fields that were not supplied are absent from the
|
|
16
|
+
* document rather than present as `undefined`.
|
|
17
17
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
18
|
+
* Only `id`, `title` and `content` are checked here; `category`, `status`
|
|
19
|
+
* and the other enums are checked by `validateDocument`, or at creation
|
|
20
|
+
* time when `strict: true` is passed.
|
|
21
|
+
*
|
|
22
|
+
* @throws {DocumentValidationError} when `id`, `title` or `content` is missing,
|
|
23
|
+
* the ID is not a valid dot-separated identifier, or (`strict: true`)
|
|
24
|
+
* `validateDocument` reports an error.
|
|
20
25
|
*
|
|
21
26
|
* @example
|
|
22
27
|
* ```ts
|
|
@@ -31,7 +36,7 @@ import { toTagList } from "./documentBuilder.normalize.js";
|
|
|
31
36
|
*/
|
|
32
37
|
export function createDocument(options) {
|
|
33
38
|
validateDocumentOptions(options);
|
|
34
|
-
const document = {
|
|
39
|
+
const document = withoutUndefined({
|
|
35
40
|
id: options.id,
|
|
36
41
|
title: options.title,
|
|
37
42
|
description: options.description,
|
|
@@ -44,48 +49,9 @@ export function createDocument(options) {
|
|
|
44
49
|
deprecated: options.deprecated,
|
|
45
50
|
deprecatedMessage: options.deprecatedMessage,
|
|
46
51
|
visibility: options.visibility,
|
|
47
|
-
};
|
|
48
|
-
return deepFreezeClone(document);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Validates document builder options.
|
|
52
|
-
* Throws on invalid input.
|
|
53
|
-
*/
|
|
54
|
-
function validateDocumentOptions(options) {
|
|
55
|
-
if (typeof options.id !== "string" || options.id.trim().length === 0) {
|
|
56
|
-
throw new DocumentValidationError("Document ID is required.");
|
|
57
|
-
}
|
|
58
|
-
if (!isValidDocumentId(options.id)) {
|
|
59
|
-
throw new DocumentValidationError(`Document ID "${options.id}" is invalid. Use dot-separated segments of letters, digits, "_" and "-".`, options.id);
|
|
60
|
-
}
|
|
61
|
-
if (typeof options.title !== "string" ||
|
|
62
|
-
options.title.trim().length === 0) {
|
|
63
|
-
throw new DocumentValidationError("Document title is required.", options.id);
|
|
64
|
-
}
|
|
65
|
-
if (!options.content || typeof options.content !== "object") {
|
|
66
|
-
throw new DocumentValidationError("Document content is required.", options.id);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Creates a markdown document.
|
|
71
|
-
*/
|
|
72
|
-
export function createMarkdownDocument(id, title, markdown, options) {
|
|
73
|
-
return createDocument({
|
|
74
|
-
...options,
|
|
75
|
-
id,
|
|
76
|
-
title,
|
|
77
|
-
content: { type: "markdown", value: markdown },
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Creates a structured document from AST nodes.
|
|
82
|
-
*/
|
|
83
|
-
export function createStructuredDocument(id, title, nodes, options) {
|
|
84
|
-
return createDocument({
|
|
85
|
-
...options,
|
|
86
|
-
id,
|
|
87
|
-
title,
|
|
88
|
-
content: { type: "structured", nodes },
|
|
89
52
|
});
|
|
53
|
+
if (options.strict) {
|
|
54
|
+
assertValid(document);
|
|
55
|
+
}
|
|
56
|
+
return deepFreezeClone(document);
|
|
90
57
|
}
|
|
91
|
-
//# sourceMappingURL=documentBuilder.core.js.map
|
|
@@ -9,4 +9,8 @@
|
|
|
9
9
|
* one-character tags.
|
|
10
10
|
*/
|
|
11
11
|
export declare function toTagList(tags: readonly string[] | string | undefined): string[] | undefined;
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Shallow copy of `value` without the keys whose value is `undefined`, so
|
|
14
|
+
* an optional field that was not supplied is absent instead of present.
|
|
15
|
+
*/
|
|
16
|
+
export declare function withoutUndefined<T extends object>(value: T): T;
|
|
@@ -15,4 +15,15 @@ export function toTagList(tags) {
|
|
|
15
15
|
return tags === "" ? [] : [tags];
|
|
16
16
|
return [...tags];
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Shallow copy of `value` without the keys whose value is `undefined`, so
|
|
20
|
+
* an optional field that was not supplied is absent instead of present.
|
|
21
|
+
*/
|
|
22
|
+
export function withoutUndefined(value) {
|
|
23
|
+
const copy = {};
|
|
24
|
+
for (const [key, item] of Object.entries(value)) {
|
|
25
|
+
if (item !== undefined)
|
|
26
|
+
copy[key] = item;
|
|
27
|
+
}
|
|
28
|
+
return copy;
|
|
29
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Input and strict-mode checks for `createDocument`.
|
|
3
|
+
*
|
|
4
|
+
* @module document/documentBuilder.validate
|
|
5
|
+
*/
|
|
6
|
+
import type { DocumentationDocument } from "../docsTypes/index.js";
|
|
7
|
+
import type { DocumentBuilderOptions } from "./documentBuilder.core.js";
|
|
8
|
+
/**
|
|
9
|
+
* Validates document builder options.
|
|
10
|
+
* Throws on invalid input.
|
|
11
|
+
*/
|
|
12
|
+
export declare function validateDocumentOptions(options: DocumentBuilderOptions): void;
|
|
13
|
+
/**
|
|
14
|
+
* Throws when `validateDocument` reports an error issue for `document`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function assertValid(document: DocumentationDocument): void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Input and strict-mode checks for `createDocument`.
|
|
3
|
+
*
|
|
4
|
+
* @module document/documentBuilder.validate
|
|
5
|
+
*/
|
|
6
|
+
import { DocumentValidationError } from "@zudojs/errors";
|
|
7
|
+
import { isValidDocumentId } from "../utils/utils.helper.js";
|
|
8
|
+
import { validateDocument } from "../validator/validatorDocument.core.js";
|
|
9
|
+
/**
|
|
10
|
+
* Validates document builder options.
|
|
11
|
+
* Throws on invalid input.
|
|
12
|
+
*/
|
|
13
|
+
export function validateDocumentOptions(options) {
|
|
14
|
+
if (typeof options.id !== "string" || options.id.trim().length === 0) {
|
|
15
|
+
throw new DocumentValidationError("Document ID is required.");
|
|
16
|
+
}
|
|
17
|
+
if (!isValidDocumentId(options.id)) {
|
|
18
|
+
throw new DocumentValidationError(`Document ID "${options.id}" is invalid. Use dot-separated segments of letters, digits, "_" and "-".`, options.id);
|
|
19
|
+
}
|
|
20
|
+
if (typeof options.title !== "string" ||
|
|
21
|
+
options.title.trim().length === 0) {
|
|
22
|
+
throw new DocumentValidationError("Document title is required.", options.id);
|
|
23
|
+
}
|
|
24
|
+
if (!options.content || typeof options.content !== "object") {
|
|
25
|
+
throw new DocumentValidationError("Document content is required.", options.id);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Throws when `validateDocument` reports an error issue for `document`.
|
|
30
|
+
*/
|
|
31
|
+
export function assertValid(document) {
|
|
32
|
+
const failure = validateDocument(document).issues.find((issue) => issue.severity === "error");
|
|
33
|
+
if (failure) {
|
|
34
|
+
throw new DocumentValidationError(failure.message, document.id);
|
|
35
|
+
}
|
|
36
|
+
}
|
package/dist/document/index.d.ts
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Document model and builder for creating documentation pages.
|
|
5
5
|
*/
|
|
6
|
-
export { createDocument
|
|
6
|
+
export { createDocument } from "./documentBuilder.core.js";
|
|
7
|
+
export { createMarkdownDocument, createStructuredDocument, } from "./documentBuilder.convenience.js";
|
|
7
8
|
export type { DocumentBuilderOptions, DocumentBuilderExtras, } from "./documentBuilder.core.js";
|
|
8
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/document/index.js
CHANGED
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Document model and builder for creating documentation pages.
|
|
5
5
|
*/
|
|
6
|
-
export { createDocument
|
|
7
|
-
|
|
6
|
+
export { createDocument } from "./documentBuilder.core.js";
|
|
7
|
+
export { createMarkdownDocument, createStructuredDocument, } from "./documentBuilder.convenience.js";
|
package/dist/errors/index.d.ts
CHANGED
|
@@ -13,4 +13,3 @@ export type { DocumentationErrorOptions } from "@zudojs/errors";
|
|
|
13
13
|
export declare function createDocumentationError(message: string, options?: DocumentationErrorOptions): DocumentationError;
|
|
14
14
|
/** Determines whether an unknown value is a `DocumentationError`. */
|
|
15
15
|
export declare function isDocumentationError(value: unknown): value is DocumentationError;
|
|
16
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/errors/index.js
CHANGED
|
@@ -39,4 +39,3 @@ export declare function renderExampleMarkdown(example: DocumentationExample): st
|
|
|
39
39
|
* Renders an example as a JSON-serializable object.
|
|
40
40
|
*/
|
|
41
41
|
export declare function exampleToJSON(example: DocumentationExample): Record<string, unknown>;
|
|
42
|
-
//# sourceMappingURL=examples.core.d.ts.map
|
package/dist/examples/index.d.ts
CHANGED
package/dist/examples/index.js
CHANGED
|
@@ -4,4 +4,3 @@
|
|
|
4
4
|
export { parseFrontmatter } from "./frontmatter.parser.js";
|
|
5
5
|
export { serializeFrontmatter } from "./frontmatter.serializer.js";
|
|
6
6
|
export type { ParsedFrontmatter, FrontmatterMetadata, FrontmatterScalar, FrontmatterValue, } from "./frontmatter.types.js";
|
|
7
|
-
//# sourceMappingURL=frontmatter.core.d.ts.map
|
|
@@ -18,4 +18,3 @@ import type { FrontmatterMetadata } from "./frontmatter.types.js";
|
|
|
18
18
|
export declare function serializeFrontmatter(metadata: FrontmatterMetadata | Readonly<Record<string, unknown>>, content: string): string;
|
|
19
19
|
/** Formats a single scalar, quoting whenever the parser could misread it. */
|
|
20
20
|
export declare function formatScalar(value: unknown): string;
|
|
21
|
-
//# sourceMappingURL=frontmatter.serializer.d.ts.map
|
|
@@ -22,4 +22,3 @@ export declare function emptyCollection(value: string): readonly never[] | Reado
|
|
|
22
22
|
* list; anything else is a single item. Items go through `parseItem`.
|
|
23
23
|
*/
|
|
24
24
|
export declare function parseInlineList(value: string, parseItem: (item: string) => string): readonly string[];
|
|
25
|
-
//# sourceMappingURL=frontmatter.values.d.ts.map
|
|
@@ -15,4 +15,3 @@ export declare function generateJSON(document: DocumentationDocument): Record<st
|
|
|
15
15
|
* `IndexGeneratorOptions.visibility`).
|
|
16
16
|
*/
|
|
17
17
|
export declare function generateIndex(documents: readonly DocumentationDocument[], options?: IndexGeneratorOptions): Record<string, unknown>[];
|
|
18
|
-
//# sourceMappingURL=generatorJson.core.d.ts.map
|
|
@@ -11,4 +11,3 @@ import type { MarkdownGeneratorOptions } from "./generator.types.js";
|
|
|
11
11
|
* and tags cannot inject metadata keys or terminate the block.
|
|
12
12
|
*/
|
|
13
13
|
export declare function generateMarkdown(document: DocumentationDocument, options?: MarkdownGeneratorOptions): string;
|
|
14
|
-
//# sourceMappingURL=generatorMarkdown.core.d.ts.map
|
|
@@ -29,4 +29,3 @@ export declare function fenceFor(value: string): string;
|
|
|
29
29
|
export declare function sanitizeLanguage(language: string | undefined): string;
|
|
30
30
|
/** Escapes `|` and newlines so a value stays inside its table cell. */
|
|
31
31
|
export declare function tableCell(value: string): string;
|
|
32
|
-
//# sourceMappingURL=generatorMarkdownNodes.d.ts.map
|
|
@@ -7,4 +7,3 @@ export { generateMarkdown } from "./generatorMarkdown.core.js";
|
|
|
7
7
|
export { nodesToMarkdown, clampHeadingLevel, fenceFor, sanitizeLanguage, tableCell, } from "./generatorMarkdownNodes.js";
|
|
8
8
|
export { generateJSON, generateIndex } from "./generatorJson.core.js";
|
|
9
9
|
export type { MarkdownGeneratorOptions, IndexGeneratorOptions, } from "./generator.types.js";
|
|
10
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/generator/index.js
CHANGED
|
@@ -6,4 +6,3 @@
|
|
|
6
6
|
export { generateMarkdown } from "./generatorMarkdown.core.js";
|
|
7
7
|
export { nodesToMarkdown, clampHeadingLevel, fenceFor, sanitizeLanguage, tableCell, } from "./generatorMarkdownNodes.js";
|
|
8
8
|
export { generateJSON, generateIndex } from "./generatorJson.core.js";
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -3,5 +3,6 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Navigation tree utilities — breadcrumbs, flattening, sibling resolution.
|
|
5
5
|
*/
|
|
6
|
-
export { getBreadcrumbs, flattenNavigation, findNavigationItem,
|
|
7
|
-
|
|
6
|
+
export { getBreadcrumbs, flattenNavigation, findNavigationItem, } from "./navigation.core.js";
|
|
7
|
+
export { getSiblings, getAdjacent } from "./navigation.adjacent.js";
|
|
8
|
+
export type { GetAdjacentOptions } from "./navigation.adjacent.js";
|