@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.
- package/CHANGELOG.md +194 -0
- package/README.md +64 -66
- package/api/component/_adapter.d.mts +25 -0
- package/api/component/_adapter.mjs +59 -5
- package/api/component/component.d.mts +6 -3
- package/api/component/component.doc.mjs +23 -10
- package/api/component/component.mjs +249 -9
- package/api/component/component.type.d.mts +25 -0
- package/api/component/component.type.mjs +44 -0
- package/api/discover/_adapter.d.mts +114 -6
- package/api/discover/_adapter.mjs +372 -17
- package/api/discover/_adapter.test.mjs +215 -0
- package/api/discover/_catalog-view.d.mts +115 -0
- package/api/discover/_catalog-view.mjs +203 -0
- package/api/discover/_catalog-view.test.mjs +128 -0
- package/api/discover/detail/detail.d.mts +18 -6
- package/api/discover/detail/detail.mjs +67 -13
- package/api/discover/detail/detail.test.mjs +85 -0
- package/api/discover/detail/item/item.d.mts +26 -0
- package/api/discover/detail/item/item.mjs +78 -0
- package/api/discover/detail/item/item.test.mjs +73 -0
- package/api/discover/discover.d.mts +3 -9
- package/api/discover/discover.doc.mjs +61 -18
- package/api/discover/discover.mjs +220 -36
- package/api/discover/discover.test.mjs +11 -2
- package/api/discover/discover.type.d.mts +147 -8
- package/api/discover/discover.type.mjs +102 -12
- package/api/discover/list/list.d.mts +20 -6
- package/api/discover/list/list.mjs +45 -12
- package/api/discover/list/list.test.mjs +46 -0
- package/api/discover/search/search.d.mts +18 -16
- package/api/discover/search/search.mjs +102 -56
- package/api/discover/search/search.test.mjs +144 -10
- package/api/docs/_adapter.d.mts +49 -7
- package/api/docs/_adapter.mjs +284 -33
- package/api/docs/docs.doc.mjs +4 -3
- package/api/docs/docs.test.mjs +2 -0
- package/api/docs/docs.type.d.mts +21 -5
- package/api/docs/docs.type.mjs +21 -5
- package/api/docs/integration-tree.test.mjs +9 -1
- package/api/docs/reference-blocks.test.mjs +406 -0
- package/api/doctor/doctor.d.mts +8 -3
- package/api/doctor/doctor.mjs +95 -10
- package/api/doctor/doctor.test.mjs +122 -10
- package/api/index.d.mts +1 -2
- package/api/index.mjs +4 -4
- package/api/integration/add-helpers.d.mts +5 -2
- package/api/integration/add-helpers.mjs +36 -9
- package/api/integration/authoring-checks.mjs +14 -1
- package/api/integration/pack-check.lifecycle-output.test.mjs +105 -0
- package/api/integration/pack-check.mjs +28 -3
- package/api/json/index.ts +0 -1
- package/api/search/search.test.mjs +18 -0
- package/api/template/table-floating-bulk-actions.test.mjs +66 -0
- package/api/template/template-integration.test.mjs +1 -65
- package/api/template/template.mjs +1 -1
- package/api/theme/add/add.mjs +17 -25
- package/api/theme/add/add.rollback.test.mjs +158 -0
- package/api/theme/add/add.staging.test.mjs +40 -23
- package/api/theme/build/build.family.test.mjs +7 -12
- package/api/theme/build/build.mjs +8 -18
- package/api/theme/build/build.rollback.test.mjs +148 -0
- package/api/upgrade/run/files-changed.test.mjs +111 -0
- package/api/upgrade/run/run.mjs +6 -4
- package/api/upgrade/upgrade.type.mjs +2 -2
- package/assets/codemods/__tests__/registry.test.mjs +1 -0
- package/assets/codemods/__tests__/runner.test.mjs +3 -1
- package/assets/codemods/file-count.test.mjs +163 -0
- package/assets/codemods/integration-runner.mjs +3 -3
- package/assets/codemods/registry.mjs +1 -0
- package/assets/codemods/runner.mjs +5 -4
- package/assets/codemods/transforms/next/index.mjs +1 -19
- package/assets/codemods/transforms/v0.6.4/index.mjs +31 -0
- package/assets/docs/internationalization.doc.mjs +7 -5
- package/assets/docs/styling-libraries.doc.mjs +1 -1
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/tree/component-lookups.doc.mjs +149 -0
- package/assets/docs/tree/integrations.doc.mjs +20 -1
- package/assets/templates/blocks/components/CheckboxList/CheckboxListSelectAllPattern.doc.mjs +1 -1
- package/assets/templates/blocks/components/CheckboxList/CheckboxListSelectAllPattern.tsx +1 -3
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider01ShippedLocale.tsx +1 -1
- package/assets/templates/blocks/components/Table/TableBulkActionsTable.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/TableBulkActionsTable.tsx +71 -0
- package/assets/templates/blocks/components/Table/TableFloatingBulkActionsTable.doc.mjs +19 -0
- package/assets/templates/blocks/components/Table/TableFloatingBulkActionsTable.tsx +139 -0
- package/authoring/config/config.doc.mjs +9 -1
- package/authoring/config/parse.d.mts +2 -0
- package/authoring/config/parse.mjs +19 -0
- package/authoring/config/parse.test.mjs +8 -0
- package/authoring/config/type.ts +13 -2
- package/authoring/discover/discover.doc.d.mts +13 -0
- package/authoring/discover/discover.doc.mjs +138 -0
- package/authoring/discover/parse.d.mts +24 -0
- package/authoring/discover/parse.mjs +128 -0
- package/authoring/discover/parse.test.mjs +124 -0
- package/authoring/discover/type.ts +87 -0
- package/authoring/doctypes/_schema.d.mts +72 -0
- package/authoring/doctypes/_schema.mjs +25 -1
- package/authoring/doctypes/command/command.doc.mjs +1 -1
- package/authoring/doctypes/command/type.ts +1 -1
- package/authoring/doctypes/load-contract.test.mjs +25 -0
- package/authoring/doctypes/reference/reference.doc.mjs +31 -4
- package/authoring/doctypes/reference/type.ts +20 -5
- package/authoring/index.d.mts +1 -0
- package/authoring/index.d.ts +10 -0
- package/authoring/index.mjs +1 -0
- package/clients/cli/command-result-coverage.test.mjs +7 -7
- package/clients/cli/commands/component/index.mjs +152 -55
- package/clients/cli/commands/component-batch.test.mjs +341 -0
- package/clients/cli/commands/component-ownership.test.mjs +89 -0
- package/clients/cli/commands/component.doc.mjs +23 -6
- package/clients/cli/commands/debug-result-summary.test.mjs +2 -2
- package/clients/cli/commands/discover.doc.mjs +53 -9
- package/clients/cli/commands/discover.mjs +393 -118
- package/clients/cli/commands/discover.sources.test.mjs +267 -0
- package/clients/cli/commands/docs.mjs +2 -2
- package/clients/cli/commands/docs.test.mjs +29 -0
- package/clients/cli/commands/doctor-integration-docs.doc.mjs +1 -1
- package/clients/cli/commands/text-json-parity.test.mjs +0 -17
- package/clients/cli/index.mjs +0 -4
- package/clients/cli/lib/exit-codes.test.mjs +1 -8
- package/clients/cli/lib/json-shim.mjs +24 -14
- package/clients/cli/lib/json-shim.test.mjs +6 -20
- package/clients/cli/lib/manifest.mjs +3 -8
- package/clients/cli/lib/manifest.test.mjs +5 -2
- package/clients/cli/lib/parse-error-format.test.mjs +81 -0
- package/foundation/discovery/authoring-self-docs.d.mts +12 -0
- package/foundation/discovery/authoring-self-docs.mjs +21 -8
- package/foundation/discovery/authoring-self-docs.test.mjs +7 -2
- package/foundation/discovery/docs-discovery.d.mts +4 -1
- package/foundation/discovery/docs-discovery.mjs +40 -6
- package/foundation/discovery/docs-discovery.test.mjs +40 -0
- package/foundation/discovery/template-adapter.mjs +1 -1
- package/foundation/doc-compiler/doc-loads.test.mjs +0 -12
- package/foundation/doc-compiler/lenses.d.mts +5 -3
- package/foundation/doc-compiler/lenses.mjs +48 -3
- package/foundation/doc-compiler/links.d.mts +30 -3
- package/foundation/doc-compiler/links.mjs +46 -5
- package/foundation/doc-compiler/links.test.mjs +53 -0
- package/foundation/doc-compiler/tree.test.mjs +9 -1
- package/foundation/integrations/cli-requirement.test.mjs +17 -42
- package/foundation/integrations/integrations.d.mts +14 -1
- package/foundation/integrations/integrations.mjs +41 -1
- package/foundation/integrations/integrations.test.mjs +31 -0
- package/foundation/response/batch.type.d.mts +33 -0
- package/foundation/response/batch.type.mjs +34 -0
- package/foundation/response/response-types.doc.mjs +15 -21
- package/foundation/response/response-types.doc.test.mjs +23 -0
- package/foundation/xle/browser.d.mts +3 -3
- package/foundation/xle/browser.mjs +3 -3
- package/foundation/xle/expand.mjs +2 -2
- package/foundation/xle/parse.mjs +1 -1
- package/foundation/xle/print.mjs +2 -2
- package/foundation/xle/splice.mjs +1 -1
- package/package.json +9 -9
- package/api/layout/_adapter.d.mts +0 -34
- package/api/layout/_adapter.mjs +0 -148
- package/api/layout/check/check.d.mts +0 -16
- package/api/layout/check/check.mjs +0 -40
- package/api/layout/expand/expand.d.mts +0 -22
- package/api/layout/expand/expand.mjs +0 -155
- package/api/layout/expand/expand.path-safety.test.mjs +0 -53
- package/api/layout/grammar/grammar.d.mts +0 -13
- package/api/layout/grammar/grammar.mjs +0 -87
- package/api/layout/layout.d.mts +0 -6
- package/api/layout/layout.mjs +0 -17
- package/api/layout/layout.test.mjs +0 -297
- package/api/layout/layout.type.d.mts +0 -89
- package/api/layout/layout.type.mjs +0 -103
- package/api/layout/layoutCheck.doc.d.mts +0 -11
- package/api/layout/layoutCheck.doc.mjs +0 -85
- package/api/layout/layoutExpand.doc.d.mts +0 -11
- package/api/layout/layoutExpand.doc.mjs +0 -107
- package/api/layout/layoutGrammar.doc.d.mts +0 -11
- package/api/layout/layoutGrammar.doc.mjs +0 -57
- package/clients/cli/commands/layout-check.doc.mjs +0 -65
- package/clients/cli/commands/layout-expand.doc.mjs +0 -83
- package/clients/cli/commands/layout-grammar.doc.mjs +0 -30
- package/clients/cli/commands/layout.doc.mjs +0 -34
- package/clients/cli/commands/layout.error-codes.test.mjs +0 -66
- package/clients/cli/commands/layout.exit-parity.test.mjs +0 -41
- package/clients/cli/commands/layout.mjs +0 -275
- package/clients/cli/commands/layout.path-help.test.mjs +0 -33
- package/clients/cli/commands/layout.stdin-cap.test.mjs +0 -47
- package/clients/cli/commands/layout.text-fields.test.mjs +0 -39
- /package/assets/codemods/transforms/{next → v0.6.4}/__tests__/migrate-native-picker-to-presentation.test.mjs +0 -0
- /package/assets/codemods/transforms/{next → v0.6.4}/__tests__/migrate-theme-catalog-to-descriptors.test.mjs +0 -0
- /package/assets/codemods/transforms/{next → v0.6.4}/migrate-native-picker-to-presentation.mjs +0 -0
- /package/assets/codemods/transforms/{next → v0.6.4}/migrate-theme-catalog-to-descriptors.mjs +0 -0
|
@@ -3,55 +3,193 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* @file Programmatic API for the discover command — dispatcher + barrel.
|
|
5
5
|
*
|
|
6
|
-
* `discover()`
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* owns each response shape:
|
|
6
|
+
* `discover()` browses the integrations a project has and, through discover
|
|
7
|
+
* sources, the ones it could add. It only reads: the package manager installs.
|
|
8
|
+
* Its job is to resolve the project and its sources (via ./_adapter) and route
|
|
9
|
+
* to the leaf that owns each response shape:
|
|
10
10
|
*
|
|
11
|
-
* discover
|
|
12
|
-
* discover
|
|
13
|
-
* discover
|
|
14
|
-
* discover
|
|
11
|
+
* discover -> ./list/list.mjs discover.list
|
|
12
|
+
* discover <package>[@<version>] -> ./detail/detail.mjs discover.detail
|
|
13
|
+
* discover <package>/<Component> -> ./detail/doc/doc.mjs discover.detail.doc
|
|
14
|
+
* discover <package>/<item> -> ./detail/item/item.mjs discover.item
|
|
15
|
+
* discover <words> -> ./search/search.mjs discover.search (always a list)
|
|
15
16
|
*
|
|
16
|
-
*
|
|
17
|
+
* Source results are additive: they ride in `meta.available`/`meta.sources`,
|
|
18
|
+
* in extra fields, or as extra search matches, so every existing field keeps
|
|
19
|
+
* its meaning.
|
|
20
|
+
*
|
|
21
|
+
* @position api/discover — thin router over ./_adapter, ./_catalog-view, and
|
|
22
|
+
* the discover leaves.
|
|
17
23
|
*/
|
|
18
24
|
|
|
19
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
addCommand,
|
|
27
|
+
callSources,
|
|
28
|
+
declaredDependencies,
|
|
29
|
+
describeInstalled,
|
|
30
|
+
discoverPackages,
|
|
31
|
+
findComponent,
|
|
32
|
+
hasSources,
|
|
33
|
+
} from './_adapter.mjs';
|
|
34
|
+
import {
|
|
35
|
+
availableEntries,
|
|
36
|
+
catalogState,
|
|
37
|
+
searchItems,
|
|
38
|
+
withLatest,
|
|
39
|
+
} from './_catalog-view.mjs';
|
|
20
40
|
import {list} from './list/list.mjs';
|
|
21
41
|
import {detail} from './detail/detail.mjs';
|
|
22
|
-
import {doc} from './detail/doc/doc.mjs';
|
|
42
|
+
import {doc, docFromResult} from './detail/doc/doc.mjs';
|
|
43
|
+
import {item} from './detail/item/item.mjs';
|
|
23
44
|
import {search} from './search/search.mjs';
|
|
24
45
|
import {AstryxError} from '../error.mjs';
|
|
25
46
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
47
|
+
import {levenshteinDistance} from '../../foundation/text/string-utils.mjs';
|
|
48
|
+
import {DISCOVER_KINDS} from '../../authoring/discover/parse.mjs';
|
|
49
|
+
|
|
50
|
+
const DEFAULT_LIMIT = 20;
|
|
51
|
+
|
|
52
|
+
/** @type {import('./_adapter.mjs').CatalogResult} */
|
|
53
|
+
const NO_CATALOG = {sources: [], packages: []};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Split a package-shaped query: `name`, `name@version`, or `name/item`, with an
|
|
57
|
+
* optional `@scope/` prefix on the name.
|
|
58
|
+
* @param {string} query
|
|
59
|
+
* @returns {{scoped: boolean, name: string, version?: string, item?: string}}
|
|
60
|
+
*/
|
|
61
|
+
function splitTarget(query) {
|
|
62
|
+
const scoped = query.startsWith('@');
|
|
63
|
+
const firstSlash = query.indexOf('/');
|
|
64
|
+
let head = query;
|
|
65
|
+
/** @type {string | undefined} */
|
|
66
|
+
let rest;
|
|
67
|
+
const split = scoped
|
|
68
|
+
? firstSlash < 0
|
|
69
|
+
? -1
|
|
70
|
+
: query.indexOf('/', firstSlash + 1)
|
|
71
|
+
: firstSlash;
|
|
72
|
+
if (split > 0) {
|
|
73
|
+
head = query.slice(0, split);
|
|
74
|
+
rest = query.slice(split + 1) || undefined;
|
|
75
|
+
}
|
|
76
|
+
const at = head.indexOf('@', 1);
|
|
77
|
+
return {
|
|
78
|
+
scoped,
|
|
79
|
+
name: at > 0 ? head.slice(0, at) : head,
|
|
80
|
+
...(at > 0 && head.slice(at + 1) ? {version: head.slice(at + 1)} : {}),
|
|
81
|
+
...(rest ? {item: rest} : {}),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @param {{type?: unknown, installed?: boolean, available?: boolean, limit?: unknown}} options
|
|
87
|
+
*/
|
|
88
|
+
function checkOptions({type, installed, available, limit}) {
|
|
89
|
+
if (
|
|
90
|
+
type != null &&
|
|
91
|
+
!(/** @type {readonly unknown[]} */ (DISCOVER_KINDS).includes(type))
|
|
92
|
+
) {
|
|
93
|
+
throw new AstryxError(
|
|
94
|
+
`Unknown --type "${String(type)}"`,
|
|
95
|
+
DISCOVER_KINDS.map(kind => ({name: kind, reason: 'item kind'})),
|
|
96
|
+
ERROR_CODES.ERR_INVALID_OPTION,
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
if (installed && available) {
|
|
100
|
+
throw new AstryxError(
|
|
101
|
+
'--installed and --available cannot be used together',
|
|
102
|
+
undefined,
|
|
103
|
+
ERROR_CODES.ERR_INVALID_OPTION,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
if (
|
|
107
|
+
limit != null &&
|
|
108
|
+
!(typeof limit === 'number' && Number.isInteger(limit) && limit > 0)
|
|
109
|
+
) {
|
|
110
|
+
throw new AstryxError(
|
|
111
|
+
`--limit must be a positive integer, not "${String(limit)}"`,
|
|
112
|
+
undefined,
|
|
113
|
+
ERROR_CODES.ERR_INVALID_OPTION,
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Items a source lists for a package that look like the one asked for: names
|
|
120
|
+
* that contain it, else the closest few by spelling.
|
|
121
|
+
* @param {import('../../authoring/discover/type.js').DiscoverPackage} entry
|
|
122
|
+
* @param {string} wanted
|
|
123
|
+
* @returns {Array<{name: string, reason: string}>}
|
|
124
|
+
*/
|
|
125
|
+
function similarItems(entry, wanted) {
|
|
126
|
+
const lower = wanted.toLowerCase();
|
|
127
|
+
const names = [...new Set(entry.contributions.map(c => c.name))];
|
|
128
|
+
const hits = names.filter(name => name.toLowerCase().includes(lower));
|
|
129
|
+
const picked =
|
|
130
|
+
hits.length > 0
|
|
131
|
+
? hits.slice(0, 5)
|
|
132
|
+
: names
|
|
133
|
+
.map(name => ({
|
|
134
|
+
name,
|
|
135
|
+
distance: levenshteinDistance(lower, name.toLowerCase()),
|
|
136
|
+
}))
|
|
137
|
+
.filter(m => m.distance <= 3)
|
|
138
|
+
.sort((a, b) => a.distance - b.distance)
|
|
139
|
+
.slice(0, 5)
|
|
140
|
+
.map(m => m.name);
|
|
141
|
+
return picked.map(name => ({
|
|
142
|
+
name: `${entry.package}/${name}`,
|
|
143
|
+
reason: 'similar name',
|
|
144
|
+
}));
|
|
145
|
+
}
|
|
26
146
|
|
|
27
147
|
/**
|
|
28
148
|
* @param {string} [query]
|
|
29
|
-
* @param {
|
|
30
|
-
* @param {boolean} [options.components]
|
|
31
|
-
* @param {string} [options.lang]
|
|
32
|
-
* @param {boolean} [options.zh]
|
|
149
|
+
* @param {import('./discover.type.mjs').DiscoverOptions} [options]
|
|
33
150
|
* @returns {Promise<
|
|
34
151
|
* import('./discover.type.mjs').DiscoverListResponse |
|
|
35
152
|
* import('./discover.type.mjs').DiscoverDetailResponse |
|
|
36
153
|
* import('./discover.type.mjs').DiscoverDetailDocResponse |
|
|
154
|
+
* import('./discover.type.mjs').DiscoverItemResponse |
|
|
37
155
|
* import('./discover.type.mjs').DiscoverSearchResponse
|
|
38
156
|
* >}
|
|
39
157
|
*/
|
|
40
158
|
export async function discover(query, options = {}) {
|
|
41
|
-
const {lang = null, zh = false} = options;
|
|
42
|
-
|
|
159
|
+
const {lang = null, zh = false, type, limit} = options;
|
|
160
|
+
checkOptions(options);
|
|
161
|
+
const only = options.installed
|
|
162
|
+
? /** @type {const} */ ('installed')
|
|
163
|
+
: options.available
|
|
164
|
+
? /** @type {const} */ ('available')
|
|
165
|
+
: undefined;
|
|
166
|
+
|
|
167
|
+
const {packages: scanned, configured, project} = await discoverPackages();
|
|
168
|
+
const withSources = hasSources(project);
|
|
169
|
+
const packages = await describeInstalled(project, scanned);
|
|
170
|
+
const declared = declaredDependencies(project);
|
|
171
|
+
const add = addCommand(project);
|
|
43
172
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (packages.length === 0) return list(packages, {configured});
|
|
173
|
+
/** @param {{package?: string, version?: string}} [request] */
|
|
174
|
+
const catalogFor = async request =>
|
|
175
|
+
withSources ? await callSources(project, request) : NO_CATALOG;
|
|
48
176
|
|
|
49
|
-
// No query: the
|
|
50
|
-
if (!query
|
|
177
|
+
// No query, or nothing to look through: the list.
|
|
178
|
+
if (!query || (packages.length === 0 && !withSources)) {
|
|
179
|
+
if (!withSources) return list(packages, {configured, type, only});
|
|
180
|
+
const catalog = await catalogFor();
|
|
181
|
+
return list(withLatest(packages, catalog), {
|
|
182
|
+
configured,
|
|
183
|
+
type,
|
|
184
|
+
only,
|
|
185
|
+
available: availableEntries(catalog, packages, declared),
|
|
186
|
+
sources: catalog.sources,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
51
189
|
|
|
52
|
-
// A non-string (truthy) query would crash
|
|
53
|
-
//
|
|
54
|
-
//
|
|
190
|
+
// A non-string (truthy) query would crash the parsing below with a raw
|
|
191
|
+
// TypeError (no ERR_* code → downgrades to ERR_UNKNOWN). The CLI only ever
|
|
192
|
+
// passes a string, but the public API must fail with a code.
|
|
55
193
|
if (typeof query !== 'string') {
|
|
56
194
|
throw new AstryxError(
|
|
57
195
|
`Invalid query "${String(query)}"`,
|
|
@@ -60,17 +198,63 @@ export async function discover(query, options = {}) {
|
|
|
60
198
|
);
|
|
61
199
|
}
|
|
62
200
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
201
|
+
const target = splitTarget(query);
|
|
202
|
+
const installedNames = new Set(packages.map(p => p.name));
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* One package, one version, or one item, once `target.name` is known to be
|
|
206
|
+
* a package the project or a source has.
|
|
207
|
+
* @param {import('./_adapter.mjs').CatalogResult} catalog
|
|
208
|
+
*/
|
|
209
|
+
const packageView = async catalog => {
|
|
210
|
+
const entry = catalog.packages.find(p => p.package === target.name);
|
|
211
|
+
const installedAs = entry
|
|
212
|
+
? catalogState(entry, installedNames, declared).installedAs
|
|
213
|
+
: undefined;
|
|
214
|
+
const context = {catalog: entry, version: target.version, add, installedAs};
|
|
215
|
+
if (!target.item) return detail(packages, target.name, context);
|
|
216
|
+
const found = item(packages, target.name, target.item, context);
|
|
217
|
+
if (found) return found;
|
|
218
|
+
// Only an installed package has docs to fall back to. For one that is
|
|
219
|
+
// only in a source, the item is what is unknown, not the package.
|
|
220
|
+
if (entry && !packages.some(p => p.name === target.name)) {
|
|
221
|
+
throw new AstryxError(
|
|
222
|
+
`"${target.item}" not found in ${target.name}`,
|
|
223
|
+
similarItems(entry, target.item),
|
|
224
|
+
ERROR_CODES.ERR_UNKNOWN_COMPONENT,
|
|
225
|
+
);
|
|
70
226
|
}
|
|
71
|
-
return
|
|
227
|
+
return await doc(packages, target.name, target.item, {lang, zh});
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// An installed component keeps resolving to its full doc, before any source
|
|
231
|
+
// is asked anything.
|
|
232
|
+
const installedPkg = packages.find(p => p.name === target.name);
|
|
233
|
+
if (installedPkg && target.item && !target.version) {
|
|
234
|
+
const resolved = findComponent([installedPkg], target.item);
|
|
235
|
+
if (resolved) return await docFromResult(resolved, {lang, zh});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (target.scoped) {
|
|
239
|
+
return await packageView(
|
|
240
|
+
await catalogFor({package: target.name, version: target.version}),
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const listing = await catalogFor();
|
|
245
|
+
const isPackage =
|
|
246
|
+
installedPkg != null ||
|
|
247
|
+
listing.packages.some(p => p.package === target.name);
|
|
248
|
+
if (isPackage && (target.version || target.item || target.name === query)) {
|
|
249
|
+
return await packageView(
|
|
250
|
+
await catalogFor({package: target.name, version: target.version}),
|
|
251
|
+
);
|
|
72
252
|
}
|
|
73
253
|
|
|
74
|
-
|
|
75
|
-
|
|
254
|
+
return await search(packages, query, {
|
|
255
|
+
items: searchItems(packages, listing, declared),
|
|
256
|
+
type,
|
|
257
|
+
only,
|
|
258
|
+
limit: limit ?? DEFAULT_LIMIT,
|
|
259
|
+
});
|
|
76
260
|
}
|
|
@@ -68,10 +68,19 @@ describe('discover() dispatcher routing', () => {
|
|
|
68
68
|
it('free-text query with multiple matches -> discover.search envelope', async () => {
|
|
69
69
|
// 'a' is a substring of both Alpha and Beta (no exact match), so the search
|
|
70
70
|
// leaf returns the multi-match discover.search envelope. Proves free-text
|
|
71
|
-
// routing reaches the search leaf and projects its envelope.
|
|
71
|
+
// routing reaches the search leaf and projects its envelope. Search also
|
|
72
|
+
// matches package names, so the package itself is listed after them.
|
|
72
73
|
const r = await discover('a');
|
|
73
74
|
expect(r.type).toBe('discover.search');
|
|
74
|
-
expect(
|
|
75
|
+
expect(
|
|
76
|
+
r.data.matches.filter(m => m.kind === 'component').map(m => m.component),
|
|
77
|
+
).toEqual(['Alpha', 'Beta']);
|
|
78
|
+
expect(r.data.matches).toContainEqual({
|
|
79
|
+
package: '@acme/widgets',
|
|
80
|
+
component: '@acme/widgets',
|
|
81
|
+
kind: 'package',
|
|
82
|
+
installed: true,
|
|
83
|
+
});
|
|
75
84
|
});
|
|
76
85
|
|
|
77
86
|
it('free-text query with no match still routes to the search leaf (coded not-found)', async () => {
|
|
@@ -6,16 +6,36 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export type DiscoverListResponse = {
|
|
8
8
|
type: "discover.list";
|
|
9
|
+
/**
|
|
10
|
+
* The integrations the project loads.
|
|
11
|
+
*/
|
|
9
12
|
data: DiscoverListEntry[];
|
|
10
13
|
/**
|
|
11
|
-
* Present when the list is empty
|
|
12
|
-
*
|
|
13
|
-
* nothing discovered".
|
|
14
|
+
* Present when the list is empty, and
|
|
15
|
+
* whenever the project has a discover source.
|
|
14
16
|
*/
|
|
15
|
-
meta?:
|
|
16
|
-
configured: boolean;
|
|
17
|
-
} | undefined;
|
|
17
|
+
meta?: DiscoverListMeta | undefined;
|
|
18
18
|
};
|
|
19
|
+
export type DiscoverListMeta = {
|
|
20
|
+
/**
|
|
21
|
+
* Present when `data` is empty, so callers can
|
|
22
|
+
* distinguish "no packages configured" from "configured but nothing
|
|
23
|
+
* discovered".
|
|
24
|
+
*/
|
|
25
|
+
configured?: boolean | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* What the project could add,
|
|
28
|
+
* one entry per integration, never an alias of a package it has.
|
|
29
|
+
*/
|
|
30
|
+
available?: DiscoverAvailableEntry[] | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* What each discover source did.
|
|
33
|
+
*/
|
|
34
|
+
sources?: DiscoverSourceState[] | undefined;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* An installed integration.
|
|
38
|
+
*/
|
|
19
39
|
export type DiscoverListEntry = {
|
|
20
40
|
name: string;
|
|
21
41
|
category: string;
|
|
@@ -23,13 +43,94 @@ export type DiscoverListEntry = {
|
|
|
23
43
|
version?: string | undefined;
|
|
24
44
|
description?: string | undefined;
|
|
25
45
|
displayName?: string | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Template ids, when it adds any.
|
|
48
|
+
*/
|
|
49
|
+
templates?: string[] | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Doc topic names, when it adds any.
|
|
52
|
+
*/
|
|
53
|
+
docs?: string[] | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Theme slugs, when it adds any.
|
|
56
|
+
*/
|
|
57
|
+
themes?: string[] | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* `<version>/<id>`, when it adds any.
|
|
60
|
+
*/
|
|
61
|
+
codemods?: string[] | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Agent guidance, when a source lists any.
|
|
64
|
+
*/
|
|
65
|
+
agentDocs?: string[] | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* The latest release a discover source knows.
|
|
68
|
+
*/
|
|
69
|
+
latest?: string | undefined;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* A package the project could add.
|
|
73
|
+
*/
|
|
74
|
+
export type DiscoverAvailableEntry = {
|
|
75
|
+
name: string;
|
|
76
|
+
/**
|
|
77
|
+
* Its latest release.
|
|
78
|
+
*/
|
|
79
|
+
version?: string | undefined;
|
|
80
|
+
components: string[];
|
|
81
|
+
templates?: string[] | undefined;
|
|
82
|
+
docs?: string[] | undefined;
|
|
83
|
+
themes?: string[] | undefined;
|
|
84
|
+
codemods?: string[] | undefined;
|
|
85
|
+
agentDocs?: string[] | undefined;
|
|
86
|
+
description?: string | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* The integration's other package names.
|
|
89
|
+
*/
|
|
90
|
+
aliases?: string[] | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* The discover source that lists it.
|
|
93
|
+
*/
|
|
94
|
+
source: string;
|
|
95
|
+
};
|
|
96
|
+
export type DiscoverSourceState = {
|
|
97
|
+
name: string;
|
|
98
|
+
/**
|
|
99
|
+
* `astryx.config`, or the integration that exports it.
|
|
100
|
+
*/
|
|
101
|
+
from: string;
|
|
102
|
+
/**
|
|
103
|
+
* `saved`: the live call
|
|
104
|
+
* failed and discover used the copy saved at `savedAt`.
|
|
105
|
+
*/
|
|
106
|
+
status: "fresh" | "saved" | "failed";
|
|
107
|
+
generatedAt?: string | undefined;
|
|
108
|
+
complete?: boolean | undefined;
|
|
109
|
+
savedAt?: string | undefined;
|
|
110
|
+
error?: string | undefined;
|
|
26
111
|
};
|
|
27
112
|
/**
|
|
28
113
|
* astryx --json discover
|
|
29
114
|
*/
|
|
30
115
|
export type DiscoverDetailResponse = {
|
|
31
116
|
type: "discover.detail";
|
|
32
|
-
|
|
117
|
+
/**
|
|
118
|
+
* `installed` says whether the project has the package;
|
|
119
|
+
* `installedVersion` is set when it has another version than the one shown.
|
|
120
|
+
* `install` is the package-manager command that adds a package the project
|
|
121
|
+
* does not have; discover prints it and never runs it. `installedAs` names
|
|
122
|
+
* the package the project has instead, when this one is an alias of it.
|
|
123
|
+
* `versions` (newest first) comes from a discover source.
|
|
124
|
+
*/
|
|
125
|
+
data: DiscoverListEntry & {
|
|
126
|
+
installed: boolean;
|
|
127
|
+
installedVersion?: string;
|
|
128
|
+
aliases?: string[];
|
|
129
|
+
source?: string;
|
|
130
|
+
installedAs?: string;
|
|
131
|
+
install?: string;
|
|
132
|
+
versions?: import("../../authoring/discover/type").DiscoverVersion[];
|
|
133
|
+
};
|
|
33
134
|
};
|
|
34
135
|
/**
|
|
35
136
|
* astryx --json discover
|
|
@@ -39,18 +140,52 @@ export type DiscoverDetailDocResponse = {
|
|
|
39
140
|
data: import("@astryxdesign/cli/authoring").ComponentDoc;
|
|
40
141
|
};
|
|
41
142
|
/**
|
|
42
|
-
* astryx --json discover
|
|
143
|
+
* astryx --json discover
|
|
144
|
+
*/
|
|
145
|
+
export type DiscoverItemResponse = {
|
|
146
|
+
type: "discover.item";
|
|
147
|
+
data: {
|
|
148
|
+
package: string;
|
|
149
|
+
version?: string;
|
|
150
|
+
kind: import("../../authoring/discover/type").DiscoverKind;
|
|
151
|
+
name: string;
|
|
152
|
+
title?: string;
|
|
153
|
+
summary?: string;
|
|
154
|
+
keywords?: string[];
|
|
155
|
+
installed: boolean;
|
|
156
|
+
installedAs?: string;
|
|
157
|
+
install?: string;
|
|
158
|
+
source?: string;
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* astryx --json discover <searchterm>
|
|
43
163
|
*/
|
|
44
164
|
export type DiscoverSearchResponse = {
|
|
45
165
|
type: "discover.search";
|
|
166
|
+
/**
|
|
167
|
+
* `total` is set when `--limit` cut the list.
|
|
168
|
+
*/
|
|
46
169
|
data: {
|
|
47
170
|
query: string;
|
|
48
171
|
matches: DiscoverSearchEntry[];
|
|
172
|
+
total?: number;
|
|
49
173
|
};
|
|
50
174
|
};
|
|
51
175
|
export type DiscoverSearchEntry = {
|
|
52
176
|
package: string;
|
|
177
|
+
/**
|
|
178
|
+
* The item's name, for every kind; for a package
|
|
179
|
+
* match, the package name.
|
|
180
|
+
*/
|
|
53
181
|
component: string;
|
|
182
|
+
kind: import("../../authoring/discover/type").DiscoverKind | "package";
|
|
183
|
+
/**
|
|
184
|
+
* Whether the project has the package.
|
|
185
|
+
*/
|
|
186
|
+
installed: boolean;
|
|
187
|
+
title?: string | undefined;
|
|
188
|
+
summary?: string | undefined;
|
|
54
189
|
};
|
|
55
190
|
/**
|
|
56
191
|
* Options for `discover()`.
|
|
@@ -59,4 +194,8 @@ export type DiscoverOptions = {
|
|
|
59
194
|
components?: boolean | undefined;
|
|
60
195
|
lang?: string | undefined;
|
|
61
196
|
zh?: boolean | undefined;
|
|
197
|
+
type?: import("@astryxdesign/cli/authoring").DiscoverKind | undefined;
|
|
198
|
+
installed?: boolean | undefined;
|
|
199
|
+
available?: boolean | undefined;
|
|
200
|
+
limit?: number | undefined;
|
|
62
201
|
};
|
|
@@ -7,24 +7,37 @@
|
|
|
7
7
|
* Invocation -> type discriminator
|
|
8
8
|
* ------------------------------------------------------------------
|
|
9
9
|
* astryx --json discover -> discover.list
|
|
10
|
-
* astryx --json discover @scope/name
|
|
10
|
+
* astryx --json discover @scope/name[@version] -> discover.detail
|
|
11
11
|
* astryx --json discover @scope/name/Component -> discover.detail.doc
|
|
12
|
-
* astryx --json discover
|
|
13
|
-
* astryx --json discover <searchterm>
|
|
12
|
+
* astryx --json discover @scope/name/<item> -> discover.item
|
|
13
|
+
* astryx --json discover <searchterm> -> discover.search
|
|
14
14
|
* (not found) -> CLIError
|
|
15
|
+
*
|
|
16
|
+
* Fields added for discover sources are additive: every earlier field keeps
|
|
17
|
+
* its meaning.
|
|
15
18
|
*/
|
|
16
19
|
|
|
17
20
|
/**
|
|
18
21
|
* astryx --json discover
|
|
19
22
|
* @typedef {object} DiscoverListResponse
|
|
20
23
|
* @property {'discover.list'} type
|
|
21
|
-
* @property {DiscoverListEntry[]} data
|
|
22
|
-
* @property {
|
|
23
|
-
*
|
|
24
|
-
* nothing discovered".
|
|
24
|
+
* @property {DiscoverListEntry[]} data The integrations the project loads.
|
|
25
|
+
* @property {DiscoverListMeta} [meta] Present when the list is empty, and
|
|
26
|
+
* whenever the project has a discover source.
|
|
25
27
|
*/
|
|
26
28
|
|
|
27
29
|
/**
|
|
30
|
+
* @typedef {object} DiscoverListMeta
|
|
31
|
+
* @property {boolean} [configured] Present when `data` is empty, so callers can
|
|
32
|
+
* distinguish "no packages configured" from "configured but nothing
|
|
33
|
+
* discovered".
|
|
34
|
+
* @property {DiscoverAvailableEntry[]} [available] What the project could add,
|
|
35
|
+
* one entry per integration, never an alias of a package it has.
|
|
36
|
+
* @property {DiscoverSourceState[]} [sources] What each discover source did.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* An installed integration.
|
|
28
41
|
* @typedef {object} DiscoverListEntry
|
|
29
42
|
* @property {string} name
|
|
30
43
|
* @property {string} category
|
|
@@ -32,13 +45,60 @@
|
|
|
32
45
|
* @property {string} [version]
|
|
33
46
|
* @property {string} [description]
|
|
34
47
|
* @property {string} [displayName]
|
|
48
|
+
* @property {string[]} [templates] Template ids, when it adds any.
|
|
49
|
+
* @property {string[]} [docs] Doc topic names, when it adds any.
|
|
50
|
+
* @property {string[]} [themes] Theme slugs, when it adds any.
|
|
51
|
+
* @property {string[]} [codemods] `<version>/<id>`, when it adds any.
|
|
52
|
+
* @property {string[]} [agentDocs] Agent guidance, when a source lists any.
|
|
53
|
+
* @property {string} [latest] The latest release a discover source knows.
|
|
35
54
|
*/
|
|
36
55
|
|
|
37
56
|
/**
|
|
38
|
-
*
|
|
57
|
+
* A package the project could add.
|
|
58
|
+
* @typedef {object} DiscoverAvailableEntry
|
|
59
|
+
* @property {string} name
|
|
60
|
+
* @property {string} [version] Its latest release.
|
|
61
|
+
* @property {string[]} components
|
|
62
|
+
* @property {string[]} [templates]
|
|
63
|
+
* @property {string[]} [docs]
|
|
64
|
+
* @property {string[]} [themes]
|
|
65
|
+
* @property {string[]} [codemods]
|
|
66
|
+
* @property {string[]} [agentDocs]
|
|
67
|
+
* @property {string} [description]
|
|
68
|
+
* @property {string[]} [aliases] The integration's other package names.
|
|
69
|
+
* @property {string} source The discover source that lists it.
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @typedef {object} DiscoverSourceState
|
|
74
|
+
* @property {string} name
|
|
75
|
+
* @property {string} from `astryx.config`, or the integration that exports it.
|
|
76
|
+
* @property {'fresh' | 'saved' | 'failed'} status `saved`: the live call
|
|
77
|
+
* failed and discover used the copy saved at `savedAt`.
|
|
78
|
+
* @property {string} [generatedAt]
|
|
79
|
+
* @property {boolean} [complete]
|
|
80
|
+
* @property {string} [savedAt]
|
|
81
|
+
* @property {string} [error]
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* astryx --json discover @scope/name[@version]
|
|
39
86
|
* @typedef {object} DiscoverDetailResponse
|
|
40
87
|
* @property {'discover.detail'} type
|
|
41
|
-
* @property {DiscoverListEntry
|
|
88
|
+
* @property {DiscoverListEntry & {
|
|
89
|
+
* installed: boolean,
|
|
90
|
+
* installedVersion?: string,
|
|
91
|
+
* aliases?: string[],
|
|
92
|
+
* source?: string,
|
|
93
|
+
* installedAs?: string,
|
|
94
|
+
* install?: string,
|
|
95
|
+
* versions?: import('../../authoring/discover/type').DiscoverVersion[],
|
|
96
|
+
* }} data `installed` says whether the project has the package;
|
|
97
|
+
* `installedVersion` is set when it has another version than the one shown.
|
|
98
|
+
* `install` is the package-manager command that adds a package the project
|
|
99
|
+
* does not have; discover prints it and never runs it. `installedAs` names
|
|
100
|
+
* the package the project has instead, when this one is an alias of it.
|
|
101
|
+
* `versions` (newest first) comes from a discover source.
|
|
42
102
|
*/
|
|
43
103
|
|
|
44
104
|
/**
|
|
@@ -49,16 +109,42 @@
|
|
|
49
109
|
*/
|
|
50
110
|
|
|
51
111
|
/**
|
|
52
|
-
* astryx --json discover
|
|
112
|
+
* astryx --json discover @scope/name/<item>, for an item that is not an
|
|
113
|
+
* installed component.
|
|
114
|
+
* @typedef {object} DiscoverItemResponse
|
|
115
|
+
* @property {'discover.item'} type
|
|
116
|
+
* @property {{
|
|
117
|
+
* package: string,
|
|
118
|
+
* version?: string,
|
|
119
|
+
* kind: import('../../authoring/discover/type').DiscoverKind,
|
|
120
|
+
* name: string,
|
|
121
|
+
* title?: string,
|
|
122
|
+
* summary?: string,
|
|
123
|
+
* keywords?: string[],
|
|
124
|
+
* installed: boolean,
|
|
125
|
+
* installedAs?: string,
|
|
126
|
+
* install?: string,
|
|
127
|
+
* source?: string,
|
|
128
|
+
* }} data
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* astryx --json discover <searchterm>
|
|
53
133
|
* @typedef {object} DiscoverSearchResponse
|
|
54
134
|
* @property {'discover.search'} type
|
|
55
|
-
* @property {{query: string, matches: DiscoverSearchEntry[]}} data
|
|
135
|
+
* @property {{query: string, matches: DiscoverSearchEntry[], total?: number}} data
|
|
136
|
+
* `total` is set when `--limit` cut the list.
|
|
56
137
|
*/
|
|
57
138
|
|
|
58
139
|
/**
|
|
59
140
|
* @typedef {object} DiscoverSearchEntry
|
|
60
141
|
* @property {string} package
|
|
61
|
-
* @property {string} component
|
|
142
|
+
* @property {string} component The item's name, for every kind; for a package
|
|
143
|
+
* match, the package name.
|
|
144
|
+
* @property {import('../../authoring/discover/type').DiscoverKind | 'package'} kind
|
|
145
|
+
* @property {boolean} installed Whether the project has the package.
|
|
146
|
+
* @property {string} [title]
|
|
147
|
+
* @property {string} [summary]
|
|
62
148
|
*/
|
|
63
149
|
|
|
64
150
|
/**
|
|
@@ -67,6 +153,10 @@
|
|
|
67
153
|
* @property {boolean} [components]
|
|
68
154
|
* @property {string} [lang]
|
|
69
155
|
* @property {boolean} [zh]
|
|
156
|
+
* @property {import('../../authoring/discover/type').DiscoverKind} [type]
|
|
157
|
+
* @property {boolean} [installed]
|
|
158
|
+
* @property {boolean} [available]
|
|
159
|
+
* @property {number} [limit]
|
|
70
160
|
*/
|
|
71
161
|
|
|
72
162
|
export {};
|