@astryxdesign/cli 0.6.5-vanilla-poc.6e25cfc → 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.
Files changed (197) hide show
  1. package/CHANGELOG.md +84 -0
  2. package/README.md +1 -34
  3. package/api/build/_adapter.d.mts +14 -0
  4. package/api/build/_adapter.mjs +58 -1
  5. package/api/build/build.test.mjs +74 -1
  6. package/api/build/kit/kit.mjs +39 -7
  7. package/api/build/kit/rank.d.mts +8 -0
  8. package/api/build/kit/rank.mjs +14 -0
  9. package/api/build/kit/weights.d.mts +82 -0
  10. package/api/build/kit/weights.json +1 -0
  11. package/api/build/kit/weights.mjs +305 -0
  12. package/api/build/kit/weights.test.mjs +190 -0
  13. package/api/component/_adapter.d.mts +1 -51
  14. package/api/component/_adapter.mjs +3 -110
  15. package/api/component/component.d.mts +1 -9
  16. package/api/component/component.doc.mjs +7 -52
  17. package/api/component/component.mjs +3 -276
  18. package/api/component/component.type.d.mts +1 -28
  19. package/api/component/component.type.mjs +1 -20
  20. package/api/docs/docs.d.mts +6 -0
  21. package/api/docs/docs.depth.test.mjs +132 -0
  22. package/api/docs/docs.doc.mjs +31 -2
  23. package/api/docs/docs.mjs +44 -1
  24. package/api/docs/docs.type.d.mts +38 -1
  25. package/api/docs/docs.type.mjs +18 -1
  26. package/api/docs/node/node.d.mts +28 -3
  27. package/api/docs/node/node.mjs +146 -23
  28. package/api/hook/list/list.d.mts +1 -1
  29. package/api/index.d.mts +0 -8
  30. package/api/index.mjs +0 -8
  31. package/api/integration/add-theme.mjs +93 -3
  32. package/api/integration/add-theme.test.mjs +100 -0
  33. package/api/integration/integrationAddTheme.doc.mjs +1 -1
  34. package/api/search/search.d.mts +8 -1
  35. package/api/search/search.doc.mjs +3 -3
  36. package/api/search/search.mjs +58 -73
  37. package/api/search/search.test.mjs +122 -21
  38. package/api/search/search.type.d.mts +0 -10
  39. package/api/search/search.type.mjs +0 -1
  40. package/api/template/cdn/cdn.test.mjs +2 -50
  41. package/api/template/template.d.mts +0 -6
  42. package/api/template/template.doc.mjs +4 -56
  43. package/api/template/template.mjs +0 -82
  44. package/api/template/template.type.d.mts +0 -12
  45. package/api/template/template.type.mjs +0 -7
  46. package/assets/cdn.template.html +5 -19
  47. package/assets/docs/tokens.doc.mjs +3 -3
  48. package/assets/docs/tree/add-a-theme.doc.mjs +4 -0
  49. package/assets/docs/tree/troubleshooting.doc.mjs +4 -4
  50. package/clients/cli/commands/component/index.mjs +9 -66
  51. package/clients/cli/commands/component.doc.mjs +4 -26
  52. package/clients/cli/commands/docs.depth.test.mjs +219 -0
  53. package/clients/cli/commands/docs.doc.mjs +15 -2
  54. package/clients/cli/commands/docs.mjs +222 -5
  55. package/clients/cli/commands/integration-add.doc.mjs +1 -1
  56. package/clients/cli/commands/search.doc.mjs +2 -3
  57. package/clients/cli/commands/search.mjs +11 -8
  58. package/clients/cli/commands/search.test.mjs +35 -40
  59. package/clients/cli/commands/template.doc.mjs +3 -31
  60. package/clients/cli/commands/template.mjs +2 -37
  61. package/foundation/discovery/theme-discovery.d.mts +6 -0
  62. package/foundation/discovery/theme-discovery.mjs +9 -0
  63. package/foundation/response/response-types.doc.mjs +0 -38
  64. package/package.json +5 -9
  65. package/api/_vanilla-assets.d.mts +0 -10
  66. package/api/_vanilla-assets.mjs +0 -59
  67. package/api/component/html/html.d.mts +0 -12
  68. package/api/component/html/html.doc.d.mts +0 -5
  69. package/api/component/html/html.doc.mjs +0 -66
  70. package/api/component/html/html.mjs +0 -25
  71. package/api/component/html/html.test.mjs +0 -61
  72. package/api/component/html/html.type.d.mts +0 -23
  73. package/api/component/html/html.type.mjs +0 -27
  74. package/api/component/web-components/web-components.d.mts +0 -12
  75. package/api/component/web-components/web-components.doc.d.mts +0 -5
  76. package/api/component/web-components/web-components.doc.mjs +0 -70
  77. package/api/component/web-components/web-components.mjs +0 -32
  78. package/api/component/web-components/web-components.test.mjs +0 -50
  79. package/api/component/web-components/web-components.type.d.mts +0 -23
  80. package/api/component/web-components/web-components.type.mjs +0 -27
  81. package/api/template/_adapter.d.mts +0 -38
  82. package/api/template/_adapter.mjs +0 -90
  83. package/api/template/html/html.d.mts +0 -17
  84. package/api/template/html/html.doc.d.mts +0 -5
  85. package/api/template/html/html.doc.mjs +0 -72
  86. package/api/template/html/html.mjs +0 -61
  87. package/api/template/html/html.test.mjs +0 -71
  88. package/api/template/html/html.type.d.mts +0 -26
  89. package/api/template/html/html.type.mjs +0 -28
  90. package/api/template/web-components/web-components.d.mts +0 -13
  91. package/api/template/web-components/web-components.doc.d.mts +0 -5
  92. package/api/template/web-components/web-components.doc.mjs +0 -69
  93. package/api/template/web-components/web-components.mjs +0 -51
  94. package/api/template/web-components/web-components.test.mjs +0 -73
  95. package/api/template/web-components/web-components.type.d.mts +0 -26
  96. package/api/template/web-components/web-components.type.mjs +0 -28
  97. package/assets/generated/core-component-docs.json +0 -1
  98. package/assets/vanilla/elements-markup/Avatar.html +0 -27
  99. package/assets/vanilla/elements-markup/Badge.html +0 -16
  100. package/assets/vanilla/elements-markup/Banner.html +0 -32
  101. package/assets/vanilla/elements-markup/Breadcrumbs.html +0 -23
  102. package/assets/vanilla/elements-markup/Button.html +0 -37
  103. package/assets/vanilla/elements-markup/Card.html +0 -24
  104. package/assets/vanilla/elements-markup/CheckboxInput.html +0 -28
  105. package/assets/vanilla/elements-markup/Collapsible.html +0 -26
  106. package/assets/vanilla/elements-markup/DateInput.html +0 -28
  107. package/assets/vanilla/elements-markup/Dialog.html +0 -33
  108. package/assets/vanilla/elements-markup/Divider.html +0 -20
  109. package/assets/vanilla/elements-markup/DropdownMenu.html +0 -26
  110. package/assets/vanilla/elements-markup/EmptyState.html +0 -27
  111. package/assets/vanilla/elements-markup/Heading.html +0 -18
  112. package/assets/vanilla/elements-markup/HoverCard.html +0 -39
  113. package/assets/vanilla/elements-markup/Layout.html +0 -28
  114. package/assets/vanilla/elements-markup/Lightbox.html +0 -33
  115. package/assets/vanilla/elements-markup/Link.html +0 -23
  116. package/assets/vanilla/elements-markup/NumberInput.html +0 -34
  117. package/assets/vanilla/elements-markup/ProgressBar.html +0 -47
  118. package/assets/vanilla/elements-markup/RadioList.html +0 -28
  119. package/assets/vanilla/elements-markup/Selector.html +0 -34
  120. package/assets/vanilla/elements-markup/SideNav.html +0 -32
  121. package/assets/vanilla/elements-markup/Skeleton.html +0 -18
  122. package/assets/vanilla/elements-markup/Slider.html +0 -31
  123. package/assets/vanilla/elements-markup/Stack.html +0 -33
  124. package/assets/vanilla/elements-markup/StatusDot.html +0 -19
  125. package/assets/vanilla/elements-markup/Switch.html +0 -28
  126. package/assets/vanilla/elements-markup/Tab.html +0 -18
  127. package/assets/vanilla/elements-markup/TabList.html +0 -31
  128. package/assets/vanilla/elements-markup/Table.html +0 -31
  129. package/assets/vanilla/elements-markup/Text.html +0 -24
  130. package/assets/vanilla/elements-markup/TextArea.html +0 -32
  131. package/assets/vanilla/elements-markup/TextInput.html +0 -92
  132. package/assets/vanilla/elements-markup/Theme.html +0 -16
  133. package/assets/vanilla/elements-markup/TimeInput.html +0 -29
  134. package/assets/vanilla/elements-markup/Toast.html +0 -22
  135. package/assets/vanilla/elements-markup/Tooltip.html +0 -30
  136. package/assets/vanilla/elements-markup/TopNav.html +0 -85
  137. package/assets/vanilla/elements-markup/Typeahead.html +0 -31
  138. package/assets/vanilla/elements-templates/dashboard.html +0 -167
  139. package/assets/vanilla/elements-templates/detail-page.html +0 -145
  140. package/assets/vanilla/elements-templates/form-two-column.html +0 -135
  141. package/assets/vanilla/elements-templates/kanban-board.html +0 -141
  142. package/assets/vanilla/elements-templates/login.html +0 -100
  143. package/assets/vanilla/elements-templates/product-detail.html +0 -128
  144. package/assets/vanilla/elements-templates/settings.html +0 -130
  145. package/assets/vanilla/elements-templates/shell-side-nav.html +0 -160
  146. package/assets/vanilla/elements-templates/table-filter.html +0 -154
  147. package/assets/vanilla/markup/Avatar.html +0 -24
  148. package/assets/vanilla/markup/Badge.html +0 -12
  149. package/assets/vanilla/markup/Banner.html +0 -49
  150. package/assets/vanilla/markup/Breadcrumbs.html +0 -38
  151. package/assets/vanilla/markup/Button.html +0 -37
  152. package/assets/vanilla/markup/Card.html +0 -16
  153. package/assets/vanilla/markup/CheckboxInput.html +0 -45
  154. package/assets/vanilla/markup/Collapsible.html +0 -9
  155. package/assets/vanilla/markup/DateInput.html +0 -42
  156. package/assets/vanilla/markup/Dialog.html +0 -45
  157. package/assets/vanilla/markup/Divider.html +0 -9
  158. package/assets/vanilla/markup/DropdownMenu.html +0 -30
  159. package/assets/vanilla/markup/EmptyState.html +0 -41
  160. package/assets/vanilla/markup/Heading.html +0 -9
  161. package/assets/vanilla/markup/HoverCard.html +0 -85
  162. package/assets/vanilla/markup/Layout.html +0 -35
  163. package/assets/vanilla/markup/Lightbox.html +0 -107
  164. package/assets/vanilla/markup/Link.html +0 -6
  165. package/assets/vanilla/markup/NumberInput.html +0 -55
  166. package/assets/vanilla/markup/ProgressBar.html +0 -101
  167. package/assets/vanilla/markup/RadioList.html +0 -90
  168. package/assets/vanilla/markup/Selector.html +0 -92
  169. package/assets/vanilla/markup/SideNav.html +0 -82
  170. package/assets/vanilla/markup/Skeleton.html +0 -26
  171. package/assets/vanilla/markup/Slider.html +0 -65
  172. package/assets/vanilla/markup/Stack.html +0 -13
  173. package/assets/vanilla/markup/StatusDot.html +0 -22
  174. package/assets/vanilla/markup/Switch.html +0 -47
  175. package/assets/vanilla/markup/TabList.html +0 -56
  176. package/assets/vanilla/markup/Table.html +0 -75
  177. package/assets/vanilla/markup/Text.html +0 -9
  178. package/assets/vanilla/markup/TextArea.html +0 -37
  179. package/assets/vanilla/markup/TextInput.html +0 -80
  180. package/assets/vanilla/markup/Theme.html +0 -48
  181. package/assets/vanilla/markup/TimeInput.html +0 -43
  182. package/assets/vanilla/markup/Toast.html +0 -42
  183. package/assets/vanilla/markup/Tooltip.html +0 -18
  184. package/assets/vanilla/markup/TopNav.html +0 -81
  185. package/assets/vanilla/markup/Typeahead.html +0 -60
  186. package/assets/vanilla/templates/dashboard.html +0 -462
  187. package/assets/vanilla/templates/detail-page.html +0 -536
  188. package/assets/vanilla/templates/form-two-column.html +0 -438
  189. package/assets/vanilla/templates/kanban-board.html +0 -443
  190. package/assets/vanilla/templates/login.html +0 -199
  191. package/assets/vanilla/templates/product-detail.html +0 -335
  192. package/assets/vanilla/templates/settings.html +0 -374
  193. package/assets/vanilla/templates/shell-side-nav.html +0 -440
  194. package/assets/vanilla/templates/table-filter.html +0 -514
  195. package/clients/cli/commands/vanilla-html.test.mjs +0 -245
  196. package/foundation/discovery/bundled-component-docs.d.mts +0 -39
  197. package/foundation/discovery/bundled-component-docs.mjs +0 -92
@@ -1,17 +1,6 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
- /**
5
- * Provenance attached only when component docs came from the version-matched
6
- * snapshot shipped with the CLI instead of a local Core installation.
7
- */
8
- export type ComponentResponseMeta = {
9
- componentDocs: {
10
- source: "bundled";
11
- package: string;
12
- version: string;
13
- };
14
- };
15
4
  /**
16
5
  * astryx --json component [--list] [--category X] [--detail names|compact|full]
17
6
  *
@@ -25,7 +14,6 @@ export type ComponentResponseMeta = {
25
14
  export type ComponentListResponse = {
26
15
  type: "component.list";
27
16
  data: ComponentListData;
28
- meta?: ComponentResponseMeta | undefined;
29
17
  };
30
18
  /**
31
19
  * Detail-tagged payload for `component.list` (discriminated on `detail`).
@@ -44,9 +32,7 @@ export type ComponentListData = ({
44
32
  * `component(string[])` always returns this type, including empty and one-item
45
33
  * arrays. The CLI returns it for two or more positional selectors.
46
34
  */
47
- export type ComponentBatchResponse = import("../../foundation/response/batch.type.mjs").BatchResponse<"component.batch", ComponentSingleResponse, ComponentBatchCandidate> & {
48
- meta?: ComponentResponseMeta;
49
- };
35
+ export type ComponentBatchResponse = import("../../foundation/response/batch.type.mjs").BatchResponse<"component.batch", ComponentSingleResponse, ComponentBatchCandidate>;
50
36
  /**
51
37
  * One installed component that makes an unqualified selector ambiguous.
52
38
  * Keys match a component row in `discover.search` so a caller does not learn a
@@ -100,7 +86,6 @@ export type ComponentBriefEntry = {
100
86
  export type ComponentDetailResponse = {
101
87
  type: "component.detail";
102
88
  data: import("@astryxdesign/cli/authoring").ComponentDoc & ComponentOwnership & ComponentDetailScope;
103
- meta?: ComponentResponseMeta | undefined;
104
89
  };
105
90
  /**
106
91
  * Present only when the requested name is a sub-component documented inside a
@@ -137,7 +122,6 @@ export type ComponentOwnership = {
137
122
  export type ComponentDetailPropsResponse = {
138
123
  type: "component.detail.props";
139
124
  data: import("@astryxdesign/cli/authoring").ComponentPropDoc[];
140
- meta?: ComponentResponseMeta | undefined;
141
125
  };
142
126
  /**
143
127
  * astryx --json component <name> --source
@@ -148,7 +132,6 @@ export type ComponentDetailSourceResponse = {
148
132
  component: string;
149
133
  source: string;
150
134
  };
151
- meta?: ComponentResponseMeta | undefined;
152
135
  };
153
136
  /**
154
137
  * astryx --json component <name> --showcase
@@ -160,7 +143,6 @@ export type ComponentDetailShowcaseResponse = {
160
143
  aspectRatio: number;
161
144
  source: string;
162
145
  };
163
- meta?: ComponentResponseMeta | undefined;
164
146
  };
165
147
  /**
166
148
  * astryx --json component <name> --blocks
@@ -173,7 +155,6 @@ export type ComponentDetailBlocksResponse = {
173
155
  examples: BlockEntry[];
174
156
  related: BlockEntry[];
175
157
  };
176
- meta?: ComponentResponseMeta | undefined;
177
158
  };
178
159
  export type BlockEntry = {
179
160
  name: string;
@@ -200,14 +181,6 @@ export type ComponentOptions = {
200
181
  * List example blocks for the component: showcase, examples, and related.
201
182
  */
202
183
  blocks?: boolean | undefined;
203
- /**
204
- * Deprecated alias for framework='html'.
205
- */
206
- html?: boolean | undefined;
207
- /**
208
- * Output framework; defaults to react.
209
- */
210
- framework?: "react" | "html" | "web-components" | undefined;
211
184
  detail?: "compact" | "full" | "brief" | undefined;
212
185
  lang?: string | undefined;
213
186
  zh?: boolean | undefined;
@@ -26,20 +26,9 @@
26
26
  * astryx --json component Button --source -> component.detail.source
27
27
  * astryx --json component Button --showcase -> component.detail.showcase
28
28
  * astryx --json component Button --blocks -> component.detail.blocks
29
- * astryx --json component --list --framework html -> component.html.list
30
- * astryx --json component Button --framework html -> component.html
31
- * astryx --json component --list --framework web-components -> component.web-components.list
32
- * astryx --json component Button --framework web-components -> component.web-components
33
29
  * (not found) -> CLIError
34
30
  */
35
31
 
36
- /**
37
- * Provenance attached only when component docs came from the version-matched
38
- * snapshot shipped with the CLI instead of a local Core installation.
39
- * @typedef {object} ComponentResponseMeta
40
- * @property {{source: 'bundled'; package: string; version: string}} componentDocs
41
- */
42
-
43
32
  /**
44
33
  * astryx --json component [--list] [--category X] [--detail names|compact|full]
45
34
  *
@@ -52,7 +41,6 @@
52
41
  * @typedef {object} ComponentListResponse
53
42
  * @property {'component.list'} type
54
43
  * @property {ComponentListData} data
55
- * @property {ComponentResponseMeta} [meta]
56
44
  */
57
45
 
58
46
  /**
@@ -71,7 +59,7 @@
71
59
  * 'component.batch',
72
60
  * ComponentSingleResponse,
73
61
  * ComponentBatchCandidate
74
- * > & {meta?: ComponentResponseMeta}} ComponentBatchResponse
62
+ * >} ComponentBatchResponse
75
63
  */
76
64
 
77
65
  /**
@@ -131,7 +119,6 @@
131
119
  * @typedef {object} ComponentDetailResponse
132
120
  * @property {'component.detail'} type
133
121
  * @property {import('@astryxdesign/cli/authoring').ComponentDoc & ComponentOwnership & ComponentDetailScope} data
134
- * @property {ComponentResponseMeta} [meta]
135
122
  */
136
123
 
137
124
  /**
@@ -156,7 +143,6 @@
156
143
  * @typedef {object} ComponentDetailPropsResponse
157
144
  * @property {'component.detail.props'} type
158
145
  * @property {import('@astryxdesign/cli/authoring').ComponentPropDoc[]} data
159
- * @property {ComponentResponseMeta} [meta]
160
146
  */
161
147
 
162
148
  /**
@@ -164,7 +150,6 @@
164
150
  * @typedef {object} ComponentDetailSourceResponse
165
151
  * @property {'component.detail.source'} type
166
152
  * @property {{component: string; source: string}} data
167
- * @property {ComponentResponseMeta} [meta]
168
153
  */
169
154
 
170
155
  /**
@@ -172,7 +157,6 @@
172
157
  * @typedef {object} ComponentDetailShowcaseResponse
173
158
  * @property {'component.detail.showcase'} type
174
159
  * @property {{component: string; aspectRatio: number; source: string}} data
175
- * @property {ComponentResponseMeta} [meta]
176
160
  */
177
161
 
178
162
  /**
@@ -180,7 +164,6 @@
180
164
  * @typedef {object} ComponentDetailBlocksResponse
181
165
  * @property {'component.detail.blocks'} type
182
166
  * @property {{component: string; showcase: BlockEntry | null; examples: BlockEntry[]; related: BlockEntry[]}} data
183
- * @property {ComponentResponseMeta} [meta]
184
167
  */
185
168
 
186
169
  /**
@@ -203,8 +186,6 @@
203
186
  * @property {boolean} [source]
204
187
  * @property {boolean} [showcase]
205
188
  * @property {boolean} [blocks] List example blocks for the component: showcase, examples, and related.
206
- * @property {boolean} [html] Deprecated alias for framework='html'.
207
- * @property {'react'|'html'|'web-components'} [framework] Output framework; defaults to react.
208
189
  * @property {'full' | 'compact' | 'brief'} [detail]
209
190
  * @property {string} [lang]
210
191
  * @property {boolean} [zh]
@@ -10,6 +10,10 @@
10
10
  * @param {boolean} [options.dense]
11
11
  * @param {boolean} [options.index] return the topic's section index instead of
12
12
  * the whole doc
13
+ * @param {number | 'all'} [options.depth] how many levels below a docs-tree
14
+ * namespace to read; a doc with nothing below it reads the same at any depth
15
+ * @param {'brief' | 'compact' | 'full'} [options.detail] how much of each doc
16
+ * below the named one a depth read returns (brief by default)
13
17
  * @param {string} [options.cwd]
14
18
  * @returns {Promise<
15
19
  * import('./docs.type.mjs').DocsListResponse |
@@ -24,6 +28,8 @@ export function docs(topic?: string, section?: string, options?: {
24
28
  zh?: boolean | undefined;
25
29
  dense?: boolean | undefined;
26
30
  index?: boolean | undefined;
31
+ depth?: number | "all" | undefined;
32
+ detail?: "compact" | "full" | "brief" | undefined;
27
33
  cwd?: string | undefined;
28
34
  }): Promise<import("./docs.type.mjs").DocsListResponse | import("./docs.type.mjs").DocsIndexResponse | import("./docs.type.mjs").DocsDetailResponse | import("./docs.type.mjs").DocsDetailSectionResponse | import("./docs.type.mjs").DocsNodeResponse>;
29
35
  import { list } from './list/list.mjs';
@@ -0,0 +1,132 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import {describe, expect, it} from 'vitest';
4
+ import {docs} from './docs.mjs';
5
+
6
+ const SLOW = 60_000;
7
+
8
+ /**
9
+ * @param {any} node
10
+ * @param {string} route
11
+ * @returns {any}
12
+ */
13
+ function findRoute(node, route) {
14
+ if (node.route === route) return node;
15
+ for (const slot of node.slots ?? []) {
16
+ for (const child of slot.children) {
17
+ const found = findRoute(child, route);
18
+ if (found) return found;
19
+ }
20
+ }
21
+ return undefined;
22
+ }
23
+
24
+ /**
25
+ * @param {any} node
26
+ * @returns {any[]}
27
+ */
28
+ function children(node) {
29
+ return (node.slots ?? []).flatMap((/** @type {any} */ slot) => slot.children);
30
+ }
31
+
32
+ describe('docs() depth', () => {
33
+ it(
34
+ 'reads one level down, as it always has, without a depth',
35
+ async () => {
36
+ const plain = await docs('cli/api');
37
+ expect(plain.type).toBe('docs.node');
38
+ if (plain.type !== 'docs.node') return;
39
+ expect(plain.data).not.toHaveProperty('childCount');
40
+ for (const child of children(plain.data)) {
41
+ expect(Object.keys(child).sort()).toEqual([
42
+ 'kind',
43
+ 'name',
44
+ 'route',
45
+ 'summary',
46
+ 'title',
47
+ ]);
48
+ }
49
+ },
50
+ SLOW,
51
+ );
52
+
53
+ it(
54
+ 'goes as many levels down as asked, each doc below as its identity',
55
+ async () => {
56
+ const result = await docs('cli/api', undefined, {depth: 2});
57
+ if (result.type !== 'docs.node') throw new Error(result.type);
58
+ const functions = findRoute(result.data, 'cli/api/functions');
59
+ expect(functions).not.toHaveProperty('childCount');
60
+ expect(findRoute(result.data, 'cli/api/functions/search')).toEqual({
61
+ route: 'cli/api/functions/search',
62
+ name: 'search',
63
+ kind: 'function',
64
+ title: 'search()',
65
+ summary: expect.any(String),
66
+ });
67
+ },
68
+ SLOW,
69
+ );
70
+
71
+ it(
72
+ 'says how many docs sit below where the read stops',
73
+ async () => {
74
+ const one = await docs('cli/api', undefined, {depth: 1});
75
+ if (one.type !== 'docs.node') throw new Error(one.type);
76
+ const functions = findRoute(one.data, 'cli/api/functions');
77
+ expect(functions).not.toHaveProperty('slots');
78
+ expect(functions.childCount).toBeGreaterThan(1);
79
+
80
+ const zero = await docs('cli/api', undefined, {depth: 0});
81
+ if (zero.type !== 'docs.node') throw new Error(zero.type);
82
+ expect(zero.data.slots).toEqual([]);
83
+ expect(zero.data.childCount).toBe(children(one.data).length);
84
+ },
85
+ SLOW,
86
+ );
87
+
88
+ it(
89
+ "reads every level with 'all', and each doc's text at full detail",
90
+ async () => {
91
+ const result = await docs('cli/api', undefined, {
92
+ depth: 'all',
93
+ detail: 'full',
94
+ });
95
+ if (result.type !== 'docs.node') throw new Error(result.type);
96
+ expect(JSON.stringify(result.data)).not.toContain('"childCount"');
97
+ const search = findRoute(result.data, 'cli/api/functions/search');
98
+ expect(JSON.stringify(search.content)).toContain(
99
+ '`astryx search` runs it. Read it with `astryx docs cli/commands/search`.',
100
+ );
101
+ },
102
+ SLOW,
103
+ );
104
+
105
+ it(
106
+ 'reads a doc with nothing below it the same at any depth',
107
+ async () => {
108
+ expect(
109
+ await docs('cli/api/functions/search', undefined, {depth: 3}),
110
+ ).toEqual(await docs('cli/api/functions/search'));
111
+ },
112
+ SLOW,
113
+ );
114
+
115
+ it(
116
+ 'refuses a depth that is not a number of levels, and an unknown detail',
117
+ async () => {
118
+ for (const depth of [-1, 1.5, 'deep', '2']) {
119
+ await expect(
120
+ docs('cli/api', undefined, {depth: /** @type {any} */ (depth)}),
121
+ ).rejects.toMatchObject({code: 'ERR_INVALID_ARGUMENT'});
122
+ }
123
+ await expect(
124
+ docs('cli/api', undefined, {
125
+ depth: 1,
126
+ detail: /** @type {any} */ ('huge'),
127
+ }),
128
+ ).rejects.toMatchObject({code: 'ERR_INVALID_DETAIL'});
129
+ },
130
+ SLOW,
131
+ );
132
+ });
@@ -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
- "`cli/api` returns its children one level down, a typed doc such as " +
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);
@@ -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()
@@ -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
  */
@@ -4,15 +4,28 @@
4
4
  /**
5
5
  * @typedef {import('../../../foundation/doc-compiler/tree.mjs').DocsTree} DocsTree
6
6
  * @typedef {import('../../../foundation/doc-compiler/tree.mjs').TreeNode} TreeNode
7
+ * @typedef {import('../../../foundation/discovery/docs-discovery.mjs').DocsCatalog} DocsCatalog
7
8
  */
8
9
  /**
9
- * The docs.node view of one tree node.
10
- * @param {import('../../../foundation/discovery/docs-discovery.mjs').DocsCatalog} catalog
10
+ * How far a read goes below the node it names, and how much of each doc below
11
+ * it shows: `depth` levels (Infinity for every level), and `detail` brief (its
12
+ * identity), or compact or full (with its text: a namespace's intro, a guide's
13
+ * sections, a typed doc's content). `lang` selects the guides' language.
14
+ * @typedef {object} DepthRead
15
+ * @property {number} depth
16
+ * @property {'brief' | 'compact' | 'full'} detail
17
+ * @property {string | null} lang
18
+ */
19
+ /**
20
+ * The docs.node view of one tree node. Without a depth read, a namespace lists
21
+ * its children one level down.
22
+ * @param {DocsCatalog} catalog
11
23
  * @param {DocsTree} tree
12
24
  * @param {TreeNode} node
25
+ * @param {DepthRead} [read] how far down to go, and how much of each doc below
13
26
  * @returns {Promise<import('../docs.type.mjs').DocsNode>}
14
27
  */
15
- export function nodeView(catalog: import("../../../foundation/discovery/docs-discovery.mjs").DocsCatalog, tree: DocsTree, node: TreeNode): Promise<import("../docs.type.mjs").DocsNode>;
28
+ export function nodeView(catalog: DocsCatalog, tree: DocsTree, node: TreeNode, read?: DepthRead): Promise<import("../docs.type.mjs").DocsNode>;
16
29
  /**
17
30
  * The typed edges a doc declares (spec:AST-047 FR5), resolved to routes: a
18
31
  * function doc's `command` and `related`, and a command doc's `fn` and
@@ -41,3 +54,15 @@ export function node(route: string, options?: {
41
54
  }): Promise<import("../docs.type.mjs").DocsNodeResponse>;
42
55
  export type DocsTree = import("../../../foundation/doc-compiler/tree.mjs").DocsTree;
43
56
  export type TreeNode = import("../../../foundation/doc-compiler/tree.mjs").TreeNode;
57
+ export type DocsCatalog = import("../../../foundation/discovery/docs-discovery.mjs").DocsCatalog;
58
+ /**
59
+ * How far a read goes below the node it names, and how much of each doc below
60
+ * it shows: `depth` levels (Infinity for every level), and `detail` brief (its
61
+ * identity), or compact or full (with its text: a namespace's intro, a guide's
62
+ * sections, a typed doc's content). `lang` selects the guides' language.
63
+ */
64
+ export type DepthRead = {
65
+ depth: number;
66
+ detail: "brief" | "compact" | "full";
67
+ lang: string | null;
68
+ };