@astryxdesign/cli 0.6.5 → 0.6.6
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/CHANGELOG.md +87 -0
- package/README.md +16 -15
- package/api/build/_adapter.d.mts +50 -2
- package/api/build/_adapter.mjs +98 -10
- package/api/build/build.doc.mjs +2 -2
- package/api/build/build.test.mjs +111 -2
- package/api/build/kit/kit.mjs +98 -22
- package/api/build/kit/rank.d.mts +32 -8
- package/api/build/kit/rank.mjs +291 -97
- package/api/build/kit/rank.test.mjs +231 -48
- package/api/build/kit/weights.d.mts +82 -0
- package/api/build/kit/weights.json +1 -0
- package/api/build/kit/weights.mjs +305 -0
- package/api/build/kit/weights.test.mjs +190 -0
- package/api/docs/docs.d.mts +6 -0
- package/api/docs/docs.depth.test.mjs +132 -0
- package/api/docs/docs.doc.mjs +31 -2
- package/api/docs/docs.mjs +44 -1
- package/api/docs/docs.test.mjs +279 -0
- package/api/docs/docs.type.d.mts +38 -1
- package/api/docs/docs.type.mjs +18 -1
- package/api/docs/integration-tree.test.mjs +572 -0
- package/api/docs/integrationDocs.test.mjs +336 -0
- package/api/docs/node/node.d.mts +28 -3
- package/api/docs/node/node.mjs +146 -23
- package/api/error.d.mts +22 -0
- package/api/error.mjs +42 -0
- package/api/gap-report/gap-report.d.mts +3 -1
- package/api/gap-report/gap-report.mjs +12 -2
- package/api/gap-report/gap-report.test.mjs +106 -0
- package/api/hook/list/list.d.mts +1 -1
- package/api/integration/add-contribution.d.mts +2 -1
- package/api/integration/add-contribution.mjs +7 -3
- package/api/integration/add-contribution.test.mjs +3 -3
- package/api/integration/add-theme.mjs +338 -26
- package/api/integration/add-theme.test.mjs +314 -1
- package/api/integration/authoring-checks.mjs +10 -7
- package/api/integration/authoring-checks.type.d.mts +8 -0
- package/api/integration/authoring-checks.type.mjs +7 -3
- package/api/integration/integration-authoring.type.d.mts +4 -1
- package/api/integration/integration-authoring.type.mjs +6 -1
- package/api/integration/integrationAdd.doc.mjs +6 -0
- package/api/integration/integrationAddTheme.doc.mjs +10 -0
- package/api/integration/integrationComponentConflicts.doc.mjs +1 -1
- package/api/integration/integrationDocConflicts.doc.mjs +1 -1
- package/api/integration/integrationTemplateConflicts.doc.mjs +1 -1
- package/api/integration/pack-check.mjs +12 -3
- package/api/integration/pack-check.test.mjs +52 -3
- package/api/integration/validate-integration.d.mts +4 -2
- package/api/integration/validate-integration.mjs +7 -2
- package/api/integration/validate-integration.test.mjs +55 -0
- package/api/integration/validate-integration.type.d.mts +5 -0
- package/api/integration/validate-integration.type.mjs +5 -1
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/layout/expand/expand.mjs +12 -7
- package/api/layout/expand/expand.receipt.test.mjs +74 -0
- package/api/layout/layout.type.d.mts +1 -0
- package/api/layout/layout.type.mjs +1 -0
- package/api/layout/layoutExpand.doc.mjs +1 -1
- package/api/search/search.d.mts +36 -5
- package/api/search/search.doc.mjs +4 -4
- package/api/search/search.mjs +194 -54
- package/api/search/search.test.mjs +825 -0
- package/api/search/search.type.d.mts +5 -5
- package/api/search/search.type.mjs +5 -5
- package/api/swizzle/copy/copy.mjs +66 -3
- package/api/swizzle/swizzle.doc.mjs +4 -0
- package/api/template/copy/copy.mjs +14 -8
- package/api/template/copy/copy.receipt.test.mjs +77 -0
- package/api/template/show/show.mjs +15 -4
- package/api/template/show/show.test.mjs +76 -0
- package/api/template/template-integration.test.mjs +14 -0
- package/api/template/template.d.mts +1 -1
- package/api/template/template.doc.mjs +6 -2
- package/api/template/template.mjs +1 -0
- package/api/template/template.type.d.mts +2 -0
- package/api/template/template.type.mjs +2 -0
- package/api/theme/build/build.d.mts +24 -0
- package/api/theme/build/build.icon-lineage.test.mjs +117 -0
- package/api/theme/build/build.icon-preservation.test.mjs +639 -0
- package/api/theme/build/build.mjs +381 -77
- package/api/theme/build/build.project-core.test.mjs +165 -0
- package/api/theme/build/build.test.mjs +190 -1
- package/api/theme/build/icon-imports.d.mts +47 -0
- package/api/theme/build/icon-imports.mjs +691 -0
- package/api/theme/themeBuild.doc.d.mts +4 -1
- package/api/theme/themeBuild.doc.mjs +14 -3
- package/api/upgrade/run/run.mjs +20 -3
- package/api/upgrade/run/run.test.mjs +45 -1
- package/api/upgrade/upgrade.doc.mjs +1 -1
- package/api/upgrade/upgrade.type.d.mts +1 -0
- package/api/upgrade/upgrade.type.mjs +1 -0
- package/assets/docs/icons.doc.mjs +1 -0
- package/assets/docs/theme.doc.mjs +3 -2
- package/assets/docs/tokens.doc.mjs +3 -3
- package/assets/docs/tree/add-a-theme.doc.mjs +4 -0
- package/assets/docs/tree/add-a-topic.doc.mjs +1 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +2 -2
- package/assets/docs/tree/checks.doc.mjs +1 -1
- package/assets/docs/tree/debug-and-gap-reports.doc.mjs +1 -1
- package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
- package/assets/docs/tree/sections-and-placement.doc.mjs +1 -1
- package/assets/docs/tree/template-doc-overview.doc.mjs +13 -1
- package/assets/docs/tree/troubleshooting.doc.mjs +9 -5
- package/assets/docs/tree/versioning.doc.mjs +7 -6
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.doc.mjs +15 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.tsx +38 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.doc.mjs +20 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.tsx +48 -0
- package/assets/templates/pages/ai-chat/template.doc.mjs +16 -1
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +9 -1
- package/assets/templates/pages/blank/template.doc.mjs +3 -1
- package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -1
- package/assets/templates/pages/centered-hero/template.doc.mjs +3 -1
- package/assets/templates/pages/checkout-wizard/template.doc.mjs +1 -0
- package/assets/templates/pages/classic-gallery/template.doc.mjs +3 -1
- package/assets/templates/pages/contact-form/template.doc.mjs +16 -1
- package/assets/templates/pages/dashboard/template.doc.mjs +15 -1
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +23 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +10 -1
- package/assets/templates/pages/dashboard-comparison/template.doc.mjs +9 -1
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +10 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +17 -1
- package/assets/templates/pages/dashboard-scorecard/template.doc.mjs +2 -1
- package/assets/templates/pages/detail-page/template.doc.mjs +8 -0
- package/assets/templates/pages/documentation/template.doc.mjs +10 -1
- package/assets/templates/pages/documentation-design/template.doc.mjs +10 -1
- package/assets/templates/pages/documentation-technical/template.doc.mjs +10 -1
- package/assets/templates/pages/editor/template.doc.mjs +9 -1
- package/assets/templates/pages/file-explorer/template.doc.mjs +3 -1
- package/assets/templates/pages/form-two-column/template.doc.mjs +17 -1
- package/assets/templates/pages/form-wizard/template.doc.mjs +14 -1
- package/assets/templates/pages/form-wizard-dialog/template.doc.mjs +1 -0
- package/assets/templates/pages/gallery-hero/template.doc.mjs +10 -1
- package/assets/templates/pages/ide/template.doc.mjs +9 -1
- package/assets/templates/pages/incident-console/template.doc.mjs +10 -1
- package/assets/templates/pages/kanban-board/template.doc.mjs +11 -1
- package/assets/templates/pages/library/template.doc.mjs +15 -1
- package/assets/templates/pages/login/template.doc.mjs +10 -1
- package/assets/templates/pages/login-card/template.doc.mjs +11 -1
- package/assets/templates/pages/login-split/template.doc.mjs +10 -1
- package/assets/templates/pages/login-sso/template.doc.mjs +10 -1
- package/assets/templates/pages/messaging-shell/template.doc.mjs +11 -1
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +10 -1
- package/assets/templates/pages/payment-form/template.doc.mjs +3 -1
- package/assets/templates/pages/product-detail/template.doc.mjs +9 -1
- package/assets/templates/pages/product-gallery/template.doc.mjs +10 -1
- package/assets/templates/pages/settings/template.doc.mjs +3 -1
- package/assets/templates/pages/settings-dialog/template.doc.mjs +9 -1
- package/assets/templates/pages/settings-sidebar/template.doc.mjs +9 -1
- package/assets/templates/pages/shell-nav/template.doc.mjs +10 -1
- package/assets/templates/pages/shell-side-nav/template.doc.mjs +14 -1
- package/assets/templates/pages/shell-top-nav/template.doc.mjs +11 -1
- package/assets/templates/pages/side-gallery/template.doc.mjs +3 -1
- package/assets/templates/pages/table/template.doc.mjs +11 -1
- package/assets/templates/pages/table-filter/template.doc.mjs +21 -1
- package/assets/templates/pages/table-grouped/template.doc.mjs +15 -1
- package/assets/templates/pages/table-inbox/template.doc.mjs +18 -6
- package/assets/templates/pages/table-page/template.doc.mjs +20 -1
- package/assets/templates/pages/table-tree/template.doc.mjs +14 -1
- package/assets/templates/pages/theme-showcase/template.doc.mjs +10 -1
- package/assets/templates/pages/work-item-detail/template.doc.mjs +10 -0
- package/assets/templates/themes/butter/icons.tsx +2 -0
- package/assets/templates/themes/chocolate/icons.tsx +2 -0
- package/assets/templates/themes/gothic/icons.tsx +2 -0
- package/assets/templates/themes/matcha/icons.tsx +2 -0
- package/assets/templates/themes/neutral/icons.tsx +2 -0
- package/assets/templates/themes/stone/icons.tsx +2 -0
- package/assets/templates/themes/y2k/icons.tsx +2 -0
- package/authoring/doctypes/template/parse.d.mts +2 -0
- package/authoring/doctypes/template/parse.mjs +1 -0
- package/authoring/doctypes/template/parse.test.mjs +21 -0
- package/authoring/doctypes/template/template.doc.mjs +6 -0
- package/authoring/doctypes/template/type.ts +10 -0
- package/clients/cli/commands/build-theme.mjs +8 -2
- package/clients/cli/commands/discover.mjs +29 -1
- package/clients/cli/commands/discover.no-source.test.mjs +75 -0
- package/clients/cli/commands/docs.depth.test.mjs +219 -0
- package/clients/cli/commands/docs.doc.mjs +15 -2
- package/clients/cli/commands/docs.mjs +222 -5
- package/clients/cli/commands/docs.test.mjs +383 -0
- package/clients/cli/commands/doctor.mjs +4 -4
- package/clients/cli/commands/gap-report.mjs +12 -0
- package/clients/cli/commands/gap-report.test.mjs +63 -0
- package/clients/cli/commands/integration-add.doc.mjs +10 -0
- package/clients/cli/commands/integration-authoring.test.mjs +12 -2
- package/clients/cli/commands/integration.mjs +3 -1
- package/clients/cli/commands/layout-expand.doc.mjs +3 -1
- package/clients/cli/commands/layout.expand-receipt.test.mjs +94 -0
- package/clients/cli/commands/layout.mjs +16 -0
- package/clients/cli/commands/search.doc.mjs +5 -4
- package/clients/cli/commands/search.mjs +30 -6
- package/clients/cli/commands/search.test.mjs +60 -16
- package/clients/cli/commands/template.copy-receipt.test.mjs +60 -0
- package/clients/cli/commands/template.mjs +19 -5
- package/clients/cli/commands/template.show-media.test.mjs +62 -0
- package/clients/cli/commands/theme-list.behavior.test.mjs +41 -0
- package/clients/cli/commands/upgrade.ascii-output.test.mjs +14 -0
- package/clients/cli/commands/write-failure.test.mjs +175 -0
- package/clients/cli/lib/manifest.mjs +44 -165
- package/clients/cli/lib/manifest.test.mjs +98 -7
- package/foundation/agent-docs/agent-docs.mjs +2 -1
- package/foundation/agent-docs/agent-docs.test.mjs +1168 -0
- package/foundation/discovery/template-adapter.d.mts +14 -0
- package/foundation/discovery/template-adapter.fixture-refs.test.mjs +37 -1
- package/foundation/discovery/template-adapter.mjs +21 -1
- package/foundation/discovery/theme-discovery.d.mts +6 -0
- package/foundation/discovery/theme-discovery.mjs +9 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +3 -3
- package/foundation/doc-compiler/inputs.test.mjs +0 -1
- package/foundation/doc-compiler/tree.test.mjs +649 -0
- package/foundation/integrations/cli-requirement.d.mts +57 -13
- package/foundation/integrations/cli-requirement.mjs +84 -22
- package/foundation/integrations/cli-requirement.test.mjs +135 -8
- package/foundation/response/response-types.doc.d.mts +5 -5
- package/foundation/response/response-types.doc.mjs +13 -13
- package/package.json +1 -1
package/api/docs/docs.doc.mjs
CHANGED
|
@@ -25,7 +25,8 @@ export const doc = {
|
|
|
25
25
|
'ones the project\'s configured integrations contribute, including any ' +
|
|
26
26
|
'topic an integration replaces or extends, so it depends on the cwd. ' +
|
|
27
27
|
'A route opens a node of the docs tree instead: a namespace such as ' +
|
|
28
|
-
|
|
28
|
+
'`cli/api` returns its children one level down (`depth` reads as many ' +
|
|
29
|
+
'levels as asked, and `detail` how much of each doc below), a typed doc such as ' +
|
|
29
30
|
"`cli/api/functions/search` returns its content, and a guide the tree " +
|
|
30
31
|
'places (`cli/integrations/quick-start`) reads like any topic. ' +
|
|
31
32
|
'Every read but the list carries `links`, the commands that move from it: ' +
|
|
@@ -82,6 +83,18 @@ export const doc = {
|
|
|
82
83
|
description:
|
|
83
84
|
"Return the topic's section index (each section's key, title, and summary), even for a topic with one section.",
|
|
84
85
|
},
|
|
86
|
+
{
|
|
87
|
+
name: 'options.depth',
|
|
88
|
+
type: "number | 'all'",
|
|
89
|
+
description:
|
|
90
|
+
"How many levels below a docs-tree namespace to read: 0 for the namespace alone, 1 for its children (the default), 'all' for every level. Where a read stops, a child with docs below it carries childCount. A doc with nothing below it reads the same at any depth.",
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: 'options.detail',
|
|
94
|
+
type: "'brief' | 'compact' | 'full'",
|
|
95
|
+
description:
|
|
96
|
+
"How much of each doc below the named one a depth read returns: brief (the default) is its identity; compact and full add its text (a guide's sections, a namespace's or typed doc's content). Given alone, it reads one level down.",
|
|
97
|
+
},
|
|
85
98
|
{
|
|
86
99
|
name: 'options.cwd',
|
|
87
100
|
type: 'string',
|
|
@@ -113,10 +126,18 @@ export const doc = {
|
|
|
113
126
|
{
|
|
114
127
|
type: 'docs.node',
|
|
115
128
|
description:
|
|
116
|
-
"A namespace or typed doc in the docs tree, read by its route: {id, route, kind, package, title, summary, breadcrumb, slots, content}. A namespace lists each slot's children one level down; a typed doc carries its content.",
|
|
129
|
+
"A namespace or typed doc in the docs tree, read by its route: {id, route, kind, package, title, summary, breadcrumb, slots, content}. A namespace lists each slot's children one level down, or as deep as depth asks, each child carrying its own slots, childCount where the read stops, and its text at compact or full detail; a typed doc carries its content.",
|
|
117
130
|
},
|
|
118
131
|
],
|
|
119
132
|
throws: [
|
|
133
|
+
{
|
|
134
|
+
code: 'ERR_INVALID_ARGUMENT',
|
|
135
|
+
when: "depth is not a whole number of levels or 'all'",
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
code: 'ERR_INVALID_DETAIL',
|
|
139
|
+
when: 'detail is not brief, compact, or full',
|
|
140
|
+
},
|
|
120
141
|
{
|
|
121
142
|
code: 'ERR_UNKNOWN_TOPIC',
|
|
122
143
|
when: 'the topic is not a string, or matches no topic and no docs-tree route',
|
|
@@ -134,6 +155,14 @@ export const doc = {
|
|
|
134
155
|
code: "await docs('principles', undefined, {index: true});",
|
|
135
156
|
},
|
|
136
157
|
{label: 'A docs-tree namespace', code: "await docs('cli/api');"},
|
|
158
|
+
{
|
|
159
|
+
label: 'Every doc below a namespace, one entry each',
|
|
160
|
+
code: "await docs('cli', undefined, {depth: 'all'});",
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
label: 'A namespace and everything below it, in full',
|
|
164
|
+
code: "await docs('cli/integrations', undefined, {depth: 'all', detail: 'full'});",
|
|
165
|
+
},
|
|
137
166
|
{label: 'One API function', code: "await docs('cli/api/functions/search');"},
|
|
138
167
|
{
|
|
139
168
|
label: 'A whole guide from the docs tree',
|
package/api/docs/docs.mjs
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* docs(topic, undefined, {index: true}) -> index -> docs.index
|
|
12
12
|
* docs(topic, section) -> section -> docs.detail.section
|
|
13
13
|
* docs(route) -> node -> docs.node
|
|
14
|
+
* docs(route, undefined, {depth: 2}) -> node -> docs.node, two levels
|
|
14
15
|
*
|
|
15
16
|
* A topic read returns the whole doc, as it always has; `index` returns its
|
|
16
17
|
* sections, so a reader can open one by its key (spec:AST-047). The CLI's text
|
|
@@ -33,6 +34,43 @@ import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
|
33
34
|
|
|
34
35
|
export {list, index, detail, sectionLeaf as section, nodeLeaf as node};
|
|
35
36
|
|
|
37
|
+
const DETAILS = ['brief', 'compact', 'full'];
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* How far a docs-tree read goes, from the options: `depth` levels below the
|
|
41
|
+
* node, or every level for `'all'`, and `detail` for each doc below it (brief
|
|
42
|
+
* by default). `detail` alone reads one level down. Neither: the plain read.
|
|
43
|
+
* @param {import('./docs.type.mjs').DocsOptions} options
|
|
44
|
+
* @returns {import('./node/node.mjs').DepthRead | undefined}
|
|
45
|
+
*/
|
|
46
|
+
function depthRead(options) {
|
|
47
|
+
const {depth, detail} = options;
|
|
48
|
+
if (detail != null && !DETAILS.includes(detail)) {
|
|
49
|
+
throw new AstryxError(
|
|
50
|
+
`detail is brief, compact, or full, not ${JSON.stringify(detail)}.`,
|
|
51
|
+
undefined,
|
|
52
|
+
ERROR_CODES.ERR_INVALID_DETAIL,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
if (
|
|
56
|
+
depth != null &&
|
|
57
|
+
depth !== 'all' &&
|
|
58
|
+
!(Number.isInteger(depth) && /** @type {number} */ (depth) >= 0)
|
|
59
|
+
) {
|
|
60
|
+
throw new AstryxError(
|
|
61
|
+
`depth is a number of levels (0, 1, 2, ...) or "all", not ${JSON.stringify(depth)}.`,
|
|
62
|
+
undefined,
|
|
63
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
if (depth == null && detail == null) return undefined;
|
|
67
|
+
return {
|
|
68
|
+
depth: depth === 'all' ? Infinity : (depth ?? 1),
|
|
69
|
+
detail: /** @type {'brief' | 'compact' | 'full'} */ (detail ?? 'brief'),
|
|
70
|
+
lang: options.lang || (options.dense ? 'dense' : options.zh ? 'zh' : null),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
36
74
|
/**
|
|
37
75
|
* @param {string} [topic]
|
|
38
76
|
* @param {string} [section]
|
|
@@ -42,6 +80,10 @@ export {list, index, detail, sectionLeaf as section, nodeLeaf as node};
|
|
|
42
80
|
* @param {boolean} [options.dense]
|
|
43
81
|
* @param {boolean} [options.index] return the topic's section index instead of
|
|
44
82
|
* the whole doc
|
|
83
|
+
* @param {number | 'all'} [options.depth] how many levels below a docs-tree
|
|
84
|
+
* namespace to read; a doc with nothing below it reads the same at any depth
|
|
85
|
+
* @param {'brief' | 'compact' | 'full'} [options.detail] how much of each doc
|
|
86
|
+
* below the named one a depth read returns (brief by default)
|
|
45
87
|
* @param {string} [options.cwd]
|
|
46
88
|
* @returns {Promise<
|
|
47
89
|
* import('./docs.type.mjs').DocsListResponse |
|
|
@@ -52,6 +94,7 @@ export {list, index, detail, sectionLeaf as section, nodeLeaf as node};
|
|
|
52
94
|
* >}
|
|
53
95
|
*/
|
|
54
96
|
export async function docs(topic, section, options = {}) {
|
|
97
|
+
const read = depthRead(options);
|
|
55
98
|
if (!topic) return list(options);
|
|
56
99
|
const found = await resolveDocsArgument(topic, options);
|
|
57
100
|
if (found.kind === 'node') {
|
|
@@ -77,7 +120,7 @@ export async function docs(topic, section, options = {}) {
|
|
|
77
120
|
}
|
|
78
121
|
return {
|
|
79
122
|
type: 'docs.node',
|
|
80
|
-
data: await nodeView(found.catalog, found.tree, found.node),
|
|
123
|
+
data: await nodeView(found.catalog, found.tree, found.node, read),
|
|
81
124
|
};
|
|
82
125
|
}
|
|
83
126
|
if (section) return sectionLeaf(topic, section, options);
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Dispatcher-level tests for docs() — the argument-shape routing that
|
|
5
|
+
* sits above the list/detail/section leaves. The leaves have their own tests;
|
|
6
|
+
* this pins the router: docs() -> list, docs(topic) -> detail,
|
|
7
|
+
* docs(topic, section) -> section, plus the unknown-topic/section error codes.
|
|
8
|
+
* Runs against the real CLI-bundled docs (no cwd/project needed).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {describe, it, expect} from 'vitest';
|
|
12
|
+
import {docs} from './docs.mjs';
|
|
13
|
+
import {AstryxError} from '../error.mjs';
|
|
14
|
+
|
|
15
|
+
const SLOW = 30_000;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The first guide a namespace places, read from the tree rather than named,
|
|
19
|
+
* so a restructure of the guides does not break the reads under test.
|
|
20
|
+
* @param {any} node the data of a docs.node read
|
|
21
|
+
* @returns {string}
|
|
22
|
+
*/
|
|
23
|
+
function placedGuide(node) {
|
|
24
|
+
const guide = node.slots
|
|
25
|
+
.flatMap((/** @type {any} */ slot) => slot.children)
|
|
26
|
+
.find((/** @type {any} */ child) => child.kind === 'generic');
|
|
27
|
+
if (guide == null) throw new Error(`${node.route} places no guide`);
|
|
28
|
+
return guide.route;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe('docs() dispatcher routing', () => {
|
|
32
|
+
it('no topic -> docs.list', async () => {
|
|
33
|
+
const r = await docs();
|
|
34
|
+
expect(r.type).toBe('docs.list');
|
|
35
|
+
expect(Array.isArray(r.data)).toBe(true);
|
|
36
|
+
expect(r.data.length).toBeGreaterThan(0);
|
|
37
|
+
}, SLOW);
|
|
38
|
+
|
|
39
|
+
it('empty topic -> docs.list (falsy topic routes to list)', async () => {
|
|
40
|
+
expect((await docs('')).type).toBe('docs.list');
|
|
41
|
+
}, SLOW);
|
|
42
|
+
|
|
43
|
+
it('topic only -> docs.detail, the whole doc', async () => {
|
|
44
|
+
const {data} = await docs();
|
|
45
|
+
expect((await docs(data[0].topic)).type).toBe('docs.detail');
|
|
46
|
+
}, SLOW);
|
|
47
|
+
|
|
48
|
+
it('topic + index -> docs.index', async () => {
|
|
49
|
+
const {data} = await docs();
|
|
50
|
+
const r = await docs(data[0].topic, undefined, {index: true});
|
|
51
|
+
expect(r.type).toBe('docs.index');
|
|
52
|
+
}, SLOW);
|
|
53
|
+
|
|
54
|
+
it('reads a shortened section by its old key, which its title still derives', async () => {
|
|
55
|
+
const r = await docs(
|
|
56
|
+
'styling',
|
|
57
|
+
'stylex-build-setup-required-for-swizzled-components',
|
|
58
|
+
);
|
|
59
|
+
expect(r.type).toBe('docs.detail.section');
|
|
60
|
+
expect(r.data).toMatchObject({id: 'stylex-setup'});
|
|
61
|
+
}, SLOW);
|
|
62
|
+
|
|
63
|
+
it('topic + section -> docs.detail.section', async () => {
|
|
64
|
+
const {data} = await docs();
|
|
65
|
+
let routed = null;
|
|
66
|
+
for (const {topic} of data) {
|
|
67
|
+
const detail = await docs(topic);
|
|
68
|
+
const sections = detail.data.sections;
|
|
69
|
+
if (Array.isArray(sections) && sections.length > 0) {
|
|
70
|
+
routed = await docs(topic, sections[0].title);
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
expect(routed).not.toBeNull();
|
|
75
|
+
expect(routed.type).toBe('docs.detail.section');
|
|
76
|
+
}, SLOW);
|
|
77
|
+
|
|
78
|
+
it('unknown topic -> ERR_UNKNOWN_TOPIC', async () => {
|
|
79
|
+
await expect(docs('zzz-not-a-real-topic')).rejects.toBeInstanceOf(AstryxError);
|
|
80
|
+
await expect(docs('zzz-not-a-real-topic')).rejects.toMatchObject({
|
|
81
|
+
code: 'ERR_UNKNOWN_TOPIC',
|
|
82
|
+
});
|
|
83
|
+
}, SLOW);
|
|
84
|
+
|
|
85
|
+
it('known topic + unknown section -> ERR_UNKNOWN_SECTION', async () => {
|
|
86
|
+
const {data} = await docs();
|
|
87
|
+
const topic = data[0].topic;
|
|
88
|
+
await expect(docs(topic, 'zzz-not-a-real-section')).rejects.toMatchObject({
|
|
89
|
+
code: 'ERR_UNKNOWN_SECTION',
|
|
90
|
+
});
|
|
91
|
+
}, SLOW);
|
|
92
|
+
|
|
93
|
+
it("lists the docs tree's namespaces in meta, so every data entry reads as a topic", async () => {
|
|
94
|
+
const res = await docs();
|
|
95
|
+
expect(res.meta.namespaces.map(entry => entry.topic)).toEqual(['cli', 'unorganized']);
|
|
96
|
+
for (const entry of res.data) {
|
|
97
|
+
expect((await docs(entry.topic)).type).toBe('docs.detail');
|
|
98
|
+
}
|
|
99
|
+
}, SLOW);
|
|
100
|
+
|
|
101
|
+
it('opens a route typed in another case', async () => {
|
|
102
|
+
const r = await docs('CLI/API');
|
|
103
|
+
expect(r.type).toBe('docs.node');
|
|
104
|
+
expect(r.data).toMatchObject({route: 'cli/api', links: {up: 'astryx docs cli'}});
|
|
105
|
+
}, SLOW);
|
|
106
|
+
|
|
107
|
+
it('a section of a typed doc -> ERR_UNKNOWN_SECTION, suggesting the doc itself', async () => {
|
|
108
|
+
const err = await docs('cli/api/functions/search', 'x').catch(e => e);
|
|
109
|
+
expect(err.code).toBe('ERR_UNKNOWN_SECTION');
|
|
110
|
+
expect(err.message).toContain('astryx docs cli/api/functions/search');
|
|
111
|
+
expect(err.suggestions.map(s => s.name)).toEqual(['cli/api/functions/search']);
|
|
112
|
+
}, SLOW);
|
|
113
|
+
|
|
114
|
+
it('a namespace route -> docs.node, one level of children', async () => {
|
|
115
|
+
const r = await docs('cli/api');
|
|
116
|
+
expect(r.type).toBe('docs.node');
|
|
117
|
+
expect(r.data).toMatchObject({
|
|
118
|
+
id: 'astryx:artifact:v1/%40astryxdesign%2Fcli/namespace/api',
|
|
119
|
+
route: 'cli/api',
|
|
120
|
+
kind: 'namespace',
|
|
121
|
+
package: '@astryxdesign/cli',
|
|
122
|
+
breadcrumb: [{route: 'cli', title: 'Astryx CLI'}],
|
|
123
|
+
content: [],
|
|
124
|
+
});
|
|
125
|
+
expect(r.data.slots.flatMap(slot => slot.children.map(c => c.route))).toEqual([
|
|
126
|
+
'cli/api/functions',
|
|
127
|
+
'cli/api/schemas',
|
|
128
|
+
'cli/api/enums',
|
|
129
|
+
]);
|
|
130
|
+
}, SLOW);
|
|
131
|
+
|
|
132
|
+
it('a typed doc route -> docs.node with its content', async () => {
|
|
133
|
+
const r = await docs('cli/api/functions/search');
|
|
134
|
+
expect(r.type).toBe('docs.node');
|
|
135
|
+
expect(r.data).toMatchObject({
|
|
136
|
+
id: 'astryx:artifact:v1/%40astryxdesign%2Fcli/function/search',
|
|
137
|
+
kind: 'function',
|
|
138
|
+
title: 'search()',
|
|
139
|
+
slots: [],
|
|
140
|
+
});
|
|
141
|
+
expect(r.data.breadcrumb.map(link => link.route)).toEqual([
|
|
142
|
+
'cli',
|
|
143
|
+
'cli/api',
|
|
144
|
+
'cli/api/functions',
|
|
145
|
+
]);
|
|
146
|
+
expect(JSON.stringify(r.data.content)).toContain(
|
|
147
|
+
'`astryx search` runs it. Read it with `astryx docs cli/commands/search`.',
|
|
148
|
+
);
|
|
149
|
+
}, SLOW);
|
|
150
|
+
|
|
151
|
+
it('a guide the tree places reads like a topic: the whole doc, its index, a section', async () => {
|
|
152
|
+
// cli/integrations is a namespace of short guides; each guide reads like a topic.
|
|
153
|
+
const integrations = await docs('cli/integrations');
|
|
154
|
+
expect(integrations.type).toBe('docs.node');
|
|
155
|
+
const guide = placedGuide(integrations.data);
|
|
156
|
+
expect((await docs(guide)).type).toBe('docs.detail');
|
|
157
|
+
const index = await docs(guide, undefined, {index: true});
|
|
158
|
+
expect(index).toMatchObject({type: 'docs.index', data: {name: guide}});
|
|
159
|
+
expect(index.data.sections.length).toBeGreaterThan(1);
|
|
160
|
+
expect((await docs(guide, index.data.sections[0].id)).type).toBe(
|
|
161
|
+
'docs.detail.section',
|
|
162
|
+
);
|
|
163
|
+
}, SLOW);
|
|
164
|
+
|
|
165
|
+
it('every read carries its moves (spec:AST-047)', async () => {
|
|
166
|
+
const root = (await docs('cli')).data;
|
|
167
|
+
expect(root.links).toEqual({up: 'astryx docs'});
|
|
168
|
+
const leaf = (await docs('cli/api/functions/search')).data;
|
|
169
|
+
expect(leaf.links.up).toBe('astryx docs cli/api/functions');
|
|
170
|
+
expect(leaf.links.previous).toMatch(/^astryx docs cli\/api\/functions\/[a-z-]+$/);
|
|
171
|
+
expect(leaf.links.next).toMatch(/^astryx docs cli\/api\/functions\/[a-z-]+$/);
|
|
172
|
+
const integrations = (await docs('cli/integrations')).data;
|
|
173
|
+
const guide = placedGuide(integrations);
|
|
174
|
+
const siblings = integrations.slots
|
|
175
|
+
.find(slot => slot.children.some(child => child.route === guide))
|
|
176
|
+
.children.map(child => child.route);
|
|
177
|
+
const at = siblings.indexOf(guide);
|
|
178
|
+
const index = await docs(guide, undefined, {index: true});
|
|
179
|
+
// A guide moves across its namespace's slot, as any tree node does.
|
|
180
|
+
expect(index.data.links).toEqual({
|
|
181
|
+
up: 'astryx docs cli/integrations',
|
|
182
|
+
...(at > 0 ? {previous: `astryx docs ${siblings[at - 1]}`} : {}),
|
|
183
|
+
...(at < siblings.length - 1
|
|
184
|
+
? {next: `astryx docs ${siblings[at + 1]}`}
|
|
185
|
+
: {}),
|
|
186
|
+
});
|
|
187
|
+
const first = (await docs(guide, index.data.sections[0].id)).data;
|
|
188
|
+
expect(first.links).toEqual({
|
|
189
|
+
up: `astryx docs ${guide} --index`,
|
|
190
|
+
next: `astryx docs ${guide} ${index.data.sections[1].id}`,
|
|
191
|
+
});
|
|
192
|
+
const last = index.data.sections.at(-1).id;
|
|
193
|
+
const end = (await docs(guide, last)).data;
|
|
194
|
+
expect(end.links.next).toBeUndefined();
|
|
195
|
+
expect(end.links.previous).toBe(
|
|
196
|
+
`astryx docs ${guide} ${index.data.sections.at(-2).id}`,
|
|
197
|
+
);
|
|
198
|
+
// A flat topic's home is the Unorganized level, and it moves across it.
|
|
199
|
+
const flat = (await docs('principles')).data.links;
|
|
200
|
+
expect(flat.up).toBe('astryx docs unorganized');
|
|
201
|
+
expect(flat.previous).toMatch(/^astryx docs [a-z-]+$/);
|
|
202
|
+
expect(flat.next).toMatch(/^astryx docs [a-z-]+$/);
|
|
203
|
+
const home = (await docs('unorganized')).data;
|
|
204
|
+
expect(home).toMatchObject({id: null, kind: 'namespace', links: {up: 'astryx docs'}});
|
|
205
|
+
expect(home.slots[0].children.map(child => child.route)).toEqual(
|
|
206
|
+
(await docs()).data.map(entry => entry.topic),
|
|
207
|
+
);
|
|
208
|
+
}, SLOW);
|
|
209
|
+
|
|
210
|
+
it('names a node by its doc identity; a generated level has id null', async () => {
|
|
211
|
+
const level = (await docs('cli/api/functions')).data;
|
|
212
|
+
expect(level).toHaveProperty('id', null);
|
|
213
|
+
expect(level.route).toBe('cli/api/functions');
|
|
214
|
+
}, SLOW);
|
|
215
|
+
|
|
216
|
+
it("offers a typed doc's related docs as moves", async () => {
|
|
217
|
+
const fn = (await docs('cli/api/functions/search')).data;
|
|
218
|
+
expect(fn.links.related).toContain('astryx docs cli/commands/search');
|
|
219
|
+
const cmd = (await docs('cli/commands/search')).data;
|
|
220
|
+
expect(cmd.links.related).toContain('astryx docs cli/api/functions/search');
|
|
221
|
+
}, SLOW);
|
|
222
|
+
|
|
223
|
+
it('a topic read returns the whole doc; index returns its sections', async () => {
|
|
224
|
+
expect((await docs('principles')).type).toBe('docs.detail');
|
|
225
|
+
const index = await docs('principles', undefined, {index: true});
|
|
226
|
+
expect(index.type).toBe('docs.index');
|
|
227
|
+
expect(index.data.sections.length).toBeGreaterThan(1);
|
|
228
|
+
expect((await docs('principles', undefined, {dense: true})).type).toBe(
|
|
229
|
+
'docs.detail',
|
|
230
|
+
);
|
|
231
|
+
}, SLOW);
|
|
232
|
+
|
|
233
|
+
it("the guide's old flat name is gone, and its error names the new route", async () => {
|
|
234
|
+
await expect(docs('cli-integrations')).rejects.toMatchObject({
|
|
235
|
+
code: 'ERR_UNKNOWN_TOPIC',
|
|
236
|
+
suggestions: [expect.objectContaining({name: 'cli/integrations'})],
|
|
237
|
+
});
|
|
238
|
+
expect((await docs()).data.map(entry => entry.topic)).not.toContain(
|
|
239
|
+
'cli-integrations',
|
|
240
|
+
);
|
|
241
|
+
}, SLOW);
|
|
242
|
+
|
|
243
|
+
it('a section of a namespace -> ERR_UNKNOWN_SECTION, naming its children', async () => {
|
|
244
|
+
const err = await docs('cli', 'commands').catch(e => e);
|
|
245
|
+
expect(err).toBeInstanceOf(AstryxError);
|
|
246
|
+
expect(err.code).toBe('ERR_UNKNOWN_SECTION');
|
|
247
|
+
// It names the namespace's children, in the order its slots list them.
|
|
248
|
+
const cli = (await docs('cli')).data;
|
|
249
|
+
expect(err.suggestions.map(s => s.name)).toEqual(
|
|
250
|
+
cli.slots.flatMap(slot => slot.children.map(child => child.route)),
|
|
251
|
+
);
|
|
252
|
+
expect(err.suggestions.map(s => s.name)).toContain('cli/commands');
|
|
253
|
+
}, SLOW);
|
|
254
|
+
|
|
255
|
+
it('an unknown route suggests the children of the deepest namespace it reaches', async () => {
|
|
256
|
+
const err = await docs('cli/api/functions/serch').catch(e => e);
|
|
257
|
+
expect(err.code).toBe('ERR_UNKNOWN_TOPIC');
|
|
258
|
+
expect(err.suggestions.map(s => s.name)).toContain('cli/api/functions/search');
|
|
259
|
+
expect(err.suggestions.every(s => s.name.startsWith('cli/api/functions/'))).toBe(true);
|
|
260
|
+
}, SLOW);
|
|
261
|
+
|
|
262
|
+
it('non-string topic -> ERR_UNKNOWN_TOPIC (not a raw TypeError)', async () => {
|
|
263
|
+
for (const bad of [123, {}, ['tokens'], true]) {
|
|
264
|
+
const err = await docs(/** @type {any} */ (bad)).catch(e => e);
|
|
265
|
+
expect(err).toBeInstanceOf(AstryxError);
|
|
266
|
+
expect(err.code).toBe('ERR_UNKNOWN_TOPIC');
|
|
267
|
+
}
|
|
268
|
+
}, SLOW);
|
|
269
|
+
|
|
270
|
+
it('non-string section -> ERR_UNKNOWN_SECTION (not a raw TypeError)', async () => {
|
|
271
|
+
const {data} = await docs();
|
|
272
|
+
const topic = data[0].topic;
|
|
273
|
+
for (const bad of [456, {}, ['x']]) {
|
|
274
|
+
const err = await docs(topic, /** @type {any} */ (bad)).catch(e => e);
|
|
275
|
+
expect(err).toBeInstanceOf(AstryxError);
|
|
276
|
+
expect(err.code).toBe('ERR_UNKNOWN_SECTION');
|
|
277
|
+
}
|
|
278
|
+
}, SLOW);
|
|
279
|
+
});
|
package/api/docs/docs.type.d.mts
CHANGED
|
@@ -205,9 +205,14 @@ export type DocsNode = {
|
|
|
205
205
|
breadcrumb: DocsNodeLink[];
|
|
206
206
|
/**
|
|
207
207
|
* a namespace's slots that hold children, in
|
|
208
|
-
* order; empty for a typed doc
|
|
208
|
+
* order; empty for a typed doc, and for a depth read of 0
|
|
209
209
|
*/
|
|
210
210
|
slots: DocsNodeSlot[];
|
|
211
|
+
/**
|
|
212
|
+
* with a depth read of 0, how many docs sit
|
|
213
|
+
* right below the namespace
|
|
214
|
+
*/
|
|
215
|
+
childCount?: number | undefined;
|
|
211
216
|
/**
|
|
212
217
|
* a typed doc's content; empty for a namespace
|
|
213
218
|
*/
|
|
@@ -246,6 +251,26 @@ export type DocsNodeChild = {
|
|
|
246
251
|
kind: string;
|
|
247
252
|
title: string;
|
|
248
253
|
summary: string;
|
|
254
|
+
/**
|
|
255
|
+
* with a depth read, its own slots, while
|
|
256
|
+
* the read goes deeper
|
|
257
|
+
*/
|
|
258
|
+
slots?: DocsNodeSlot[] | undefined;
|
|
259
|
+
/**
|
|
260
|
+
* with a depth read, how many docs sit right
|
|
261
|
+
* below it where the read stops
|
|
262
|
+
*/
|
|
263
|
+
childCount?: number | undefined;
|
|
264
|
+
/**
|
|
265
|
+
* with a depth read at compact or full detail: a namespace's intro or a typed
|
|
266
|
+
* doc's content
|
|
267
|
+
*/
|
|
268
|
+
content?: import("@astryxdesign/cli/authoring").ReferenceContentBlock[] | undefined;
|
|
269
|
+
/**
|
|
270
|
+
* with a depth read at compact or full
|
|
271
|
+
* detail: a guide's sections
|
|
272
|
+
*/
|
|
273
|
+
sections?: DocsReadSection[] | undefined;
|
|
249
274
|
};
|
|
250
275
|
/**
|
|
251
276
|
* Options for `docs()`.
|
|
@@ -259,6 +284,18 @@ export type DocsOptions = {
|
|
|
259
284
|
* whole doc
|
|
260
285
|
*/
|
|
261
286
|
index?: boolean | undefined;
|
|
287
|
+
/**
|
|
288
|
+
* how many levels below a docs-tree
|
|
289
|
+
* namespace to read: 0 for the namespace alone, 1 for its children (the
|
|
290
|
+
* default), 'all' for every level
|
|
291
|
+
*/
|
|
292
|
+
depth?: number | "all" | undefined;
|
|
293
|
+
/**
|
|
294
|
+
* how much of each doc below
|
|
295
|
+
* the named one a depth read returns: brief (the default) is its identity,
|
|
296
|
+
* compact and full add its text
|
|
297
|
+
*/
|
|
298
|
+
detail?: "compact" | "full" | "brief" | undefined;
|
|
262
299
|
/**
|
|
263
300
|
* project directory whose configured integrations
|
|
264
301
|
* contribute topics; defaults to process.cwd()
|
package/api/docs/docs.type.mjs
CHANGED
|
@@ -153,7 +153,9 @@
|
|
|
153
153
|
* @property {string} summary
|
|
154
154
|
* @property {DocsNodeLink[]} breadcrumb the namespaces above it, top first
|
|
155
155
|
* @property {DocsNodeSlot[]} slots a namespace's slots that hold children, in
|
|
156
|
-
* order; empty for a typed doc
|
|
156
|
+
* order; empty for a typed doc, and for a depth read of 0
|
|
157
|
+
* @property {number} [childCount] with a depth read of 0, how many docs sit
|
|
158
|
+
* right below the namespace
|
|
157
159
|
* @property {import('@astryxdesign/cli/authoring').ReferenceContentBlock[]} content
|
|
158
160
|
* a typed doc's content; empty for a namespace
|
|
159
161
|
* @property {DocsLinks} links the moves from the node: up to its parent (the
|
|
@@ -181,6 +183,15 @@
|
|
|
181
183
|
* @property {string} kind
|
|
182
184
|
* @property {string} title
|
|
183
185
|
* @property {string} summary
|
|
186
|
+
* @property {DocsNodeSlot[]} [slots] with a depth read, its own slots, while
|
|
187
|
+
* the read goes deeper
|
|
188
|
+
* @property {number} [childCount] with a depth read, how many docs sit right
|
|
189
|
+
* below it where the read stops
|
|
190
|
+
* @property {import('@astryxdesign/cli/authoring').ReferenceContentBlock[]} [content]
|
|
191
|
+
* with a depth read at compact or full detail: a namespace's intro or a typed
|
|
192
|
+
* doc's content
|
|
193
|
+
* @property {DocsReadSection[]} [sections] with a depth read at compact or full
|
|
194
|
+
* detail: a guide's sections
|
|
184
195
|
*/
|
|
185
196
|
|
|
186
197
|
/**
|
|
@@ -191,6 +202,12 @@
|
|
|
191
202
|
* @property {boolean} [dense]
|
|
192
203
|
* @property {boolean} [index] return a topic's section index instead of its
|
|
193
204
|
* whole doc
|
|
205
|
+
* @property {number | 'all'} [depth] how many levels below a docs-tree
|
|
206
|
+
* namespace to read: 0 for the namespace alone, 1 for its children (the
|
|
207
|
+
* default), 'all' for every level
|
|
208
|
+
* @property {'brief' | 'compact' | 'full'} [detail] how much of each doc below
|
|
209
|
+
* the named one a depth read returns: brief (the default) is its identity,
|
|
210
|
+
* compact and full add its text
|
|
194
211
|
* @property {string} [cwd] project directory whose configured integrations
|
|
195
212
|
* contribute topics; defaults to process.cwd()
|
|
196
213
|
*/
|