@astryxdesign/cli 0.6.5-canary.84fdbd1 → 0.6.5-canary.8a5b3fb

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 (81) hide show
  1. package/README.md +21 -21
  2. package/api/build/_adapter.d.mts +5 -0
  3. package/api/build/_adapter.mjs +2 -0
  4. package/api/build/build.type.d.mts +8 -0
  5. package/api/build/build.type.mjs +2 -0
  6. package/api/build/kit/kit.mjs +1 -0
  7. package/api/component/component.mjs +17 -15
  8. package/api/component/component.type.d.mts +33 -3
  9. package/api/component/component.type.mjs +10 -3
  10. package/api/component/detail/blocks/blocks.d.mts +2 -1
  11. package/api/component/detail/blocks/blocks.mjs +5 -2
  12. package/api/component/detail/detail.mjs +5 -1
  13. package/api/component/detail/props/props.d.mts +2 -1
  14. package/api/component/detail/props/props.mjs +3 -2
  15. package/api/component/detail/showcase/showcase.d.mts +3 -1
  16. package/api/component/detail/showcase/showcase.mjs +3 -1
  17. package/api/component/detail/source/source.d.mts +3 -2
  18. package/api/component/detail/source/source.mjs +7 -3
  19. package/api/component/list/list.mjs +18 -6
  20. package/api/docs/_adapter.d.mts +11 -0
  21. package/api/docs/_adapter.mjs +25 -0
  22. package/api/docs/detail/detail.mjs +19 -3
  23. package/api/docs/detail/section/section.mjs +7 -1
  24. package/api/docs/docs.depth.test.mjs +2 -0
  25. package/api/docs/docs.mjs +2 -0
  26. package/api/docs/docs.type.d.mts +43 -3
  27. package/api/docs/docs.type.mjs +23 -3
  28. package/api/docs/index/index.mjs +11 -2
  29. package/api/docs/index/index.test.mjs +2 -1
  30. package/api/docs/node/node.mjs +3 -0
  31. package/api/hook/_adapter.d.mts +1 -0
  32. package/api/hook/_adapter.mjs +3 -0
  33. package/api/hook/detail/detail.mjs +2 -2
  34. package/api/hook/detail/params/params.mjs +2 -2
  35. package/api/hook/hook.type.d.mts +12 -0
  36. package/api/hook/hook.type.mjs +3 -0
  37. package/api/hook/list/list.mjs +8 -8
  38. package/api/search/search.d.mts +3 -3
  39. package/api/search/search.mjs +9 -5
  40. package/api/search/search.type.d.mts +2 -2
  41. package/api/search/search.type.mjs +1 -1
  42. package/api/swizzle/_adapter.d.mts +1 -0
  43. package/api/swizzle/_adapter.mjs +3 -0
  44. package/api/swizzle/copy/copy.mjs +1 -1
  45. package/api/swizzle/list/list.mjs +2 -2
  46. package/api/swizzle/swizzle.type.d.mts +8 -0
  47. package/api/swizzle/swizzle.type.mjs +2 -0
  48. package/api/template/copy/copy.mjs +2 -1
  49. package/api/template/show/show.mjs +2 -0
  50. package/api/template/skeleton/skeleton.mjs +2 -1
  51. package/api/template/template.d.mts +1 -1
  52. package/api/template/template.mjs +1 -0
  53. package/api/template/template.type.d.mts +12 -0
  54. package/api/template/template.type.mjs +3 -0
  55. package/api/upgrade/_adapter.d.mts +1 -0
  56. package/api/upgrade/_adapter.mjs +3 -0
  57. package/api/upgrade/list/list.mjs +9 -3
  58. package/api/upgrade/upgrade.type.d.mts +4 -0
  59. package/api/upgrade/upgrade.type.mjs +1 -0
  60. package/clients/cli/commands/build.mjs +7 -6
  61. package/clients/cli/commands/build.text-fields.test.mjs +1 -1
  62. package/clients/cli/commands/component/index.mjs +34 -6
  63. package/clients/cli/commands/docs.mjs +63 -23
  64. package/clients/cli/commands/hook/index.mjs +7 -2
  65. package/clients/cli/commands/swizzle.mjs +2 -1
  66. package/clients/cli/commands/template.mjs +8 -4
  67. package/clients/cli/commands/text-json-parity.test.mjs +22 -0
  68. package/clients/cli/commands/upgrade.mjs +1 -1
  69. package/clients/cli/index.mjs +1 -1
  70. package/foundation/discovery/docs-output-budget.d.mts +6 -2
  71. package/foundation/discovery/docs-output-budget.mjs +2 -1
  72. package/foundation/discovery/docs-section-key.d.mts +4 -2
  73. package/foundation/discovery/docs-section-key.mjs +1 -1
  74. package/foundation/doc-compiler/lenses.d.mts +4 -2
  75. package/foundation/doc-compiler/lenses.mjs +1 -1
  76. package/foundation/response/base.d.ts +9 -3
  77. package/foundation/response/json.d.mts +7 -4
  78. package/foundation/response/json.mjs +10 -6
  79. package/foundation/response/response-types.doc.mjs +25 -20
  80. package/foundation/response/response.doc.mjs +17 -3
  81. package/package.json +9 -9
@@ -6,10 +6,11 @@
6
6
  * envelope. Throws ERR_NO_SOURCE when the owner ships no source file.
7
7
  * @param {string} componentName - bare name, echoed back as `data.component`
8
8
  * @param {string|null} sourcePath - the resolved source path (null → not found)
9
- * @param {{name: string, notFoundInPackage?: string|null}} ctx - `name` is the caller's original input; `notFoundInPackage` scopes the not-found message to a package
9
+ * @param {{name: string, notFoundInPackage?: string|null, ownerPackage: string}} ctx - `name` is the caller's original input; `notFoundInPackage` scopes the not-found message to a package; `ownerPackage` is the npm package that owns the component
10
10
  * @returns {import('../../component.type.mjs').ComponentDetailSourceResponse}
11
11
  */
12
- export function componentDetailSource(componentName: string, sourcePath: string | null, { name, notFoundInPackage }: {
12
+ export function componentDetailSource(componentName: string, sourcePath: string | null, { name, notFoundInPackage, ownerPackage }: {
13
13
  name: string;
14
14
  notFoundInPackage?: string | null;
15
+ ownerPackage: string;
15
16
  }): import("../../component.type.mjs").ComponentDetailSourceResponse;
@@ -17,13 +17,17 @@ import {ERROR_CODES} from '../../../../foundation/response/error-codes.mjs';
17
17
  * envelope. Throws ERR_NO_SOURCE when the owner ships no source file.
18
18
  * @param {string} componentName - bare name, echoed back as `data.component`
19
19
  * @param {string|null} sourcePath - the resolved source path (null → not found)
20
- * @param {{name: string, notFoundInPackage?: string|null}} ctx - `name` is the caller's original input; `notFoundInPackage` scopes the not-found message to a package
20
+ * @param {{name: string, notFoundInPackage?: string|null, ownerPackage: string}} ctx - `name` is the caller's original input; `notFoundInPackage` scopes the not-found message to a package; `ownerPackage` is the npm package that owns the component
21
21
  * @returns {import('../../component.type.mjs').ComponentDetailSourceResponse}
22
22
  */
23
- export function componentDetailSource(componentName, sourcePath, {name, notFoundInPackage = null}) {
23
+ export function componentDetailSource(componentName, sourcePath, {name, notFoundInPackage = null, ownerPackage}) {
24
24
  if (!sourcePath) {
25
25
  const suffix = notFoundInPackage ? ` in package "${notFoundInPackage}"` : '';
26
26
  throw new AstryxError(`Source for "${name}" not found${suffix}`, undefined, ERROR_CODES.ERR_NO_SOURCE);
27
27
  }
28
- return {type: 'component.detail.source', data: {component: componentName, source: fs.readFileSync(sourcePath, 'utf-8')}};
28
+ return {
29
+ type: 'component.detail.source',
30
+ package: ownerPackage,
31
+ data: {component: componentName, source: fs.readFileSync(sourcePath, 'utf-8')},
32
+ };
29
33
  }
@@ -55,6 +55,12 @@ async function legacyImport(ext, name, coreDir, docOpts) {
55
55
  return withOwnership(docs, {package: ext.name, sourcePath: null}, name, coreDir).import;
56
56
  }
57
57
 
58
+ /**
59
+ * A full Core ComponentDoc list entry, naming the package that owns it.
60
+ * @param {any} doc
61
+ */
62
+ const coreEntry = doc => ({name: doc.name, package: CORE_PACKAGE, ...doc});
63
+
58
64
  /**
59
65
  * Build the `component.list` envelope. The list taxonomy is collapsed: all
60
66
  * three detail levels emit ONE `component.list` type; the depth rides in
@@ -97,12 +103,14 @@ export async function componentList(
97
103
  const docs = await loadComponentDoc(readme, {zh, lang});
98
104
  entries.push({
99
105
  name: comp,
106
+ package: CORE_PACKAGE,
100
107
  description: docs.usage?.description || docs.description || '',
101
108
  import: resolveImportPath(coreDir, comp),
102
109
  });
103
110
  } catch {
104
111
  entries.push({
105
112
  name: comp,
113
+ package: CORE_PACKAGE,
106
114
  description: '',
107
115
  import: resolveImportPath(coreDir, comp),
108
116
  });
@@ -110,6 +118,7 @@ export async function componentList(
110
118
  } else {
111
119
  entries.push({
112
120
  name: comp,
121
+ package: CORE_PACKAGE,
113
122
  description: '',
114
123
  import: resolveImportPath(coreDir, comp),
115
124
  });
@@ -128,12 +137,12 @@ export async function componentList(
128
137
  const readme = findComponentReadme(coreDir, comp);
129
138
  if (readme && readme.endsWith('.doc.mjs')) {
130
139
  try {
131
- entries.push(await loadComponentDoc(readme, {zh, lang, dense}));
140
+ entries.push(coreEntry(await loadComponentDoc(readme, {zh, lang, dense})));
132
141
  } catch {
133
- entries.push({name: `XDS${comp}`, description: ''});
142
+ entries.push({name: `XDS${comp}`, package: CORE_PACKAGE, description: ''});
134
143
  }
135
144
  } else {
136
- entries.push({name: `XDS${comp}`, description: ''});
145
+ entries.push({name: `XDS${comp}`, package: CORE_PACKAGE, description: ''});
137
146
  }
138
147
  }
139
148
  return {
@@ -169,12 +178,14 @@ export async function componentList(
169
178
  const docs = await loadComponentDoc(readme, {zh, lang});
170
179
  result[cat].push({
171
180
  name: comp,
181
+ package: CORE_PACKAGE,
172
182
  description: docs.usage?.description || docs.description || '',
173
183
  import: resolveImportPath(coreDir, comp),
174
184
  });
175
185
  } catch {
176
186
  result[cat].push({
177
187
  name: comp,
188
+ package: CORE_PACKAGE,
178
189
  description: '',
179
190
  import: resolveImportPath(coreDir, comp),
180
191
  });
@@ -182,6 +193,7 @@ export async function componentList(
182
193
  } else {
183
194
  result[cat].push({
184
195
  name: comp,
196
+ package: CORE_PACKAGE,
185
197
  description: '',
186
198
  import: resolveImportPath(coreDir, comp),
187
199
  });
@@ -203,12 +215,12 @@ export async function componentList(
203
215
  const readme = findComponentReadme(coreDir, comp);
204
216
  if (readme && readme.endsWith('.doc.mjs')) {
205
217
  try {
206
- result[cat].push(await loadComponentDoc(readme, {zh, lang, dense}));
218
+ result[cat].push(coreEntry(await loadComponentDoc(readme, {zh, lang, dense})));
207
219
  } catch {
208
- result[cat].push({name: `XDS${comp}`, description: ''});
220
+ result[cat].push({name: `XDS${comp}`, package: CORE_PACKAGE, description: ''});
209
221
  }
210
222
  } else {
211
- result[cat].push({name: `XDS${comp}`, description: ''});
223
+ result[cat].push({name: `XDS${comp}`, package: CORE_PACKAGE, description: ''});
212
224
  }
213
225
  }
214
226
  }
@@ -20,6 +20,17 @@ export function loadDocsCatalog(cwd?: string): Promise<DocsCatalog>;
20
20
  * @returns {DocsCatalog}
21
21
  */
22
22
  export function builtinCatalog(): DocsCatalog;
23
+ /**
24
+ * The npm package that wrote each section of a lowered topic: the topic's own
25
+ * package, or the package of the extension that contributed the section
26
+ * (spec cli-surface INV28).
27
+ * @param {DocsTopicEntry} entry
28
+ * @param {{sectionProviders?: Record<string, string>}} node the lowered topic
29
+ * @returns {(sectionId: string | undefined) => string}
30
+ */
31
+ export function sectionPackageOf(entry: DocsTopicEntry, node: {
32
+ sectionProviders?: Record<string, string>;
33
+ }): (sectionId: string | undefined) => string;
23
34
  /**
24
35
  * One topic, lowered for `lang` with every link between docs resolved
25
36
  * (spec:AST-047 FR9): an inline `{@link <target>}` reads as the command that
@@ -150,6 +150,31 @@ function providerOf(entry) {
150
150
  return normalizeProviderId(entry.providerId ?? entry.package);
151
151
  }
152
152
 
153
+ /**
154
+ * The npm package that wrote each section of a lowered topic: the topic's own
155
+ * package, or the package of the extension that contributed the section
156
+ * (spec cli-surface INV28).
157
+ * @param {DocsTopicEntry} entry
158
+ * @param {{sectionProviders?: Record<string, string>}} node the lowered topic
159
+ * @returns {(sectionId: string | undefined) => string}
160
+ */
161
+ export function sectionPackageOf(entry, node) {
162
+ /** @type {Map<string, string>} */
163
+ const byProvider = new Map([[providerOf(entry), entry.package]]);
164
+ for (const extension of entry.extensions ?? []) {
165
+ byProvider.set(providerOf(extension), extension.package);
166
+ }
167
+ return sectionId => {
168
+ const provider =
169
+ sectionId == null ? undefined : node.sectionProviders?.[sectionId];
170
+ return (
171
+ (provider == null
172
+ ? undefined
173
+ : byProvider.get(normalizeProviderId(provider))) ?? entry.package
174
+ );
175
+ };
176
+ }
177
+
153
178
  /**
154
179
  * One topic, lowered for `lang` with every link between docs resolved
155
180
  * (spec:AST-047 FR9): an inline `{@link <target>}` reads as the command that
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * @input A topic name plus optional {lang, zh, dense, cwd}. Resolves the topic
7
7
  * via the shared adapter and compiles it with its token references linked.
8
- * @output { type: 'docs.detail', data: ReferenceDoc } — the full doc with
8
+ * @output { type: 'docs.detail', package, data: ReferenceDoc } — the full doc with
9
9
  * token-refs inlined, matching `astryx --json docs <topic>`.
10
10
  * @position Leaf under api/docs. Reads the compiled node through the detail
11
11
  * lens; resolution, overlays and extensions happen in the compiler.
@@ -13,7 +13,12 @@
13
13
 
14
14
  import {linkReferenceTopic} from '../../../foundation/doc-compiler/compile.mjs';
15
15
  import {detailView} from '../../../foundation/doc-compiler/lenses.mjs';
16
- import {referenceTargets, resolveTopicDocs, topicLinks} from '../_adapter.mjs';
16
+ import {
17
+ referenceTargets,
18
+ resolveTopicDocs,
19
+ sectionPackageOf,
20
+ topicLinks,
21
+ } from '../_adapter.mjs';
17
22
 
18
23
  /**
19
24
  * @param {string} topic
@@ -30,10 +35,21 @@ export async function detail(topic, options = {}) {
30
35
  node,
31
36
  referenceTargets(catalog, lang),
32
37
  );
38
+ const view = detailView(linked);
39
+ const sectionPackage = sectionPackageOf(entry, node);
33
40
  return {
34
41
  type: 'docs.detail',
42
+ package: entry.package,
35
43
  data: {
36
- ...detailView(linked),
44
+ ...view,
45
+ // Each section names the package that wrote it: the topic's own, or an
46
+ // extension's.
47
+ sections: view.sections.map(
48
+ (/** @type {import('../docs.type.mjs').DocsReadSection} */ section) => {
49
+ const {id, title, ...rest} = section;
50
+ return {id, title, package: sectionPackage(id), ...rest};
51
+ },
52
+ ),
37
53
  // A guide the docs tree places is read by its route, not its doc name.
38
54
  ...(entry.tree ? {name: entry.name} : {}),
39
55
  links: await topicLinks(catalog, entry),
@@ -26,7 +26,11 @@ import {
26
26
  readerSections,
27
27
  sectionView,
28
28
  } from '../../../../foundation/doc-compiler/lenses.mjs';
29
- import {referenceTargets, resolveTopicDocs} from '../../_adapter.mjs';
29
+ import {
30
+ referenceTargets,
31
+ resolveTopicDocs,
32
+ sectionPackageOf,
33
+ } from '../../_adapter.mjs';
30
34
 
31
35
  /**
32
36
  * @param {string} topic
@@ -84,6 +88,8 @@ export async function section(topic, sectionName, options = {}) {
84
88
  }
85
89
  return {
86
90
  type: 'docs.detail.section',
91
+ // The package that wrote this section: the topic's own, or an extension's.
92
+ package: sectionPackageOf(entry, node)(match.id),
87
93
  data: {...sectionView(node, linked), links},
88
94
  };
89
95
  }
@@ -41,6 +41,7 @@ describe('docs() depth', () => {
41
41
  expect(Object.keys(child).sort()).toEqual([
42
42
  'kind',
43
43
  'name',
44
+ 'package',
44
45
  'route',
45
46
  'summary',
46
47
  'title',
@@ -60,6 +61,7 @@ describe('docs() depth', () => {
60
61
  expect(findRoute(result.data, 'cli/api/functions/search')).toEqual({
61
62
  route: 'cli/api/functions/search',
62
63
  name: 'search',
64
+ package: '@astryxdesign/cli',
63
65
  kind: 'function',
64
66
  title: 'search()',
65
67
  summary: expect.any(String),
package/api/docs/docs.mjs CHANGED
@@ -120,6 +120,8 @@ export async function docs(topic, section, options = {}) {
120
120
  }
121
121
  return {
122
122
  type: 'docs.node',
123
+ // The docs tree names each node's npm package as its provider.
124
+ package: found.node.provider,
123
125
  data: await nodeView(found.catalog, found.tree, found.node, read),
124
126
  };
125
127
  }
@@ -57,6 +57,10 @@ export type DocsListNamespace = {
57
57
  */
58
58
  export type DocsIndexResponse = {
59
59
  type: "docs.index";
60
+ /**
61
+ * the npm package that owns the topic
62
+ */
63
+ package: string;
60
64
  data: DocsIndex;
61
65
  };
62
66
  /**
@@ -65,9 +69,15 @@ export type DocsIndexResponse = {
65
69
  export type DocsDetailResponse = {
66
70
  type: "docs.detail";
67
71
  /**
68
- * the whole doc, and the moves from it
72
+ * the npm package that owns the topic
69
73
  */
70
- data: DocsReadDoc & {
74
+ package: string;
75
+ /**
76
+ * the whole doc, each section naming the package that wrote it, and the
77
+ * moves from it
78
+ */
79
+ data: Omit<DocsReadDoc, "sections"> & {
80
+ sections: DocsDetailSection[];
71
81
  links: DocsLinks;
72
82
  };
73
83
  };
@@ -79,6 +89,13 @@ export type DocsDetailResponse = {
79
89
  export type DocsReadSection = Omit<import("@astryxdesign/cli/authoring").ReferenceSection, "content"> & {
80
90
  content: import("@astryxdesign/cli/authoring").ReferenceContentBlock[];
81
91
  };
92
+ /**
93
+ * A section of a whole-topic read: the read section, naming the package that
94
+ * wrote it.
95
+ */
96
+ export type DocsDetailSection = DocsReadSection & {
97
+ package: string;
98
+ };
82
99
  /**
83
100
  * A topic as a read returns it: every section a {@link DocsReadSection}.
84
101
  */
@@ -141,7 +158,10 @@ export type DocsIndex = {
141
158
  */
142
159
  links: DocsLinks;
143
160
  };
144
- export type DocsIndexSection = {
161
+ /**
162
+ * One section of a topic's index, before it names its package.
163
+ */
164
+ export type DocsIndexEntry = {
145
165
  /**
146
166
  * stable key; pass it as the section argument
147
167
  */
@@ -153,11 +173,23 @@ export type DocsIndexSection = {
153
173
  */
154
174
  summary: string;
155
175
  };
176
+ /**
177
+ * One section of a topic's index, naming the package that wrote it: the
178
+ * topic's own, or the extension's that contributed it.
179
+ */
180
+ export type DocsIndexSection = DocsIndexEntry & {
181
+ package: string;
182
+ };
156
183
  /**
157
184
  * astryx --json docs <topic> <section>
158
185
  */
159
186
  export type DocsDetailSectionResponse = {
160
187
  type: "docs.detail.section";
188
+ /**
189
+ * the npm package that wrote the section: the
190
+ * topic's own, or the extension's that contributed it
191
+ */
192
+ package: string;
161
193
  /**
162
194
  * the section, and the moves from it: up to its topic's index, and across to
163
195
  * the sections before and after it
@@ -171,6 +203,10 @@ export type DocsDetailSectionResponse = {
171
203
  */
172
204
  export type DocsNodeResponse = {
173
205
  type: "docs.node";
206
+ /**
207
+ * the package that owns the node
208
+ */
209
+ package: string;
174
210
  data: DocsNode;
175
211
  };
176
212
  /**
@@ -248,6 +284,10 @@ export type DocsNodeChild = {
248
284
  * the last segment of its route
249
285
  */
250
286
  name: string;
287
+ /**
288
+ * the package that owns the child
289
+ */
290
+ package: string;
251
291
  kind: string;
252
292
  title: string;
253
293
  summary: string;
@@ -49,6 +49,7 @@
49
49
  * astryx --json docs <topic> --index
50
50
  * @typedef {object} DocsIndexResponse
51
51
  * @property {'docs.index'} type
52
+ * @property {string} package the npm package that owns the topic
52
53
  * @property {DocsIndex} data
53
54
  */
54
55
 
@@ -56,8 +57,10 @@
56
57
  * astryx --json docs <topic>
57
58
  * @typedef {object} DocsDetailResponse
58
59
  * @property {'docs.detail'} type
59
- * @property {DocsReadDoc & {links: DocsLinks}} data
60
- * the whole doc, and the moves from it
60
+ * @property {string} package the npm package that owns the topic
61
+ * @property {Omit<DocsReadDoc, 'sections'> & {sections: DocsDetailSection[], links: DocsLinks}} data
62
+ * the whole doc, each section naming the package that wrote it, and the
63
+ * moves from it
61
64
  */
62
65
 
63
66
  /**
@@ -68,6 +71,12 @@
68
71
  * & {content: import('@astryxdesign/cli/authoring').ReferenceContentBlock[]}} DocsReadSection
69
72
  */
70
73
 
74
+ /**
75
+ * A section of a whole-topic read: the read section, naming the package that
76
+ * wrote it.
77
+ * @typedef {DocsReadSection & {package: string}} DocsDetailSection
78
+ */
79
+
71
80
  /**
72
81
  * A topic as a read returns it: every section a {@link DocsReadSection}.
73
82
  * @typedef {Omit<import('@astryxdesign/cli/authoring').ReferenceDoc, 'sections'>
@@ -115,17 +124,26 @@
115
124
  */
116
125
 
117
126
  /**
118
- * @typedef {object} DocsIndexSection
127
+ * One section of a topic's index, before it names its package.
128
+ * @typedef {object} DocsIndexEntry
119
129
  * @property {string} id stable key; pass it as the section argument
120
130
  * @property {string} title
121
131
  * @property {string} summary the section's first line of text, at most 240
122
132
  * characters
123
133
  */
124
134
 
135
+ /**
136
+ * One section of a topic's index, naming the package that wrote it: the
137
+ * topic's own, or the extension's that contributed it.
138
+ * @typedef {DocsIndexEntry & {package: string}} DocsIndexSection
139
+ */
140
+
125
141
  /**
126
142
  * astryx --json docs <topic> <section>
127
143
  * @typedef {object} DocsDetailSectionResponse
128
144
  * @property {'docs.detail.section'} type
145
+ * @property {string} package the npm package that wrote the section: the
146
+ * topic's own, or the extension's that contributed it
129
147
  * @property {DocsReadSection & {links: DocsLinks}} data
130
148
  * the section, and the moves from it: up to its topic's index, and across to
131
149
  * the sections before and after it
@@ -135,6 +153,7 @@
135
153
  * astryx --json docs <route>, for a namespace or a typed doc in the docs tree
136
154
  * @typedef {object} DocsNodeResponse
137
155
  * @property {'docs.node'} type
156
+ * @property {string} package the package that owns the node
138
157
  * @property {DocsNode} data
139
158
  */
140
159
 
@@ -180,6 +199,7 @@
180
199
  * @typedef {object} DocsNodeChild
181
200
  * @property {string} route pass it to `astryx docs` to go one level down
182
201
  * @property {string} name the last segment of its route
202
+ * @property {string} package the package that owns the child
183
203
  * @property {string} kind
184
204
  * @property {string} title
185
205
  * @property {string} summary
@@ -15,7 +15,7 @@
15
15
  */
16
16
 
17
17
  import {indexView} from '../../../foundation/doc-compiler/lenses.mjs';
18
- import {resolveTopicDocs, topicLinks} from '../_adapter.mjs';
18
+ import {resolveTopicDocs, sectionPackageOf, topicLinks} from '../_adapter.mjs';
19
19
 
20
20
  /**
21
21
  * @param {string} topic
@@ -29,12 +29,21 @@ import {resolveTopicDocs, topicLinks} from '../_adapter.mjs';
29
29
  export async function index(topic, options = {}) {
30
30
  const {node, entry, catalog} = await resolveTopicDocs(topic, options);
31
31
  const view = indexView(node);
32
+ const sectionPackage = sectionPackageOf(entry, node);
32
33
  /** @type {import('../docs.type.mjs').DocsIndex} */
33
34
  const data = {
34
35
  ...view,
35
36
  // A guide the docs tree places is read by its route, not its doc name.
36
37
  name: entry.tree ? entry.name : view.name,
38
+ // Each section names the package that wrote it: the topic's own, or an
39
+ // extension's.
40
+ sections: view.sections.map(s => ({
41
+ id: s.id,
42
+ title: s.title,
43
+ package: sectionPackage(s.id),
44
+ summary: s.summary,
45
+ })),
37
46
  links: await topicLinks(catalog, entry),
38
47
  };
39
- return {type: 'docs.index', data};
48
+ return {type: 'docs.index', package: entry.package, data};
40
49
  }
@@ -15,7 +15,8 @@ describe('docs.index leaf', () => {
15
15
  const keys = res.data.sections.map(s => s.id);
16
16
  expect(new Set(keys).size).toBe(keys.length);
17
17
  for (const entry of res.data.sections) {
18
- expect(Object.keys(entry)).toEqual(['id', 'title', 'summary']);
18
+ expect(Object.keys(entry)).toEqual(['id', 'title', 'package', 'summary']);
19
+ expect(entry.package).toBe(res.package);
19
20
  expect(entry.summary.length).toBeLessThanOrEqual(240);
20
21
  }
21
22
  }, SLOW);
@@ -94,6 +94,7 @@ function childIdentity(child) {
94
94
  return {
95
95
  route: child.route,
96
96
  name: child.route.slice(child.route.lastIndexOf('/') + 1),
97
+ package: child.provider,
97
98
  kind: child.kind,
98
99
  title: child.title,
99
100
  summary: child.summary,
@@ -310,6 +311,8 @@ export async function node(route, options = {}) {
310
311
  throw await unknownTopicError(route, found.catalog);
311
312
  return {
312
313
  type: 'docs.node',
314
+ // The docs tree names each node's npm package as its provider.
315
+ package: found.node.provider,
313
316
  data: await nodeView(found.catalog, found.tree, found.node),
314
317
  };
315
318
  }
@@ -21,3 +21,4 @@ export function resolveHookDoc(coreDir: string, name: string, { zh, lang }?: {
21
21
  zh?: boolean;
22
22
  lang?: string | null;
23
23
  }): Promise<import("./hook.type.mjs").HookDoc>;
24
+ export { CORE_PROVIDER_ID as CORE_PACKAGE } from "../../foundation/identity/providers.mjs";
@@ -24,6 +24,9 @@ import {levenshteinDistance} from '../../foundation/text/string-utils.mjs';
24
24
  import {AstryxError} from '../error.mjs';
25
25
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
26
26
 
27
+ /** The package that owns Core's components, hooks, and codemods. */
28
+ export {CORE_PROVIDER_ID as CORE_PACKAGE} from '../../foundation/identity/providers.mjs';
29
+
27
30
  /**
28
31
  * Locate the @astryxdesign/core package directory, or throw the same
29
32
  * ERR_CORE_NOT_FOUND envelope the flat command threw. Shared by every hook leaf.
@@ -12,7 +12,7 @@
12
12
  * @position api/hook/detail/detail.mjs — dispatched from ../hook.mjs
13
13
  */
14
14
 
15
- import {resolveCoreDir, resolveHookDoc} from '../_adapter.mjs';
15
+ import {CORE_PACKAGE, resolveCoreDir, resolveHookDoc} from '../_adapter.mjs';
16
16
 
17
17
  /**
18
18
  * @param {string} name
@@ -22,5 +22,5 @@ import {resolveCoreDir, resolveHookDoc} from '../_adapter.mjs';
22
22
  export async function detail(name, {cwd = process.cwd(), zh = false, lang = null} = {}) {
23
23
  const coreDir = resolveCoreDir(cwd);
24
24
  const docs = await resolveHookDoc(coreDir, name, {zh, lang});
25
- return {type: 'hook.detail', data: docs};
25
+ return {type: 'hook.detail', package: CORE_PACKAGE, data: docs};
26
26
  }
@@ -12,7 +12,7 @@
12
12
  * @position api/hook/detail/params/params.mjs — dispatched from ../../hook.mjs
13
13
  */
14
14
 
15
- import {resolveCoreDir, resolveHookDoc} from '../../_adapter.mjs';
15
+ import {CORE_PACKAGE, resolveCoreDir, resolveHookDoc} from '../../_adapter.mjs';
16
16
 
17
17
  /**
18
18
  * @param {string} name
@@ -22,5 +22,5 @@ import {resolveCoreDir, resolveHookDoc} from '../../_adapter.mjs';
22
22
  export async function params(name, {cwd = process.cwd(), zh = false, lang = null} = {}) {
23
23
  const coreDir = resolveCoreDir(cwd);
24
24
  const docs = await resolveHookDoc(coreDir, name, {zh, lang});
25
- return {type: 'hook.detail.params', data: docs.params || []};
25
+ return {type: 'hook.detail.params', package: CORE_PACKAGE, data: docs.params || []};
26
26
  }
@@ -15,6 +15,10 @@ export type HookParamDoc = import("@astryxdesign/cli/authoring").HookParamDoc;
15
15
  */
16
16
  export type HookListResponse = {
17
17
  type: "hook.list";
18
+ /**
19
+ * `@astryxdesign/core`, the only package that ships hooks.
20
+ */
21
+ package: string;
18
22
  data: HookListData;
19
23
  };
20
24
  /**
@@ -43,6 +47,10 @@ export type HookBriefEntry = {
43
47
  */
44
48
  export type HookDetailResponse = {
45
49
  type: "hook.detail";
50
+ /**
51
+ * `@astryxdesign/core`, the only package that ships hooks.
52
+ */
53
+ package: string;
46
54
  data: HookDoc;
47
55
  };
48
56
  /**
@@ -50,6 +58,10 @@ export type HookDetailResponse = {
50
58
  */
51
59
  export type HookDetailParamsResponse = {
52
60
  type: "hook.detail.params";
61
+ /**
62
+ * `@astryxdesign/core`, the only package that ships hooks.
63
+ */
64
+ package: string;
53
65
  data: HookParamDoc[];
54
66
  };
55
67
  /**
@@ -39,6 +39,7 @@
39
39
  *
40
40
  * @typedef {object} HookListResponse
41
41
  * @property {'hook.list'} type
42
+ * @property {string} package `@astryxdesign/core`, the only package that ships hooks.
42
43
  * @property {HookListData} data
43
44
  */
44
45
 
@@ -59,6 +60,7 @@
59
60
  * astryx --json hook <name>
60
61
  * @typedef {object} HookDetailResponse
61
62
  * @property {'hook.detail'} type
63
+ * @property {string} package `@astryxdesign/core`, the only package that ships hooks.
62
64
  * @property {HookDoc} data
63
65
  */
64
66
 
@@ -66,6 +68,7 @@
66
68
  * astryx --json hook <name> --params
67
69
  * @typedef {object} HookDetailParamsResponse
68
70
  * @property {'hook.detail.params'} type
71
+ * @property {string} package `@astryxdesign/core`, the only package that ships hooks.
69
72
  * @property {HookParamDoc[]} data
70
73
  */
71
74