@astryxdesign/cli 0.6.3-canary.aa04154 → 0.6.3-canary.abbb293

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 (38) hide show
  1. package/api/docs/_adapter.d.mts +49 -7
  2. package/api/docs/_adapter.mjs +284 -33
  3. package/api/docs/docs.doc.mjs +4 -3
  4. package/api/docs/docs.type.d.mts +21 -5
  5. package/api/docs/docs.type.mjs +21 -5
  6. package/api/docs/integration-tree.test.mjs +9 -1
  7. package/api/docs/reference-blocks.test.mjs +406 -0
  8. package/api/doctor/doctor.mjs +5 -1
  9. package/api/integration/authoring-checks.mjs +14 -1
  10. package/api/template/table-floating-bulk-actions.test.mjs +66 -0
  11. package/assets/docs/styling-libraries.doc.mjs +1 -1
  12. package/assets/docs/theme.doc.mjs +1 -1
  13. package/assets/templates/blocks/components/CheckboxList/CheckboxListSelectAllPattern.doc.mjs +1 -1
  14. package/assets/templates/blocks/components/CheckboxList/CheckboxListSelectAllPattern.tsx +1 -3
  15. package/assets/templates/blocks/components/Table/TableBulkActionsTable.doc.mjs +14 -0
  16. package/assets/templates/blocks/components/Table/TableBulkActionsTable.tsx +71 -0
  17. package/assets/templates/blocks/components/Table/TableFloatingBulkActionsTable.doc.mjs +19 -0
  18. package/assets/templates/blocks/components/Table/TableFloatingBulkActionsTable.tsx +139 -0
  19. package/authoring/doctypes/_schema.d.mts +72 -0
  20. package/authoring/doctypes/_schema.mjs +25 -1
  21. package/authoring/doctypes/load-contract.test.mjs +25 -0
  22. package/authoring/doctypes/reference/reference.doc.mjs +31 -4
  23. package/authoring/doctypes/reference/type.ts +20 -5
  24. package/clients/cli/commands/docs.mjs +2 -2
  25. package/clients/cli/commands/doctor-integration-docs.doc.mjs +1 -1
  26. package/foundation/discovery/authoring-self-docs.d.mts +12 -0
  27. package/foundation/discovery/authoring-self-docs.mjs +20 -8
  28. package/foundation/discovery/authoring-self-docs.test.mjs +7 -2
  29. package/foundation/discovery/docs-discovery.d.mts +4 -1
  30. package/foundation/discovery/docs-discovery.mjs +40 -6
  31. package/foundation/discovery/docs-discovery.test.mjs +40 -0
  32. package/foundation/doc-compiler/lenses.d.mts +5 -3
  33. package/foundation/doc-compiler/lenses.mjs +48 -3
  34. package/foundation/doc-compiler/links.d.mts +30 -3
  35. package/foundation/doc-compiler/links.mjs +46 -5
  36. package/foundation/doc-compiler/links.test.mjs +53 -0
  37. package/foundation/integrations/cli-requirement.test.mjs +17 -42
  38. package/package.json +9 -9
@@ -310,6 +310,46 @@ describe('problemsInTopic', () => {
310
310
  }
311
311
  });
312
312
 
313
+ it('takes a reference block, and checks its projection and presentation', () => {
314
+ /** @param {any[]} content */
315
+ const withBlocks = content =>
316
+ problemsInTopic(topic({sections: [{title: 'Overview', content}]}));
317
+ expect(
318
+ withBlocks([
319
+ {type: 'reference', target: 'schema:integration'},
320
+ {
321
+ type: 'reference',
322
+ target: '@astryxdesign/cli:schema:integration',
323
+ projection: {fields: ['docs']},
324
+ presentation: 'compact',
325
+ },
326
+ ]),
327
+ ).toEqual([]);
328
+ expect(
329
+ withBlocks([
330
+ {type: 'reference', target: ''},
331
+ {type: 'reference', target: 'schema:x', presentation: 'card'},
332
+ {type: 'reference', target: 'schema:x', projection: {fields: []}},
333
+ {type: 'reference', target: 'schema:x', projection: {rows: ['a']}},
334
+ {type: 'reference', target: 'schema:x', projection: ['docs']},
335
+ {type: 'reference', target: 'schema:x', link: {}},
336
+ ]),
337
+ ).toEqual([
338
+ 'sections[0].content[0].target: expected a non-empty string',
339
+ 'sections[0].content[1].presentation: "card" is not one of summary, compact, full',
340
+ 'sections[0].content[2].projection.fields: expected a non-empty array of names',
341
+ 'sections[0].content[3].projection.rows: not a field of a projection',
342
+ 'sections[0].content[4].projection: expected {fields?, sections?}, naming the parts of the doc to include',
343
+ 'sections[0].content[5].link: not a field of a reference block',
344
+ ]);
345
+ // Workflow and collection blocks stay in a namespace doc's `blocks`.
346
+ for (const type of ['workflow', 'collection']) {
347
+ expect(withBlocks([{type}]).join('\n')).toContain(
348
+ 'requires the compiled graph renderer',
349
+ );
350
+ }
351
+ });
352
+
313
353
  it('rejects a name that is not URL-safe', () => {
314
354
  expect(problemsInTopic(topic({name: 'not a topic'})).join('\n')).toContain(
315
355
  'URL-safe',
@@ -24,9 +24,11 @@ export function detailView(node: import("./compile.mjs").CompiledReferenceNode):
24
24
  */
25
25
  export function indexView(node: import("./compile.mjs").CompiledReferenceNode): Omit<import("../../api/docs/docs.type.mjs").DocsIndex, "links">;
26
26
  /**
27
- * `docs.detail.section`: one section with its token references inlined. A
28
- * referenced section's content takes the reference's place; the section takes
29
- * the preview type of the last reference that has one, unless it has its own.
27
+ * `docs.detail.section`: one section with its token references and reference
28
+ * blocks inlined, so a read returns only the stable block kinds. A referenced
29
+ * section's content takes the token reference's place; the section takes the
30
+ * preview type of the last reference that has one, unless it has its own. A
31
+ * reference block becomes the content it includes (see referenceView).
30
32
  * @param {import('./compile.mjs').CompiledReferenceNode} node
31
33
  * @param {any} section a linked section of `node`
32
34
  * @returns {any}
@@ -71,9 +71,11 @@ export function indexView(node) {
71
71
  }
72
72
 
73
73
  /**
74
- * `docs.detail.section`: one section with its token references inlined. A
75
- * referenced section's content takes the reference's place; the section takes
76
- * the preview type of the last reference that has one, unless it has its own.
74
+ * `docs.detail.section`: one section with its token references and reference
75
+ * blocks inlined, so a read returns only the stable block kinds. A referenced
76
+ * section's content takes the token reference's place; the section takes the
77
+ * preview type of the last reference that has one, unless it has its own. A
78
+ * reference block becomes the content it includes (see referenceView).
77
79
  * @param {import('./compile.mjs').CompiledReferenceNode} node
78
80
  * @param {any} section a linked section of `node`
79
81
  * @returns {any}
@@ -84,6 +86,10 @@ export function sectionView(node, section) {
84
86
  /** @type {string | null} */
85
87
  let previewType = null;
86
88
  for (const block of section.content) {
89
+ if (block?.type === 'reference') {
90
+ content.push(...referenceView(node, block));
91
+ continue;
92
+ }
87
93
  if (block?.type !== 'token-ref') {
88
94
  content.push(structuredClone(block));
89
95
  continue;
@@ -126,3 +132,42 @@ export function sectionView(node, section) {
126
132
  view.content = content;
127
133
  return withSourceTitle(view, authoredTitle(node, section));
128
134
  }
135
+
136
+ /**
137
+ * A reference block as a read shows it (spec:AST-047 FR9): the content it
138
+ * includes, then where that content comes from and the command that opens it.
139
+ * A reference that includes nothing (a summary, or a doc that is not included
140
+ * whole) shows the doc's title and summary; one whose doc is missing says so
141
+ * where its content would be, as a token reference does.
142
+ * @param {import('./compile.mjs').CompiledReferenceNode} node
143
+ * @param {any} block a linked reference block
144
+ * @returns {any[]}
145
+ */
146
+ function referenceView(node, block) {
147
+ if (!('link' in block)) {
148
+ throw new Error(
149
+ `The reference to "${block.target}" in "${node.id}" was read before it was linked.`,
150
+ );
151
+ }
152
+ const link = block.link;
153
+ if (link == null) {
154
+ return [
155
+ {type: 'prose', text: `[reference: "${block.target}" names no doc]`},
156
+ ];
157
+ }
158
+ const included = (block.content ?? []).map((/** @type {any} */ each) =>
159
+ structuredClone(each),
160
+ );
161
+ if (included.length === 0) {
162
+ const summary = String(link.summary ?? '').trim();
163
+ const lead =
164
+ summary === ''
165
+ ? link.title
166
+ : `${link.title}: ${summary}${/[.!?]$/.test(summary) ? '' : '.'}`;
167
+ return [{type: 'prose', text: `${lead} Read it with \`${link.command}\`.`}];
168
+ }
169
+ return [
170
+ ...included,
171
+ {type: 'prose', text: `From ${link.title}: \`${link.command}\``},
172
+ ];
173
+ }
@@ -27,6 +27,15 @@
27
27
  * @property {string} target the target as written
28
28
  * @property {string} message
29
29
  * @property {string} [section] the key of the section the link sits in
30
+ * @property {true} [include] the problem is in a `reference` block, which
31
+ * includes content rather than linking to it: a reader loses that content,
32
+ * so the authoring check fails on it
33
+ */
34
+ /**
35
+ * What a `reference` block in a topic section includes of the doc it names:
36
+ * stable content blocks, with anything it could not include named in
37
+ * `problems`.
38
+ * @typedef {(block: any) => Promise<{content: any[], problems: string[]}>} DocIncluder
30
39
  */
31
40
  /**
32
41
  * Parse `[<provider>:]<kind>:<name>`. A name may hold spaces
@@ -49,11 +58,13 @@ export function unlinkText(text: string): string;
49
58
  * @param {any[]} blocks
50
59
  * @param {LinkResolver} resolve
51
60
  * @param {{section?: string}} [at]
61
+ * @param {DocIncluder} [include] how a `reference` block includes the doc it
62
+ * names; without it, the block only carries its `link`
52
63
  * @returns {Promise<{content: any[], problems: LinkProblem[]}>}
53
64
  */
54
65
  export function linkBlocks(blocks: any[], resolve: LinkResolver, at?: {
55
66
  section?: string;
56
- }): Promise<{
67
+ }, include?: DocIncluder): Promise<{
57
68
  content: any[];
58
69
  problems: LinkProblem[];
59
70
  }>;
@@ -75,8 +86,9 @@ export function linkSections(sections: any[], resolve: LinkResolver): Promise<{
75
86
  * `{@link <target>}`; and a resolver that finds the doc a target names.
76
87
  * @output The same content with every link resolved: an inline link becomes
77
88
  * the `astryx docs` command that opens its doc, and a block carries a `link`
78
- * with the doc's identity, route, title, summary, and command. A link that
79
- * names no doc is a problem, never a guess.
89
+ * with the doc's identity, route, title, summary, and command. A reference
90
+ * block in a topic section also carries the `content` it includes. A link
91
+ * that names no doc is a problem, never a guess.
80
92
  * @position Pure. The docs adapter owns the resolver (the project's docs tree
81
93
  * and topic catalog) and applies this to every read and every doctor check.
82
94
  */
@@ -132,4 +144,19 @@ export type LinkProblem = {
132
144
  * the key of the section the link sits in
133
145
  */
134
146
  section?: string | undefined;
147
+ /**
148
+ * the problem is in a `reference` block, which
149
+ * includes content rather than linking to it: a reader loses that content,
150
+ * so the authoring check fails on it
151
+ */
152
+ include?: true | undefined;
135
153
  };
154
+ /**
155
+ * What a `reference` block in a topic section includes of the doc it names:
156
+ * stable content blocks, with anything it could not include named in
157
+ * `problems`.
158
+ */
159
+ export type DocIncluder = (block: any) => Promise<{
160
+ content: any[];
161
+ problems: string[];
162
+ }>;
@@ -8,8 +8,9 @@
8
8
  * `{@link <target>}`; and a resolver that finds the doc a target names.
9
9
  * @output The same content with every link resolved: an inline link becomes
10
10
  * the `astryx docs` command that opens its doc, and a block carries a `link`
11
- * with the doc's identity, route, title, summary, and command. A link that
12
- * names no doc is a problem, never a guess.
11
+ * with the doc's identity, route, title, summary, and command. A reference
12
+ * block in a topic section also carries the `content` it includes. A link
13
+ * that names no doc is a problem, never a guess.
13
14
  * @position Pure. The docs adapter owns the resolver (the project's docs tree
14
15
  * and topic catalog) and applies this to every read and every doctor check.
15
16
  */
@@ -62,6 +63,16 @@ const CODE_SPAN = /(`[^`]*`)/;
62
63
  * @property {string} target the target as written
63
64
  * @property {string} message
64
65
  * @property {string} [section] the key of the section the link sits in
66
+ * @property {true} [include] the problem is in a `reference` block, which
67
+ * includes content rather than linking to it: a reader loses that content,
68
+ * so the authoring check fails on it
69
+ */
70
+
71
+ /**
72
+ * What a `reference` block in a topic section includes of the doc it names:
73
+ * stable content blocks, with anything it could not include named in
74
+ * `problems`.
75
+ * @typedef {(block: any) => Promise<{content: any[], problems: string[]}>} DocIncluder
65
76
  */
66
77
 
67
78
  /**
@@ -119,9 +130,11 @@ export function unlinkText(text) {
119
130
  * @param {any[]} blocks
120
131
  * @param {LinkResolver} resolve
121
132
  * @param {{section?: string}} [at]
133
+ * @param {DocIncluder} [include] how a `reference` block includes the doc it
134
+ * names; without it, the block only carries its `link`
122
135
  * @returns {Promise<{content: any[], problems: LinkProblem[]}>}
123
136
  */
124
- export async function linkBlocks(blocks, resolve, at = {}) {
137
+ export async function linkBlocks(blocks, resolve, at = {}, include) {
125
138
  /** @type {LinkProblem[]} */
126
139
  const problems = [];
127
140
  const where = at.section ? {section: at.section} : {};
@@ -195,9 +208,37 @@ export async function linkBlocks(blocks, resolve, at = {}) {
195
208
  });
196
209
  break;
197
210
  }
198
- case 'reference':
199
- content.push({...block, link: await find(block.target)});
211
+ case 'reference': {
212
+ // A reference includes content, so what it cannot include is a
213
+ // problem the authoring check fails on, not one that prints as written.
214
+ const found = await resolve(block.target);
215
+ if ('problem' in found) {
216
+ problems.push({
217
+ target: block.target,
218
+ message: found.problem,
219
+ include: true,
220
+ ...where,
221
+ });
222
+ content.push({...block, link: null});
223
+ break;
224
+ }
225
+ /** @type {any} */
226
+ const linked = {...block, link: found};
227
+ if (include) {
228
+ const included = await include(block);
229
+ for (const message of included.problems) {
230
+ problems.push({
231
+ target: block.target,
232
+ message,
233
+ include: true,
234
+ ...where,
235
+ });
236
+ }
237
+ linked.content = included.content;
238
+ }
239
+ content.push(linked);
200
240
  break;
241
+ }
201
242
  case 'workflow': {
202
243
  const steps = [];
203
244
  for (const step of block.steps ?? []) {
@@ -105,6 +105,59 @@ describe('linkBlocks', () => {
105
105
  );
106
106
  });
107
107
 
108
+ it('includes what a reference block names, and marks what it cannot include', async () => {
109
+ /** @type {any[]} */
110
+ const asked = [];
111
+ const include = async (/** @type {any} */ block) => {
112
+ asked.push(block.target);
113
+ return {
114
+ content: [{type: 'prose', text: 'The doctor command.'}],
115
+ problems: block.projection ? ['projection.fields: no such field'] : [],
116
+ };
117
+ };
118
+ const {content, problems} = await linkBlocks(
119
+ [
120
+ {type: 'reference', target: 'command:doctor'},
121
+ {
122
+ type: 'reference',
123
+ target: 'command:doctor',
124
+ projection: {fields: ['--nope']},
125
+ },
126
+ {type: 'reference', target: 'command:gone'},
127
+ ],
128
+ resolve,
129
+ {section: 'check'},
130
+ include,
131
+ );
132
+ // A target that names no doc is never handed to the includer.
133
+ expect(asked).toEqual(['command:doctor', 'command:doctor']);
134
+ expect(content[0]).toMatchObject({
135
+ link: {command: 'astryx docs cli/commands/doctor'},
136
+ content: [{type: 'prose', text: 'The doctor command.'}],
137
+ });
138
+ expect(content[2]).toEqual({
139
+ type: 'reference',
140
+ target: 'command:gone',
141
+ link: null,
142
+ });
143
+ // Both are the authoring check's: the block includes content, where a
144
+ // link only points at it.
145
+ expect(problems).toEqual([
146
+ {
147
+ target: 'command:doctor',
148
+ message: 'projection.fields: no such field',
149
+ include: true,
150
+ section: 'check',
151
+ },
152
+ {
153
+ target: 'command:gone',
154
+ message: '"command:gone" names no doc',
155
+ include: true,
156
+ section: 'check',
157
+ },
158
+ ]);
159
+ });
160
+
108
161
  it('names every link that finds no doc, and never guesses', async () => {
109
162
  const {content, problems} = await linkSections(
110
163
  [
@@ -1,10 +1,6 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  import {describe, expect, it} from 'vitest';
4
- import * as fs from 'node:fs';
5
- import * as path from 'node:path';
6
- import {CLI_ROOT} from '../fs/paths.mjs';
7
- import {semverCompare} from '../env/semver.mjs';
8
4
  import {
9
5
  DOCS_TREE_CLI,
10
6
  lowestAdmitted,
@@ -55,55 +51,34 @@ describe('docsTreeCliProblem', () => {
55
51
 
56
52
  it('declares the peer as optional, and keeps what the package says of it', () => {
57
53
  const declared = withDocsTreeCli({name: '@acme/kit'});
58
- expect(declared.peerDependencies).toEqual({'@astryxdesign/cli': `>=${DOCS_TREE_CLI}`});
59
- expect(declared.peerDependenciesMeta).toEqual({'@astryxdesign/cli': {optional: true}});
54
+ expect(declared.peerDependencies).toEqual({
55
+ '@astryxdesign/cli': `>=${DOCS_TREE_CLI}`,
56
+ });
57
+ expect(declared.peerDependenciesMeta).toEqual({
58
+ '@astryxdesign/cli': {optional: true},
59
+ });
60
60
  expect(docsTreeCliProblem(declared)).toBeNull();
61
61
  const required = withDocsTreeCli({
62
62
  peerDependencies: {react: '^19.0.0', '@astryxdesign/cli': '^0.6.0'},
63
63
  peerDependenciesMeta: {'@astryxdesign/cli': {optional: false}},
64
64
  });
65
65
  expect(required.peerDependencies.react).toBe('^19.0.0');
66
- expect(required.peerDependenciesMeta['@astryxdesign/cli']).toEqual({optional: false});
66
+ expect(required.peerDependenciesMeta['@astryxdesign/cli']).toEqual({
67
+ optional: false,
68
+ });
67
69
  });
68
70
  });
69
71
 
70
72
  describe('replacesCliProblem', () => {
71
73
  it('asks a package that sets replaces for a CLI that reads the field', () => {
72
- expect(replacesCliProblem({name: '@acme/kit'})).toContain('sets `replaces`');
73
- expect(replacesCliProblem({peerDependencies: {'@astryxdesign/cli': '^0.6.0'}})).toContain(
74
- 'admits a CLI older than',
75
- );
76
- expect(replacesCliProblem({peerDependencies: {'@astryxdesign/cli': '>=0.7.0'}})).toBeNull();
77
- });
78
- });
79
-
80
- describe('DOCS_TREE_CLI', () => {
81
- it('is no later than the release the pending changesets make', () => {
82
- const {version} = JSON.parse(
83
- fs.readFileSync(path.join(CLI_ROOT, 'package.json'), 'utf-8'),
74
+ expect(replacesCliProblem({name: '@acme/kit'})).toContain(
75
+ 'sets `replaces`',
84
76
  );
85
- const dir = path.join(CLI_ROOT, '..', '..', '.changeset');
86
- /** @type {Record<string, number>} */
87
- const rank = {patch: 1, minor: 2, major: 3};
88
- let bump = 0;
89
- for (const file of fs.readdirSync(dir)) {
90
- if (!file.endsWith('.md') || file === 'README.md') continue;
91
- const head = fs.readFileSync(path.join(dir, file), 'utf-8').split('---')[1] ?? '';
92
- const m = /['"]@astryxdesign\/cli['"]\s*:\s*(patch|minor|major)/.exec(head);
93
- if (m) bump = Math.max(bump, rank[m[1]]);
94
- }
95
- const [major, minor, patch] = version.split('-')[0].split('.').map(Number);
96
- const next =
97
- bump === 3
98
- ? `${major + 1}.0.0`
99
- : bump === 2
100
- ? `${major}.${minor + 1}.0`
101
- : bump === 1
102
- ? `${major}.${minor}.${patch + 1}`
103
- : version;
104
- // The first release that reads namespace docs is this one or an earlier
105
- // one; a later constant would make every author wait for a CLI that does
106
- // not exist yet.
107
- expect(semverCompare(DOCS_TREE_CLI, next)).toBeLessThanOrEqual(0);
77
+ expect(
78
+ replacesCliProblem({peerDependencies: {'@astryxdesign/cli': '^0.6.0'}}),
79
+ ).toContain('admits a CLI older than');
80
+ expect(
81
+ replacesCliProblem({peerDependencies: {'@astryxdesign/cli': '>=0.7.0'}}),
82
+ ).toBeNull();
108
83
  });
109
84
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.6.3-canary.aa04154",
3
+ "version": "0.6.3-canary.abbb293",
4
4
  "displayName": "CLI",
5
5
  "description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
6
6
  "author": "Meta Open Source",
@@ -101,10 +101,10 @@
101
101
  "zod": "^4.4.3"
102
102
  },
103
103
  "peerDependencies": {
104
- "@astryxdesign/charts": "0.6.3-canary.aa04154",
105
- "@astryxdesign/core": "0.6.3-canary.aa04154",
106
- "@astryxdesign/lab": "0.6.3-canary.aa04154",
107
- "@astryxdesign/theme-neutral": "0.6.3-canary.aa04154"
104
+ "@astryxdesign/charts": "0.6.3-canary.abbb293",
105
+ "@astryxdesign/core": "0.6.3-canary.abbb293",
106
+ "@astryxdesign/lab": "0.6.3-canary.abbb293",
107
+ "@astryxdesign/theme-neutral": "0.6.3-canary.abbb293"
108
108
  },
109
109
  "peerDependenciesMeta": {
110
110
  "@astryxdesign/charts": {
@@ -121,10 +121,10 @@
121
121
  }
122
122
  },
123
123
  "devDependencies": {
124
- "@astryxdesign/charts": "0.6.3-canary.aa04154",
125
- "@astryxdesign/core": "0.6.3-canary.aa04154",
126
- "@astryxdesign/lab": "0.6.3-canary.aa04154",
127
- "@astryxdesign/theme-neutral": "0.6.3-canary.aa04154",
124
+ "@astryxdesign/charts": "0.6.3-canary.abbb293",
125
+ "@astryxdesign/core": "0.6.3-canary.abbb293",
126
+ "@astryxdesign/lab": "0.6.3-canary.abbb293",
127
+ "@astryxdesign/theme-neutral": "0.6.3-canary.abbb293",
128
128
  "@heroicons/react": "^2.2.0",
129
129
  "@stylexjs/stylex": "^0.19.0",
130
130
  "@types/babel__core": "^7.20.5",