@astryxdesign/cli 0.6.3-canary.f839b67 → 0.6.4-canary.06c8fa3

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 (189) hide show
  1. package/CHANGELOG.md +194 -0
  2. package/README.md +64 -66
  3. package/api/component/_adapter.d.mts +25 -0
  4. package/api/component/_adapter.mjs +59 -5
  5. package/api/component/component.d.mts +6 -3
  6. package/api/component/component.doc.mjs +23 -10
  7. package/api/component/component.mjs +249 -9
  8. package/api/component/component.type.d.mts +25 -0
  9. package/api/component/component.type.mjs +44 -0
  10. package/api/discover/_adapter.d.mts +114 -6
  11. package/api/discover/_adapter.mjs +372 -17
  12. package/api/discover/_adapter.test.mjs +215 -0
  13. package/api/discover/_catalog-view.d.mts +115 -0
  14. package/api/discover/_catalog-view.mjs +203 -0
  15. package/api/discover/_catalog-view.test.mjs +128 -0
  16. package/api/discover/detail/detail.d.mts +18 -6
  17. package/api/discover/detail/detail.mjs +67 -13
  18. package/api/discover/detail/detail.test.mjs +85 -0
  19. package/api/discover/detail/item/item.d.mts +26 -0
  20. package/api/discover/detail/item/item.mjs +78 -0
  21. package/api/discover/detail/item/item.test.mjs +73 -0
  22. package/api/discover/discover.d.mts +3 -9
  23. package/api/discover/discover.doc.mjs +61 -18
  24. package/api/discover/discover.mjs +220 -36
  25. package/api/discover/discover.test.mjs +11 -2
  26. package/api/discover/discover.type.d.mts +147 -8
  27. package/api/discover/discover.type.mjs +102 -12
  28. package/api/discover/list/list.d.mts +20 -6
  29. package/api/discover/list/list.mjs +45 -12
  30. package/api/discover/list/list.test.mjs +46 -0
  31. package/api/discover/search/search.d.mts +18 -16
  32. package/api/discover/search/search.mjs +102 -56
  33. package/api/discover/search/search.test.mjs +144 -10
  34. package/api/docs/_adapter.d.mts +49 -7
  35. package/api/docs/_adapter.mjs +284 -33
  36. package/api/docs/docs.doc.mjs +4 -3
  37. package/api/docs/docs.test.mjs +2 -0
  38. package/api/docs/docs.type.d.mts +21 -5
  39. package/api/docs/docs.type.mjs +21 -5
  40. package/api/docs/integration-tree.test.mjs +9 -1
  41. package/api/docs/reference-blocks.test.mjs +406 -0
  42. package/api/doctor/doctor.d.mts +8 -3
  43. package/api/doctor/doctor.mjs +95 -10
  44. package/api/doctor/doctor.test.mjs +122 -10
  45. package/api/index.d.mts +1 -2
  46. package/api/index.mjs +4 -4
  47. package/api/integration/add-helpers.d.mts +5 -2
  48. package/api/integration/add-helpers.mjs +36 -9
  49. package/api/integration/authoring-checks.mjs +14 -1
  50. package/api/integration/pack-check.lifecycle-output.test.mjs +105 -0
  51. package/api/integration/pack-check.mjs +28 -3
  52. package/api/json/index.ts +0 -1
  53. package/api/search/search.test.mjs +18 -0
  54. package/api/template/table-floating-bulk-actions.test.mjs +66 -0
  55. package/api/template/template-integration.test.mjs +1 -65
  56. package/api/template/template.mjs +1 -1
  57. package/api/theme/add/add.mjs +17 -25
  58. package/api/theme/add/add.rollback.test.mjs +158 -0
  59. package/api/theme/add/add.staging.test.mjs +40 -23
  60. package/api/theme/build/build.family.test.mjs +7 -12
  61. package/api/theme/build/build.mjs +8 -18
  62. package/api/theme/build/build.rollback.test.mjs +148 -0
  63. package/api/upgrade/run/files-changed.test.mjs +111 -0
  64. package/api/upgrade/run/run.mjs +6 -4
  65. package/api/upgrade/upgrade.type.mjs +2 -2
  66. package/assets/codemods/__tests__/registry.test.mjs +1 -0
  67. package/assets/codemods/__tests__/runner.test.mjs +3 -1
  68. package/assets/codemods/file-count.test.mjs +163 -0
  69. package/assets/codemods/integration-runner.mjs +3 -3
  70. package/assets/codemods/registry.mjs +1 -0
  71. package/assets/codemods/runner.mjs +5 -4
  72. package/assets/codemods/transforms/next/index.mjs +1 -19
  73. package/assets/codemods/transforms/v0.6.4/index.mjs +31 -0
  74. package/assets/docs/internationalization.doc.mjs +7 -5
  75. package/assets/docs/styling-libraries.doc.mjs +1 -1
  76. package/assets/docs/theme.doc.mjs +1 -1
  77. package/assets/docs/tree/component-lookups.doc.mjs +149 -0
  78. package/assets/docs/tree/integrations.doc.mjs +20 -1
  79. package/assets/templates/blocks/components/CheckboxList/CheckboxListSelectAllPattern.doc.mjs +1 -1
  80. package/assets/templates/blocks/components/CheckboxList/CheckboxListSelectAllPattern.tsx +1 -3
  81. package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider01ShippedLocale.tsx +1 -1
  82. package/assets/templates/blocks/components/Table/TableBulkActionsTable.doc.mjs +14 -0
  83. package/assets/templates/blocks/components/Table/TableBulkActionsTable.tsx +71 -0
  84. package/assets/templates/blocks/components/Table/TableFloatingBulkActionsTable.doc.mjs +19 -0
  85. package/assets/templates/blocks/components/Table/TableFloatingBulkActionsTable.tsx +139 -0
  86. package/authoring/config/config.doc.mjs +9 -1
  87. package/authoring/config/parse.d.mts +2 -0
  88. package/authoring/config/parse.mjs +19 -0
  89. package/authoring/config/parse.test.mjs +8 -0
  90. package/authoring/config/type.ts +13 -2
  91. package/authoring/discover/discover.doc.d.mts +13 -0
  92. package/authoring/discover/discover.doc.mjs +138 -0
  93. package/authoring/discover/parse.d.mts +24 -0
  94. package/authoring/discover/parse.mjs +128 -0
  95. package/authoring/discover/parse.test.mjs +124 -0
  96. package/authoring/discover/type.ts +87 -0
  97. package/authoring/doctypes/_schema.d.mts +72 -0
  98. package/authoring/doctypes/_schema.mjs +25 -1
  99. package/authoring/doctypes/command/command.doc.mjs +1 -1
  100. package/authoring/doctypes/command/type.ts +1 -1
  101. package/authoring/doctypes/load-contract.test.mjs +25 -0
  102. package/authoring/doctypes/reference/reference.doc.mjs +31 -4
  103. package/authoring/doctypes/reference/type.ts +20 -5
  104. package/authoring/index.d.mts +1 -0
  105. package/authoring/index.d.ts +10 -0
  106. package/authoring/index.mjs +1 -0
  107. package/clients/cli/command-result-coverage.test.mjs +7 -7
  108. package/clients/cli/commands/component/index.mjs +152 -55
  109. package/clients/cli/commands/component-batch.test.mjs +341 -0
  110. package/clients/cli/commands/component-ownership.test.mjs +89 -0
  111. package/clients/cli/commands/component.doc.mjs +23 -6
  112. package/clients/cli/commands/debug-result-summary.test.mjs +2 -2
  113. package/clients/cli/commands/discover.doc.mjs +53 -9
  114. package/clients/cli/commands/discover.mjs +393 -118
  115. package/clients/cli/commands/discover.sources.test.mjs +267 -0
  116. package/clients/cli/commands/docs.mjs +2 -2
  117. package/clients/cli/commands/docs.test.mjs +29 -0
  118. package/clients/cli/commands/doctor-integration-docs.doc.mjs +1 -1
  119. package/clients/cli/commands/text-json-parity.test.mjs +0 -17
  120. package/clients/cli/index.mjs +0 -4
  121. package/clients/cli/lib/exit-codes.test.mjs +1 -8
  122. package/clients/cli/lib/json-shim.mjs +24 -14
  123. package/clients/cli/lib/json-shim.test.mjs +6 -20
  124. package/clients/cli/lib/manifest.mjs +3 -8
  125. package/clients/cli/lib/manifest.test.mjs +5 -2
  126. package/clients/cli/lib/parse-error-format.test.mjs +81 -0
  127. package/foundation/discovery/authoring-self-docs.d.mts +12 -0
  128. package/foundation/discovery/authoring-self-docs.mjs +21 -8
  129. package/foundation/discovery/authoring-self-docs.test.mjs +7 -2
  130. package/foundation/discovery/docs-discovery.d.mts +4 -1
  131. package/foundation/discovery/docs-discovery.mjs +40 -6
  132. package/foundation/discovery/docs-discovery.test.mjs +40 -0
  133. package/foundation/discovery/template-adapter.mjs +1 -1
  134. package/foundation/doc-compiler/doc-loads.test.mjs +0 -12
  135. package/foundation/doc-compiler/lenses.d.mts +5 -3
  136. package/foundation/doc-compiler/lenses.mjs +48 -3
  137. package/foundation/doc-compiler/links.d.mts +30 -3
  138. package/foundation/doc-compiler/links.mjs +46 -5
  139. package/foundation/doc-compiler/links.test.mjs +53 -0
  140. package/foundation/doc-compiler/tree.test.mjs +9 -1
  141. package/foundation/integrations/cli-requirement.test.mjs +17 -42
  142. package/foundation/integrations/integrations.d.mts +14 -1
  143. package/foundation/integrations/integrations.mjs +41 -1
  144. package/foundation/integrations/integrations.test.mjs +31 -0
  145. package/foundation/response/batch.type.d.mts +33 -0
  146. package/foundation/response/batch.type.mjs +34 -0
  147. package/foundation/response/response-types.doc.mjs +15 -21
  148. package/foundation/response/response-types.doc.test.mjs +23 -0
  149. package/foundation/xle/browser.d.mts +3 -3
  150. package/foundation/xle/browser.mjs +3 -3
  151. package/foundation/xle/expand.mjs +2 -2
  152. package/foundation/xle/parse.mjs +1 -1
  153. package/foundation/xle/print.mjs +2 -2
  154. package/foundation/xle/splice.mjs +1 -1
  155. package/package.json +9 -9
  156. package/api/layout/_adapter.d.mts +0 -34
  157. package/api/layout/_adapter.mjs +0 -148
  158. package/api/layout/check/check.d.mts +0 -16
  159. package/api/layout/check/check.mjs +0 -40
  160. package/api/layout/expand/expand.d.mts +0 -22
  161. package/api/layout/expand/expand.mjs +0 -155
  162. package/api/layout/expand/expand.path-safety.test.mjs +0 -53
  163. package/api/layout/grammar/grammar.d.mts +0 -13
  164. package/api/layout/grammar/grammar.mjs +0 -87
  165. package/api/layout/layout.d.mts +0 -6
  166. package/api/layout/layout.mjs +0 -17
  167. package/api/layout/layout.test.mjs +0 -297
  168. package/api/layout/layout.type.d.mts +0 -89
  169. package/api/layout/layout.type.mjs +0 -103
  170. package/api/layout/layoutCheck.doc.d.mts +0 -11
  171. package/api/layout/layoutCheck.doc.mjs +0 -85
  172. package/api/layout/layoutExpand.doc.d.mts +0 -11
  173. package/api/layout/layoutExpand.doc.mjs +0 -107
  174. package/api/layout/layoutGrammar.doc.d.mts +0 -11
  175. package/api/layout/layoutGrammar.doc.mjs +0 -57
  176. package/clients/cli/commands/layout-check.doc.mjs +0 -65
  177. package/clients/cli/commands/layout-expand.doc.mjs +0 -83
  178. package/clients/cli/commands/layout-grammar.doc.mjs +0 -30
  179. package/clients/cli/commands/layout.doc.mjs +0 -34
  180. package/clients/cli/commands/layout.error-codes.test.mjs +0 -66
  181. package/clients/cli/commands/layout.exit-parity.test.mjs +0 -41
  182. package/clients/cli/commands/layout.mjs +0 -275
  183. package/clients/cli/commands/layout.path-help.test.mjs +0 -33
  184. package/clients/cli/commands/layout.stdin-cap.test.mjs +0 -47
  185. package/clients/cli/commands/layout.text-fields.test.mjs +0 -39
  186. /package/assets/codemods/transforms/{next → v0.6.4}/__tests__/migrate-native-picker-to-presentation.test.mjs +0 -0
  187. /package/assets/codemods/transforms/{next → v0.6.4}/__tests__/migrate-theme-catalog-to-descriptors.test.mjs +0 -0
  188. /package/assets/codemods/transforms/{next → v0.6.4}/migrate-native-picker-to-presentation.mjs +0 -0
  189. /package/assets/codemods/transforms/{next → v0.6.4}/migrate-theme-catalog-to-descriptors.mjs +0 -0
@@ -0,0 +1,138 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file SchemaDoc for DiscoverSource, the function `astryx discover` calls to
5
+ * learn which integrations a project could add.
6
+ * @input The DiscoverSource type and the catalog types beside it (`type.ts`),
7
+ * which `parse.mjs` validates.
8
+ * @output The `discover-source` section of `astryx docs authoring`.
9
+ * @position packages/cli/authoring/discover — schema documentation
10
+ */
11
+
12
+ /** @type {import('@astryxdesign/cli/authoring').SchemaDoc} */
13
+ export const doc = {
14
+ type: 'schema',
15
+ name: 'discover-source',
16
+ displayName: 'DiscoverSource',
17
+ namespace: 'authoring',
18
+ description:
19
+ 'A source for `astryx discover`: an async function that returns a catalog of packages a project could add, their versions, and what each version adds. Set it as `discover` in astryx.config, or export it as `discover` from an integration manifest. Discover calls every source, the project one first, and one that throws, runs past 30 seconds, or returns an invalid catalog never hides the others; discover then uses the last good answer it saved for that source. Discover only reads: it prints the command that adds a package and never runs it.',
20
+ appliesTo:
21
+ '`discover` in astryx.config.*, or the `discover` named export of astryx.integration.*',
22
+ fields: [
23
+ {
24
+ name: 'context',
25
+ type: 'DiscoverSourceContext',
26
+ description: 'The one argument the source is called with.',
27
+ required: true,
28
+ fields: [
29
+ {
30
+ name: 'context.signal',
31
+ type: 'AbortSignal',
32
+ description: 'Aborted when the source runs past 30 seconds.',
33
+ required: true,
34
+ },
35
+ {
36
+ name: 'context.package',
37
+ type: 'string',
38
+ description:
39
+ 'Set when discover shows one package: return that package with every version.',
40
+ },
41
+ {
42
+ name: 'context.version',
43
+ type: 'string',
44
+ description:
45
+ "With `package`: return that version's contributions. Without it, the latest release's.",
46
+ },
47
+ ],
48
+ },
49
+ {
50
+ name: 'returns',
51
+ type: 'Promise<DiscoverCatalog>',
52
+ description:
53
+ 'The catalog. Discover checks it, ignores fields and item kinds it does not know, and refuses any schemaVersion but 1.',
54
+ required: true,
55
+ fields: [
56
+ {
57
+ name: 'schemaVersion',
58
+ type: '1',
59
+ description: 'Version of the catalog shape.',
60
+ required: true,
61
+ },
62
+ {
63
+ name: 'source',
64
+ type: '{name: string, generatedAt: string, complete: boolean}',
65
+ description:
66
+ 'Who answered, when the data was produced (ISO 8601), and false when the source knows its list is partial.',
67
+ required: true,
68
+ },
69
+ {
70
+ name: 'packages',
71
+ type: 'DiscoverPackage[]',
72
+ description:
73
+ 'One entry per npm package. When two sources list the same package, the earlier source wins.',
74
+ required: true,
75
+ fields: [
76
+ {
77
+ name: 'packages[].package',
78
+ type: 'string',
79
+ description: 'The npm name.',
80
+ required: true,
81
+ },
82
+ {
83
+ name: 'packages[].integration',
84
+ type: 'string',
85
+ description:
86
+ 'Shared by every npm name that publishes the same integration. Discover lists an integration once.',
87
+ required: true,
88
+ },
89
+ {
90
+ name: 'packages[].aliases',
91
+ type: 'string[]',
92
+ description:
93
+ "The integration's other npm names. Discover never offers a package the project has under another name.",
94
+ required: true,
95
+ },
96
+ {
97
+ name: 'packages[].description',
98
+ type: 'string',
99
+ description: 'One line, for the list and search.',
100
+ },
101
+ {
102
+ name: 'packages[].latest',
103
+ type: 'string | null',
104
+ description: 'The latest release. Null when there are only prereleases.',
105
+ required: true,
106
+ },
107
+ {
108
+ name: 'packages[].versions',
109
+ type: 'DiscoverVersion[]',
110
+ description:
111
+ 'Every version, newest first: `{version, publishedAt, prerelease, status}`, where status is `ok` or why the version could not be read.',
112
+ required: true,
113
+ },
114
+ {
115
+ name: 'packages[].contributions',
116
+ type: 'DiscoverContribution[]',
117
+ description:
118
+ "What the requested (else latest) version adds: `{kind, name, title?, summary?, keywords?}`, where kind is `component`, `template`, `doc`, `theme`, `codemod`, or `agent-doc` (a DiscoverKind) and name is the name the CLI uses for it.",
119
+ required: true,
120
+ },
121
+ ],
122
+ },
123
+ ],
124
+ },
125
+ ],
126
+ examples: [
127
+ {
128
+ label: 'A project source in astryx.config',
129
+ code:
130
+ 'export default {\n' +
131
+ ' async discover({signal, package: name, version}) {\n' +
132
+ ' const res = await fetch(catalogUrl(name, version), {signal});\n' +
133
+ ' return res.json();\n' +
134
+ ' },\n' +
135
+ '};',
136
+ },
137
+ ],
138
+ };
@@ -0,0 +1,24 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in authoring/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * Check a catalog a discover source returned. Throws an Error naming the first
6
+ * problem. Items of a kind this CLI does not know are dropped, and versions are
7
+ * put newest first whatever order the source used.
8
+ *
9
+ * @param {unknown} value
10
+ * @param {string} [label]
11
+ * @returns {import('./type.js').DiscoverCatalog}
12
+ */
13
+ export function parseDiscoverCatalog(value: unknown, label?: string): import("./type.js").DiscoverCatalog;
14
+ /**
15
+ * Check a discover source itself: an async function, like `debug`, that takes
16
+ * `{signal, package?, version?}` and resolves to a catalog.
17
+ *
18
+ * @param {unknown} value
19
+ * @param {string} label
20
+ * @returns {import('./type.js').DiscoverSource}
21
+ */
22
+ export function parseDiscoverSource(value: unknown, label: string): import("./type.js").DiscoverSource;
23
+ /** Item kinds a catalog may list, in display order. */
24
+ export const DISCOVER_KINDS: readonly ["component", "template", "doc", "theme", "codemod", "agent-doc"];
@@ -0,0 +1,128 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Runtime checks for discover sources and the catalogs they return.
5
+ *
6
+ * The catalog schema is deliberately not strict: a source may add fields this
7
+ * CLI does not know, and they are dropped. An unknown `schemaVersion` is
8
+ * refused, and an item of a kind this CLI does not know is skipped, so a newer
9
+ * source never breaks an older CLI.
10
+ *
11
+ * @position packages/cli/authoring/discover — parse + validate, no I/O.
12
+ */
13
+
14
+ import {z} from 'zod';
15
+
16
+ /** Item kinds a catalog may list, in display order. */
17
+ export const DISCOVER_KINDS = /** @type {const} */ ([
18
+ 'component',
19
+ 'template',
20
+ 'doc',
21
+ 'theme',
22
+ 'codemod',
23
+ 'agent-doc',
24
+ ]);
25
+
26
+ const text = (/** @type {number} */ max) => z.string().min(1).max(max);
27
+
28
+ const contributionSchema = z.object({
29
+ kind: text(32),
30
+ name: text(512),
31
+ title: z.string().max(512).optional(),
32
+ summary: z.string().max(4096).optional(),
33
+ keywords: z.array(z.string().max(128)).max(64).optional(),
34
+ });
35
+
36
+ const versionSchema = z.object({
37
+ version: text(256),
38
+ publishedAt: z.string().max(64).nullable(),
39
+ prerelease: z.boolean(),
40
+ status: text(64),
41
+ });
42
+
43
+ const packageSchema = z.object({
44
+ package: text(214),
45
+ integration: text(214),
46
+ aliases: z.array(text(214)).max(64),
47
+ description: z.string().max(1024).optional(),
48
+ latest: text(256).nullable(),
49
+ versions: z.array(versionSchema).max(50_000),
50
+ contributions: z.array(contributionSchema).max(50_000),
51
+ });
52
+
53
+ const catalogSchema = z.object({
54
+ schemaVersion: z.literal(1),
55
+ source: z.object({
56
+ name: text(256),
57
+ generatedAt: text(64),
58
+ complete: z.boolean(),
59
+ }),
60
+ packages: z.array(packageSchema).max(20_000),
61
+ });
62
+
63
+ /**
64
+ * Newest first by publish time. A version with no known publish time goes
65
+ * last, and ties fall back to the version number.
66
+ * @param {{version: string, publishedAt: string | null}} a
67
+ * @param {{version: string, publishedAt: string | null}} b
68
+ */
69
+ function newestFirst(a, b) {
70
+ const at = Date.parse(a.publishedAt ?? '');
71
+ const bt = Date.parse(b.publishedAt ?? '');
72
+ if (Number.isNaN(at) !== Number.isNaN(bt)) return Number.isNaN(at) ? 1 : -1;
73
+ if (!Number.isNaN(at) && at !== bt) return bt - at;
74
+ return b.version.localeCompare(a.version, 'en', {numeric: true});
75
+ }
76
+
77
+ /**
78
+ * Check a catalog a discover source returned. Throws an Error naming the first
79
+ * problem. Items of a kind this CLI does not know are dropped, and versions are
80
+ * put newest first whatever order the source used.
81
+ *
82
+ * @param {unknown} value
83
+ * @param {string} [label]
84
+ * @returns {import('./type.js').DiscoverCatalog}
85
+ */
86
+ export function parseDiscoverCatalog(value, label = 'discover source') {
87
+ const version =
88
+ value != null && typeof value === 'object'
89
+ ? /** @type {{schemaVersion?: unknown}} */ (value).schemaVersion
90
+ : undefined;
91
+ if (version !== undefined && version !== 1) {
92
+ throw new Error(
93
+ `${label} returned schemaVersion ${String(version)}; this CLI reads schemaVersion 1`,
94
+ );
95
+ }
96
+ const parsed = catalogSchema.safeParse(value);
97
+ if (!parsed.success) {
98
+ const issue = parsed.error.issues[0];
99
+ const where = issue?.path.length ? ` at ${issue.path.join('.')}` : '';
100
+ throw new Error(
101
+ `${label} returned an invalid catalog${where}: ${issue?.message}`,
102
+ );
103
+ }
104
+ const known = /** @type {readonly string[]} */ (DISCOVER_KINDS);
105
+ return /** @type {import('./type.js').DiscoverCatalog} */ ({
106
+ ...parsed.data,
107
+ packages: parsed.data.packages.map(pkg => ({
108
+ ...pkg,
109
+ versions: [...pkg.versions].sort(newestFirst),
110
+ contributions: pkg.contributions.filter(c => known.includes(c.kind)),
111
+ })),
112
+ });
113
+ }
114
+
115
+ /**
116
+ * Check a discover source itself: an async function, like `debug`, that takes
117
+ * `{signal, package?, version?}` and resolves to a catalog.
118
+ *
119
+ * @param {unknown} value
120
+ * @param {string} label
121
+ * @returns {import('./type.js').DiscoverSource}
122
+ */
123
+ export function parseDiscoverSource(value, label) {
124
+ if (typeof value !== 'function') {
125
+ throw new Error(`${label} must be a function`);
126
+ }
127
+ return /** @type {import('./type.js').DiscoverSource} */ (value);
128
+ }
@@ -0,0 +1,124 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Tests for the discover source and catalog checks.
5
+ */
6
+
7
+ import {describe, it, expect} from 'vitest';
8
+ import {
9
+ DISCOVER_KINDS,
10
+ parseDiscoverCatalog,
11
+ parseDiscoverSource,
12
+ } from './parse.mjs';
13
+
14
+ function catalog(overrides = {}) {
15
+ return {
16
+ schemaVersion: 1,
17
+ source: {
18
+ name: 'Acme catalog',
19
+ generatedAt: '2026-09-30T14:00:00.000Z',
20
+ complete: true,
21
+ },
22
+ packages: [
23
+ {
24
+ package: '@acme/ui',
25
+ integration: 'acme-ui',
26
+ aliases: [],
27
+ latest: '2.0.0',
28
+ versions: [
29
+ {
30
+ version: '2.0.0',
31
+ publishedAt: '2026-09-29T00:00:00.000Z',
32
+ prerelease: false,
33
+ status: 'ok',
34
+ },
35
+ ],
36
+ contributions: [{kind: 'component', name: 'Button'}],
37
+ },
38
+ ],
39
+ ...overrides,
40
+ };
41
+ }
42
+
43
+ describe('parseDiscoverCatalog', () => {
44
+ it('accepts a catalog', () => {
45
+ expect(parseDiscoverCatalog(catalog())).toEqual(catalog());
46
+ });
47
+
48
+ it('drops fields it does not know, so a newer source still works', () => {
49
+ const parsed = parseDiscoverCatalog({...catalog(), cursor: 'next'});
50
+ expect(parsed).not.toHaveProperty('cursor');
51
+ });
52
+
53
+ it('drops items of a kind it does not know', () => {
54
+ const value = catalog();
55
+ value.packages[0].contributions.push({kind: 'widget', name: 'Spinner'});
56
+ expect(parseDiscoverCatalog(value).packages[0].contributions).toEqual([
57
+ {kind: 'component', name: 'Button'},
58
+ ]);
59
+ });
60
+
61
+ it('puts versions newest first whatever order the source used', () => {
62
+ const value = catalog();
63
+ value.packages[0].versions = [
64
+ {
65
+ version: '1.0.0',
66
+ publishedAt: '2026-01-05T00:00:00.000Z',
67
+ prerelease: false,
68
+ status: 'ok',
69
+ },
70
+ {version: '1.5.0', publishedAt: null, prerelease: false, status: 'ok'},
71
+ {
72
+ version: '2.0.0',
73
+ publishedAt: '2026-09-29T00:00:00.000Z',
74
+ prerelease: false,
75
+ status: 'ok',
76
+ },
77
+ {
78
+ version: '2.0.0-rc.1',
79
+ publishedAt: '2026-09-01T00:00:00.000Z',
80
+ prerelease: true,
81
+ status: 'ok',
82
+ },
83
+ ];
84
+ expect(
85
+ parseDiscoverCatalog(value).packages[0].versions.map(v => v.version),
86
+ ).toEqual(['2.0.0', '2.0.0-rc.1', '1.0.0', '1.5.0']);
87
+ });
88
+
89
+ it('refuses a schemaVersion it does not read', () => {
90
+ expect(() => parseDiscoverCatalog(catalog({schemaVersion: 2}))).toThrow(
91
+ 'this CLI reads schemaVersion 1',
92
+ );
93
+ });
94
+
95
+ it('names the first problem and where it is', () => {
96
+ expect(() =>
97
+ parseDiscoverCatalog(catalog({packages: [{package: ''}]}), 'the source'),
98
+ ).toThrow(/^the source returned an invalid catalog at packages\.0\./);
99
+ });
100
+
101
+ it('lists the kinds in display order', () => {
102
+ expect(DISCOVER_KINDS).toEqual([
103
+ 'component',
104
+ 'template',
105
+ 'doc',
106
+ 'theme',
107
+ 'codemod',
108
+ 'agent-doc',
109
+ ]);
110
+ });
111
+ });
112
+
113
+ describe('parseDiscoverSource', () => {
114
+ it('accepts a function', () => {
115
+ const source = async () => catalog();
116
+ expect(parseDiscoverSource(source, 'discover')).toBe(source);
117
+ });
118
+
119
+ it('refuses anything else, such as a URL', () => {
120
+ expect(() =>
121
+ parseDiscoverSource('https://example.com/catalog.json', 'discover'),
122
+ ).toThrow('discover must be a function');
123
+ });
124
+ });
@@ -0,0 +1,87 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * Public type surface for discover sources.
5
+ *
6
+ * A discover source tells `astryx discover` which integrations exist beyond the
7
+ * ones a project already has. A project sets one as `discover` in
8
+ * `astryx.config`; an integration exports one as a `discover` NAMED export from
9
+ * its manifest. Discover calls every source, checks each answer, keeps a saved
10
+ * copy of the last good one, and never installs, enables, or runs anything a
11
+ * catalog names.
12
+ */
13
+
14
+ /** Kinds of item a package can add. */
15
+ export type DiscoverKind =
16
+ 'component' | 'template' | 'doc' | 'theme' | 'codemod' | 'agent-doc';
17
+
18
+ /** One item a package version adds. */
19
+ export interface DiscoverContribution {
20
+ kind: DiscoverKind;
21
+ /**
22
+ * The name the CLI uses for it: a component name, template id, doc topic,
23
+ * theme slug, or codemod id.
24
+ */
25
+ name: string;
26
+ title?: string;
27
+ summary?: string;
28
+ keywords?: string[];
29
+ }
30
+
31
+ /** One published version of a package. */
32
+ export interface DiscoverVersion {
33
+ version: string;
34
+ /** ISO 8601 publish time, or null when the source does not know it. */
35
+ publishedAt: string | null;
36
+ prerelease: boolean;
37
+ /** `ok`, or why the source could not read this version. */
38
+ status: string;
39
+ }
40
+
41
+ /** One npm package a source knows about. */
42
+ export interface DiscoverPackage {
43
+ package: string;
44
+ /** Shared by every npm name that publishes the same integration. */
45
+ integration: string;
46
+ /** The integration's other npm names. Discover never offers one the project has. */
47
+ aliases: string[];
48
+ description?: string;
49
+ /** The latest release, or null when the package has only prereleases. */
50
+ latest: string | null;
51
+ /** Every version, newest first. */
52
+ versions: DiscoverVersion[];
53
+ /** What the requested version adds, or the latest when none was requested. */
54
+ contributions: DiscoverContribution[];
55
+ }
56
+
57
+ /** What a discover source returns. */
58
+ export interface DiscoverCatalog {
59
+ schemaVersion: 1;
60
+ source: {
61
+ /** Shown to people, for example "Acme catalog". */
62
+ name: string;
63
+ /** ISO 8601 time the source's data was produced. */
64
+ generatedAt: string;
65
+ /** False when the source knows its list is partial. */
66
+ complete: boolean;
67
+ };
68
+ packages: DiscoverPackage[];
69
+ }
70
+
71
+ /** One call to a discover source. */
72
+ export interface DiscoverSourceContext {
73
+ /** Aborted when the source exceeds its 30-second budget. */
74
+ readonly signal: AbortSignal;
75
+ /** Asks for one package: every version, and `version`'s contributions. */
76
+ readonly package?: string;
77
+ /** With `package`: the version whose contributions to return. Defaults to the latest. */
78
+ readonly version?: string;
79
+ }
80
+
81
+ /**
82
+ * A discover source: an async function, like `debug`. Set it as `discover` in
83
+ * astryx.config, or export it as `discover` from an integration manifest.
84
+ */
85
+ export type DiscoverSource = (
86
+ context: DiscoverSourceContext,
87
+ ) => Promise<DiscoverCatalog>;
@@ -93,6 +93,52 @@ export const GraphContentBlockSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
93
93
  full: "full";
94
94
  }>>;
95
95
  }, z.core.$strict>], "type">;
96
+ /**
97
+ * A topic section's blocks: the stable union, plus a reference block, which a
98
+ * read inlines as the doc it includes.
99
+ */
100
+ export const SectionContentBlockSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
101
+ type: z.ZodLiteral<"prose">;
102
+ text: z.ZodString;
103
+ }, z.core.$strict>, z.ZodObject<{
104
+ type: z.ZodLiteral<"heading">;
105
+ level: z.ZodUnion<readonly [z.ZodLiteral<3>, z.ZodLiteral<4>, z.ZodLiteral<5>, z.ZodLiteral<6>]>;
106
+ text: z.ZodString;
107
+ }, z.core.$strict>, z.ZodObject<{
108
+ type: z.ZodLiteral<"code">;
109
+ lang: z.ZodString;
110
+ code: z.ZodString;
111
+ label: z.ZodOptional<z.ZodString>;
112
+ }, z.core.$strict>, z.ZodObject<{
113
+ type: z.ZodLiteral<"table">;
114
+ headers: z.ZodArray<z.ZodString>;
115
+ rows: z.ZodArray<z.ZodArray<z.ZodString>>;
116
+ }, z.core.$strict>, z.ZodObject<{
117
+ type: z.ZodLiteral<"list">;
118
+ style: z.ZodEnum<{
119
+ ordered: "ordered";
120
+ unordered: "unordered";
121
+ do: "do";
122
+ dont: "dont";
123
+ }>;
124
+ items: z.ZodArray<z.ZodString>;
125
+ }, z.core.$strict>, z.ZodObject<{
126
+ type: z.ZodLiteral<"token-ref">;
127
+ topic: z.ZodString;
128
+ section: z.ZodString;
129
+ }, z.core.$strict>, z.ZodObject<{
130
+ type: z.ZodLiteral<"reference">;
131
+ target: z.ZodString;
132
+ projection: z.ZodOptional<z.ZodObject<{
133
+ fields: z.ZodOptional<z.ZodArray<z.ZodString>>;
134
+ sections: z.ZodOptional<z.ZodArray<z.ZodString>>;
135
+ }, z.core.$strict>>;
136
+ presentation: z.ZodOptional<z.ZodEnum<{
137
+ compact: "compact";
138
+ summary: "summary";
139
+ full: "full";
140
+ }>>;
141
+ }, z.core.$strict>], "type">;
96
142
  /** Namespace content accepts both stable reference blocks and graph-only blocks. */
97
143
  export const NamespaceContentBlockSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
98
144
  type: z.ZodLiteral<"prose">;
@@ -303,6 +349,18 @@ export const GenericDocKindSchema: z.ZodObject<{
303
349
  type: z.ZodLiteral<"token-ref">;
304
350
  topic: z.ZodString;
305
351
  section: z.ZodString;
352
+ }, z.core.$strict>, z.ZodObject<{
353
+ type: z.ZodLiteral<"reference">;
354
+ target: z.ZodString;
355
+ projection: z.ZodOptional<z.ZodObject<{
356
+ fields: z.ZodOptional<z.ZodArray<z.ZodString>>;
357
+ sections: z.ZodOptional<z.ZodArray<z.ZodString>>;
358
+ }, z.core.$strict>>;
359
+ presentation: z.ZodOptional<z.ZodEnum<{
360
+ compact: "compact";
361
+ summary: "summary";
362
+ full: "full";
363
+ }>>;
306
364
  }, z.core.$strict>], "type">>;
307
365
  previewType: z.ZodOptional<z.ZodEnum<{
308
366
  swatch: "swatch";
@@ -840,6 +898,18 @@ export const LegacyDocSchema: z.ZodUnion<readonly [z.ZodObject<{
840
898
  type: z.ZodLiteral<"token-ref">;
841
899
  topic: z.ZodString;
842
900
  section: z.ZodString;
901
+ }, z.core.$strict>, z.ZodObject<{
902
+ type: z.ZodLiteral<"reference">;
903
+ target: z.ZodString;
904
+ projection: z.ZodOptional<z.ZodObject<{
905
+ fields: z.ZodOptional<z.ZodArray<z.ZodString>>;
906
+ sections: z.ZodOptional<z.ZodArray<z.ZodString>>;
907
+ }, z.core.$strict>>;
908
+ presentation: z.ZodOptional<z.ZodEnum<{
909
+ compact: "compact";
910
+ summary: "summary";
911
+ full: "full";
912
+ }>>;
843
913
  }, z.core.$strict>], "type">>;
844
914
  previewType: z.ZodOptional<z.ZodEnum<{
845
915
  swatch: "swatch";
@@ -862,6 +932,7 @@ export type AuthoredDocKind = import("./base/type.js").AuthoredDocKind;
862
932
  export type NamespaceDoc = import("./namespace/type.js").NamespaceDoc;
863
933
  export type ReferenceContentBlock = import("./reference/type.js").ReferenceContentBlock;
864
934
  export type GraphContentBlock = import("./reference/type.js").GraphContentBlock;
935
+ export type ReferenceSection = import("./reference/type.js").ReferenceSection;
865
936
  export type ReferenceDoc = import("./reference/type.js").ReferenceDoc;
866
937
  export type SingleComponentDoc = import("./component/type.js").SingleComponentDoc;
867
938
  export type ComponentPropDoc = import("./base/type.js").ComponentPropDoc;
@@ -874,6 +945,7 @@ export type _AuthoredDocKindDriftLock = import("../_shared/contract.js").Expect<
874
945
  export type _AuthoredDocGraphDriftLock = import("../_shared/contract.js").Expect<import("../_shared/contract.js").MutuallyAssignable<z.infer<typeof _AuthoredDocGraphSchema>, AuthoredDocGraphFieldsType>>;
875
946
  export type _ReferenceContentBlockDriftLock = import("../_shared/contract.js").Expect<import("../_shared/contract.js").Equal<z.infer<typeof ReferenceContentBlockSchema>, ReferenceContentBlock>>;
876
947
  export type _GraphContentBlockDriftLock = import("../_shared/contract.js").Expect<import("../_shared/contract.js").Equal<z.infer<typeof GraphContentBlockSchema>, GraphContentBlock>>;
948
+ export type _SectionContentBlockDriftLock = import("../_shared/contract.js").Expect<import("../_shared/contract.js").Equal<z.infer<typeof SectionContentBlockSchema>, ReferenceSection["content"][number]>>;
877
949
  /**
878
950
  * A stamped component doc as it loads. The loader accepts what the unstamped
879
951
  * format always accepted, so stamping an existing doc never breaks it:
@@ -16,6 +16,7 @@ import {z} from 'zod';
16
16
  /** @typedef {import('./namespace/type.js').NamespaceDoc} NamespaceDoc */
17
17
  /** @typedef {import('./reference/type.js').ReferenceContentBlock} ReferenceContentBlock */
18
18
  /** @typedef {import('./reference/type.js').GraphContentBlock} GraphContentBlock */
19
+ /** @typedef {import('./reference/type.js').ReferenceSection} ReferenceSection */
19
20
  /** @typedef {import('./reference/type.js').ReferenceDoc} ReferenceDoc */
20
21
  /** @typedef {import('./component/type.js').SingleComponentDoc} SingleComponentDoc */
21
22
  /** @typedef {import('./base/type.js').ComponentPropDoc} ComponentPropDoc */
@@ -179,6 +180,20 @@ export const GraphContentBlockSchema = z.discriminatedUnion('type', [
179
180
  ReferenceBlockSchema,
180
181
  ]);
181
182
 
183
+ /**
184
+ * A topic section's blocks: the stable union, plus a reference block, which a
185
+ * read inlines as the doc it includes.
186
+ */
187
+ export const SectionContentBlockSchema = z.discriminatedUnion('type', [
188
+ ProseBlockSchema,
189
+ HeadingBlockSchema,
190
+ CodeBlockSchema,
191
+ TableBlockSchema,
192
+ ListBlockSchema,
193
+ TokenReferenceBlockSchema,
194
+ ReferenceBlockSchema,
195
+ ]);
196
+
182
197
  /** Namespace content accepts both stable reference blocks and graph-only blocks. */
183
198
  export const NamespaceContentBlockSchema = z.discriminatedUnion('type', [
184
199
  ProseBlockSchema,
@@ -210,12 +225,21 @@ export const NamespaceContentBlockSchema = z.discriminatedUnion('type', [
210
225
  * >} _GraphContentBlockDriftLock
211
226
  */
212
227
 
228
+ /**
229
+ * @typedef {import('../_shared/contract.js').Expect<
230
+ * import('../_shared/contract.js').Equal<
231
+ * z.infer<typeof SectionContentBlockSchema>,
232
+ * ReferenceSection['content'][number]
233
+ * >
234
+ * >} _SectionContentBlockDriftLock
235
+ */
236
+
213
237
  const ReferenceSectionSchema = z
214
238
  .object({
215
239
  id: nonEmptyString.optional(),
216
240
  title: nonEmptyString,
217
241
  category: z.string().optional(),
218
- content: z.array(ReferenceContentBlockSchema),
242
+ content: z.array(SectionContentBlockSchema),
219
243
  previewType: z
220
244
  .enum([
221
245
  'swatch',
@@ -151,7 +151,7 @@ export const doc = {
151
151
  name: 'subcommands',
152
152
  type: 'string[]',
153
153
  description:
154
- 'Subcommand names (for command groups like `theme` / `layout`).',
154
+ 'Subcommand names (for command groups like `theme`).',
155
155
  },
156
156
  {
157
157
  name: 'examples',
@@ -75,7 +75,7 @@ export interface CommandDoc extends AuthoredDocGraphFields {
75
75
  args?: CommandArgDoc[];
76
76
  /** Flags/options. */
77
77
  options?: CommandOptionDoc[];
78
- /** Subcommand names (for command groups like `theme` / `layout`). */
78
+ /** Subcommand names (for command groups like `theme`). */
79
79
  subcommands?: string[];
80
80
  /** Terminal examples. */
81
81
  examples?: CommandExampleDoc[];