@astryxdesign/cli 0.7.8-canary.ffd29c5 → 0.7.9-canary.0200dfe
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 +62 -0
- package/README.md +1 -1
- package/api/component/__fixtures__/resolutions/modules.txt +2 -2
- package/api/discover/_adapter.d.mts +1 -1
- package/api/docs/_adapter.d.mts +8 -2
- package/api/docs/_adapter.mjs +10 -4
- package/api/docs/detail/section/section.d.mts +5 -2
- package/api/docs/detail/section/section.mjs +6 -2
- package/api/docs/docs.mjs +7 -1
- package/api/doctor/_adapter.d.mts +6 -2
- package/api/doctor/_adapter.mjs +5 -3
- package/api/doctor/built-checks.d.mts +9 -4
- package/api/doctor/built-checks.mjs +15 -10
- package/api/search/_adapter.d.mts +3 -1
- package/api/search/_adapter.mjs +12 -2
- package/api/search/_candidate-score.d.mts +4 -1
- package/api/search/_candidate-score.mjs +46 -28
- package/api/search/_gather-components.mjs +5 -0
- package/api/search/_gather-templates.mjs +31 -6
- package/api/search/_lexical.d.mts +14 -0
- package/api/search/_lexical.mjs +4 -0
- package/api/search/_main-searcher.mjs +1 -1
- package/api/search/_result.d.mts +6 -5
- package/api/search/_result.mjs +1 -0
- package/api/search/_words.d.mts +44 -7
- package/api/search/_words.mjs +113 -21
- package/api/search/search.d.mts +4 -2
- package/api/search/search.doc.mjs +1 -1
- package/api/search/search.mjs +9 -8
- package/api/search/search.type.d.mts +4 -0
- package/api/search/search.type.mjs +1 -0
- package/api/swizzle/_adapter.d.mts +10 -0
- package/api/swizzle/_adapter.mjs +24 -1
- package/api/swizzle/copy/copy.mjs +9 -4
- package/api/theme/build/build.d.mts +26 -1
- package/api/theme/build/build.mjs +71 -20
- package/api/theme/build/core-interception.d.mts +2 -1
- package/api/theme/build/core-interception.mjs +23 -5
- package/assets/codemods/registry.mjs +1 -0
- package/assets/codemods/transforms/next/index.mjs +1 -11
- package/assets/codemods/transforms/v0.7.8/index.mjs +20 -0
- package/assets/discover/official-packages.json +4 -0
- package/assets/docs/browser-support.doc.mjs +27 -1
- package/assets/docs/tree/calendar-systems.doc.mjs +146 -0
- package/assets/docs/tree/calendars.doc.mjs +46 -0
- package/assets/docs/tree/i18n-calendars.doc.mjs +51 -0
- package/assets/docs/tree/internationalization.doc.mjs +3 -3
- package/assets/docs/tree/tokens-color.doc.mjs +1 -1
- package/assets/templates/blocks/components/Hooks/useClickableContainerHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useClickableContainerHookUsage.tsx +67 -0
- package/assets/templates/blocks/components/Hooks/useClipboardHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useClipboardHookUsage.tsx +35 -0
- package/assets/templates/blocks/components/Hooks/useImageModeHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useImageModeHookUsage.tsx +55 -0
- package/assets/templates/blocks/components/Hooks/useTreeFocusHookUsage.doc.mjs +15 -0
- package/assets/templates/blocks/components/Hooks/useTreeFocusHookUsage.tsx +98 -0
- package/assets/templates/blocks/components/Icon/useIconHookUsage.doc.mjs +19 -0
- package/assets/templates/blocks/components/Icon/useIconHookUsage.tsx +68 -0
- package/assets/templates/blocks/components/InfoTip/InfoTipMetricDefinitions.doc.mjs +14 -0
- package/assets/templates/blocks/components/InfoTip/InfoTipMetricDefinitions.tsx +46 -0
- package/assets/templates/blocks/components/InfoTip/InfoTipPermissionNotes.doc.mjs +14 -0
- package/assets/templates/blocks/components/InfoTip/InfoTipPermissionNotes.tsx +41 -0
- package/assets/templates/blocks/components/InfoTip/InfoTipShowcase.doc.mjs +13 -0
- package/assets/templates/blocks/components/InfoTip/InfoTipShowcase.tsx +24 -0
- package/assets/templates/blocks/components/PowerSearch/PowerSearchContentSearch.tsx +8 -7
- package/assets/templates/blocks/components/PowerSearch/PowerSearchFullFeatured.tsx +8 -7
- package/assets/templates/blocks/components/PowerSearch/PowerSearchPresetFilters.tsx +8 -7
- package/assets/templates/blocks/components/PowerSearch/PowerSearchSearchWithTable.tsx +12 -10
- package/assets/templates/blocks/components/PowerSearch/PowerSearchShowcase.tsx +8 -7
- package/assets/templates/blocks/components/Tokenizer/TokenizerClear.doc.mjs +2 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +2 -2
- package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +0 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +0 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.doc.mjs +2 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +0 -2
- package/assets/templates/pages/table-inbox/page.tsx +11 -8
- package/assets/templates/pages/work-item-detail/page.tsx +6 -2
- package/assets/theme.template.ts +1 -1
- package/authoring/debug/parse.d.mts +2 -2
- package/authoring/doctypes/_schema.d.mts +16 -0
- package/authoring/doctypes/_schema.mjs +15 -0
- package/authoring/doctypes/component/component.doc.mjs +6 -0
- package/authoring/doctypes/component/type.ts +16 -0
- package/authoring/index.d.ts +1 -0
- package/clients/cli/commands/build.mjs +9 -3
- package/clients/cli/commands/ensure-core-built.mjs +399 -43
- package/clients/cli/commands/search.mjs +8 -2
- package/clients/cli/formatters/index.mjs +11 -0
- package/clients/cli/index.mjs +11 -6
- package/foundation/agent-docs/agent-docs-target.d.mts +49 -0
- package/foundation/agent-docs/agent-docs-target.mjs +201 -0
- package/foundation/agent-docs/agent-docs.d.mts +1 -38
- package/foundation/agent-docs/agent-docs.mjs +16 -181
- package/foundation/config/config-path.d.mts +13 -0
- package/foundation/config/config-path.mjs +42 -0
- package/foundation/config/project.d.mts +1 -10
- package/foundation/config/project.mjs +31 -35
- package/foundation/discovery/component-discovery.mjs +56 -10
- package/foundation/discovery/component-loader.d.mts +1 -1
- package/foundation/discovery/icon-set-paths.d.mts +18 -0
- package/foundation/discovery/icon-set-paths.mjs +23 -0
- package/foundation/discovery/icon-set-writer.d.mts +2 -7
- package/foundation/discovery/icon-set-writer.mjs +3 -12
- package/foundation/discovery/template-adapter.d.mts +10 -0
- package/foundation/discovery/template-adapter.mjs +94 -4
- package/foundation/env/search-path.d.mts +12 -0
- package/foundation/env/search-path.mjs +71 -43
- package/foundation/fs/module-loader.d.mts +2 -8
- package/foundation/fs/module-loader.mjs +3 -12
- package/foundation/fs/present-files.d.mts +11 -0
- package/foundation/fs/present-files.mjs +25 -0
- package/foundation/integrations/autolink.d.mts +2 -21
- package/foundation/integrations/autolink.mjs +6 -42
- package/foundation/integrations/contribution-fixes.mjs +26 -3
- package/foundation/integrations/contribution-inventory.mjs +1 -1
- package/foundation/integrations/installed-package.d.mts +36 -0
- package/foundation/integrations/installed-package.mjs +57 -0
- package/foundation/integrations/integrations.d.mts +3 -75
- package/foundation/integrations/integrations.mjs +3 -16
- package/foundation/integrations/manifest-paths.d.mts +13 -0
- package/foundation/integrations/manifest-paths.mjs +31 -0
- package/foundation/integrations/manifest-writer.d.mts +3 -4
- package/foundation/integrations/manifest-writer.mjs +5 -3
- package/foundation/release/cache.d.mts +11 -4
- package/foundation/release/cache.mjs +15 -7
- package/foundation/response/response-types.doc.mjs +1 -1
- package/foundation/runtime/locked-versions.mjs +1 -1
- package/foundation/runtime/package-set.mjs +1 -1
- package/foundation/text/levenshtein.d.mts +4 -1
- package/foundation/text/levenshtein.mjs +44 -1
- package/package.json +9 -9
- package/api/swizzle/_github.d.mts +0 -8
- package/api/swizzle/_github.mjs +0 -22
- /package/assets/codemods/transforms/{next → v0.7.8}/promote-tokenizer-presentation.mjs +0 -0
|
@@ -35,15 +35,15 @@
|
|
|
35
35
|
* "cable" is not "table".
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
|
-
import {levenshteinDistance} from '../../foundation/text/string-utils.mjs';
|
|
39
38
|
import {
|
|
40
39
|
stem,
|
|
41
|
-
wordForms,
|
|
42
40
|
sameWord,
|
|
43
|
-
|
|
41
|
+
sameTermWord,
|
|
42
|
+
startsATermWordOf,
|
|
43
|
+
termWords,
|
|
44
44
|
wordsOf,
|
|
45
45
|
joined,
|
|
46
|
-
|
|
46
|
+
typoDistance,
|
|
47
47
|
} from './_words.mjs';
|
|
48
48
|
import {pluralOf} from './_query.mjs';
|
|
49
49
|
|
|
@@ -79,14 +79,14 @@ function spellsOut(term, name, description) {
|
|
|
79
79
|
/**
|
|
80
80
|
* Whether a one-word term is a name's last word and every word before it is a
|
|
81
81
|
* single letter: Stack in VStack and HStack.
|
|
82
|
-
* @param {
|
|
82
|
+
* @param {import('./_words.mjs').TermWords} t
|
|
83
83
|
* @param {string} name
|
|
84
84
|
*/
|
|
85
|
-
function headOfLetters(
|
|
85
|
+
function headOfLetters(t, name) {
|
|
86
86
|
const parts = wordsOf(name);
|
|
87
87
|
return (
|
|
88
88
|
parts.length >= 2 &&
|
|
89
|
-
|
|
89
|
+
sameTermWord(t, parts[parts.length - 1]) &&
|
|
90
90
|
parts.slice(0, -1).every(p => p.length === 1)
|
|
91
91
|
);
|
|
92
92
|
}
|
|
@@ -94,6 +94,19 @@ function headOfLetters(term, name) {
|
|
|
94
94
|
/** How many of a family's members a query naming the family lists. */
|
|
95
95
|
const FAMILY_MEMBERS = 3;
|
|
96
96
|
|
|
97
|
+
/**
|
|
98
|
+
* A derived name's score for a term: 60 for the same word, 40 for a word the
|
|
99
|
+
* term starts, else 0.
|
|
100
|
+
* @param {import('./_words.mjs').TermWords} t - The lowercased search term.
|
|
101
|
+
* @param {string} kw - The derived name as authored.
|
|
102
|
+
* @returns {number}
|
|
103
|
+
*/
|
|
104
|
+
function weakKeywordScore(t, kw) {
|
|
105
|
+
const kwLower = String(kw).toLowerCase();
|
|
106
|
+
if (kwLower === t.term || sameTermWord(t, kwLower)) return 60;
|
|
107
|
+
return startsATermWordOf(t, kw) ? 40 : 0;
|
|
108
|
+
}
|
|
109
|
+
|
|
97
110
|
/**
|
|
98
111
|
* Score a single candidate against the search term across name, keywords,
|
|
99
112
|
* and prose signals. Returns the best (highest) score plus a human reason,
|
|
@@ -107,6 +120,8 @@ const FAMILY_MEMBERS = 3;
|
|
|
107
120
|
* also matches typed as words: `command palette` is CommandPalette.
|
|
108
121
|
* @param {string[]} [candidate.keywords] - Authored intent (componentsUsed, category words).
|
|
109
122
|
* @param {string[]} [candidate.weakKeywords] - Derived signal (components a page renders).
|
|
123
|
+
* @param {string[]} [candidate.weakKeywordBound] - Every name `weakKeywords`
|
|
124
|
+
* can hold, when reading them is costly: they are read only if one matches.
|
|
110
125
|
* @param {string} [candidate.description]
|
|
111
126
|
* @param {string[]} [candidate.prose] - Extra free-text blobs (doc section text, best practices).
|
|
112
127
|
* @param {string[]} [candidate.guidance] - Usage guidance (features, best practices) — scored a tier below description.
|
|
@@ -118,20 +133,22 @@ const FAMILY_MEMBERS = 3;
|
|
|
118
133
|
*/
|
|
119
134
|
export function scoreCandidate(
|
|
120
135
|
term,
|
|
121
|
-
|
|
136
|
+
candidate,
|
|
137
|
+
{fuzzy = true, joins = true, part = false, synonym = false} = {},
|
|
138
|
+
) {
|
|
139
|
+
const {
|
|
122
140
|
name,
|
|
123
141
|
aliases = [],
|
|
124
142
|
domain,
|
|
125
143
|
keywords = [],
|
|
126
|
-
weakKeywords = [],
|
|
127
144
|
description = '',
|
|
128
145
|
prose = [],
|
|
129
146
|
guidance = [],
|
|
130
147
|
_family,
|
|
131
148
|
_familyIndex,
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
)
|
|
149
|
+
} = candidate;
|
|
150
|
+
// The term's forms, worked out once for every word below.
|
|
151
|
+
const t = termWords(term);
|
|
135
152
|
let best = 0;
|
|
136
153
|
let reason = '';
|
|
137
154
|
/** @type {'partial' | 'keyword' | false} */
|
|
@@ -194,23 +211,23 @@ export function scoreCandidate(
|
|
|
194
211
|
// outranks the Token component for `tokens`.
|
|
195
212
|
consider(99, 'plural of the name');
|
|
196
213
|
} else {
|
|
197
|
-
if (
|
|
214
|
+
if (sameTermWord(t, nameLower)) consider(95, `name "${candidateName}"`);
|
|
198
215
|
// The term is a word of the name, or starts one: "input" in TextInput.
|
|
199
216
|
else if (
|
|
200
217
|
!part &&
|
|
201
218
|
domain !== 'doc' &&
|
|
202
219
|
domain !== 'theme' &&
|
|
203
|
-
headOfLetters(
|
|
220
|
+
headOfLetters(t, candidateName)
|
|
204
221
|
) {
|
|
205
222
|
// The whole query is the name's head word after single letters (Stack
|
|
206
223
|
// in VStack, HStack): a variant named by its head, as a keyword is.
|
|
207
224
|
consider(90, `name "${candidateName}" ends in "${term}"`);
|
|
208
|
-
} else if (
|
|
225
|
+
} else if (startsATermWordOf(t, candidateName)) {
|
|
209
226
|
consider(60, `name contains "${term}"`);
|
|
210
227
|
}
|
|
211
228
|
if (fuzzy) {
|
|
212
|
-
const dist =
|
|
213
|
-
if (
|
|
229
|
+
const dist = typoDistance(term, nameLower);
|
|
230
|
+
if (dist != null) {
|
|
214
231
|
consider(
|
|
215
232
|
dist === 1 ? 80 : dist === 2 ? 40 : 20,
|
|
216
233
|
`similar name (distance ${dist})`,
|
|
@@ -259,14 +276,14 @@ export function scoreCandidate(
|
|
|
259
276
|
consider(90, `keyword "${kw}"`, 'keyword');
|
|
260
277
|
continue;
|
|
261
278
|
}
|
|
262
|
-
if (
|
|
279
|
+
if (sameTermWord(t, kwLower)) {
|
|
263
280
|
consider(88, `keyword "${kw}"`);
|
|
264
281
|
continue;
|
|
265
282
|
}
|
|
266
|
-
if (
|
|
283
|
+
if (startsATermWordOf(t, kw)) consider(70, `keyword "${kw}"`);
|
|
267
284
|
if (fuzzy) {
|
|
268
|
-
const dist =
|
|
269
|
-
if (
|
|
285
|
+
const dist = typoDistance(term, kwLower);
|
|
286
|
+
if (dist != null && dist <= 2) {
|
|
270
287
|
consider(dist === 1 ? 70 : 30, `keyword "${kw}" (distance ${dist})`);
|
|
271
288
|
}
|
|
272
289
|
}
|
|
@@ -277,13 +294,14 @@ export function scoreCandidate(
|
|
|
277
294
|
// confident-match gate on its own; it still counts toward multi-term
|
|
278
295
|
// coverage, which is where "this page renders that" is real evidence.
|
|
279
296
|
// No Levenshtein tier — fuzzy matching a derived signal is pure noise.
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
297
|
+
// A bound skips the read when no name the page can yield matches the term,
|
|
298
|
+
// and then no weak keyword can match it either.
|
|
299
|
+
const bound = candidate.weakKeywordBound;
|
|
300
|
+
if (!bound || bound.some(kw => weakKeywordScore(t, kw) > 0)) {
|
|
301
|
+
for (const kw of candidate.weakKeywords ?? []) {
|
|
302
|
+
const score = weakKeywordScore(t, kw);
|
|
303
|
+
if (score > 0) consider(score, `renders ${kw}`);
|
|
285
304
|
}
|
|
286
|
-
if (startsAWordOf(term, kw)) consider(40, `renders ${kw}`);
|
|
287
305
|
}
|
|
288
306
|
|
|
289
307
|
// ── Prose / description / guidance signals (stem-tolerant whole word) ──
|
|
@@ -292,7 +310,7 @@ export function scoreCandidate(
|
|
|
292
310
|
if (term.length >= 3) {
|
|
293
311
|
// Any form of the term, with any common suffix: `spacing` finds
|
|
294
312
|
// "space" and "spaces", `tables` finds "table".
|
|
295
|
-
const roots = [...new Set([stem(term), ...
|
|
313
|
+
const roots = [...new Set([stem(term), ...t.forms])]
|
|
296
314
|
.filter(f => f.length >= 3)
|
|
297
315
|
.map(f => f.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
|
298
316
|
const re = new RegExp(`\\b(?:${roots.join('|')})(s|es|ing|ed|ies)?\\b`);
|
|
@@ -73,6 +73,8 @@ async function gatherCoreComponents(coreDir) {
|
|
|
73
73
|
let description = '';
|
|
74
74
|
/** @type {string[]} */
|
|
75
75
|
let guidance = [];
|
|
76
|
+
/** @type {import('@astryxdesign/cli/authoring').ComponentDeprecation | undefined} */
|
|
77
|
+
let deprecated;
|
|
76
78
|
if (readme && readme.endsWith('.doc.mjs')) {
|
|
77
79
|
const loaded = await loadModuleDoc(readme);
|
|
78
80
|
// A member documented in its family's doc (VStack in Stack's doc) is
|
|
@@ -83,6 +85,7 @@ async function gatherCoreComponents(coreDir) {
|
|
|
83
85
|
keywords = Array.isArray(doc.keywords) ? doc.keywords : [];
|
|
84
86
|
description = doc.usage?.description || doc.description || '';
|
|
85
87
|
guidance = guidanceFrom(doc);
|
|
88
|
+
deprecated = doc.deprecated;
|
|
86
89
|
}
|
|
87
90
|
for (const [n, place] of familyPlaces(loaded)) places.set(n, place);
|
|
88
91
|
}
|
|
@@ -92,6 +95,7 @@ async function gatherCoreComponents(coreDir) {
|
|
|
92
95
|
keywords,
|
|
93
96
|
description,
|
|
94
97
|
guidance,
|
|
98
|
+
...(deprecated ? {_deprecated: deprecated} : {}),
|
|
95
99
|
_package: CORE_PACKAGE,
|
|
96
100
|
_import: resolveImportPath(coreDir, comp),
|
|
97
101
|
});
|
|
@@ -178,6 +182,7 @@ async function gatherIntegrationComponents(loadedIntegrations) {
|
|
|
178
182
|
keywords: doc && Array.isArray(doc.keywords) ? doc.keywords : [],
|
|
179
183
|
description: doc ? doc.usage?.description || doc.description || '' : '',
|
|
180
184
|
guidance: guidanceFrom(doc),
|
|
185
|
+
...(doc?.deprecated ? {_deprecated: doc.deprecated} : {}),
|
|
181
186
|
...places.get(rec.name),
|
|
182
187
|
_package: rec.package ?? integration.name,
|
|
183
188
|
// Exactly what `component` reports: a doc may state its own specifier
|
|
@@ -4,10 +4,15 @@
|
|
|
4
4
|
* @file Search's template and theme candidates. Imported only by the adapter.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import fs from 'node:fs';
|
|
7
8
|
import {CORE_PACKAGE} from '../../foundation/discovery/component-discovery.mjs';
|
|
8
|
-
import {discoverTemplates
|
|
9
|
+
import {discoverTemplates} from '../template/template.mjs';
|
|
9
10
|
import {listAvailableThemes} from '../theme/_adapter.mjs';
|
|
10
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
componentNameBound,
|
|
13
|
+
componentsInSource,
|
|
14
|
+
templateLookupIds,
|
|
15
|
+
} from '../../foundation/discovery/template-adapter.mjs';
|
|
11
16
|
import {sameWord, wordsOf} from './_words.mjs';
|
|
12
17
|
|
|
13
18
|
/** @typedef {import('./_lexical.mjs').Candidate} Candidate */
|
|
@@ -66,12 +71,29 @@ export async function gatherTemplates(cwd) {
|
|
|
66
71
|
? [...t.componentsUsed]
|
|
67
72
|
: [];
|
|
68
73
|
keywords.push(...templateLookupIds(t).filter(id => id !== commandName));
|
|
69
|
-
/** @type {string[]} */
|
|
70
|
-
let
|
|
74
|
+
/** @type {() => string[]} */
|
|
75
|
+
let derive = () => [];
|
|
76
|
+
/** @type {string[] | null} */
|
|
77
|
+
let weakKeywordBound = null;
|
|
71
78
|
if (t.type === 'page') {
|
|
72
79
|
if (t.filePath) {
|
|
73
80
|
try {
|
|
74
|
-
|
|
81
|
+
const source = fs.readFileSync(t.filePath, 'utf-8');
|
|
82
|
+
// Parsing the source costs more than the rest of the page's gather.
|
|
83
|
+
// It waits until a term could match a name the source can yield.
|
|
84
|
+
/** @type {string[] | undefined} */
|
|
85
|
+
let derived;
|
|
86
|
+
derive = () => {
|
|
87
|
+
if (derived === undefined) {
|
|
88
|
+
try {
|
|
89
|
+
derived = componentsInSource(source);
|
|
90
|
+
} catch {
|
|
91
|
+
derived = [];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return derived;
|
|
95
|
+
};
|
|
96
|
+
weakKeywordBound = componentNameBound(source);
|
|
75
97
|
} catch {
|
|
76
98
|
// Best-effort: skip keyword enrichment if the source can't be read.
|
|
77
99
|
}
|
|
@@ -83,7 +105,10 @@ export async function gatherTemplates(cwd) {
|
|
|
83
105
|
domain: 'template',
|
|
84
106
|
name: commandName,
|
|
85
107
|
keywords,
|
|
86
|
-
weakKeywords
|
|
108
|
+
get weakKeywords() {
|
|
109
|
+
return derive();
|
|
110
|
+
},
|
|
111
|
+
...(weakKeywordBound ? {weakKeywordBound} : {}),
|
|
87
112
|
description: t.description || '',
|
|
88
113
|
// A template's own keywords name the many ideas it serves, so they score
|
|
89
114
|
// as its prose does, not as a name: one of them matching one word of a
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
* author lists in `keywords`, without the code terms and table cells its
|
|
15
15
|
* other keywords add.
|
|
16
16
|
* @property {string[]} [weakKeywords]
|
|
17
|
+
* @property {string[]} [weakKeywordBound] - Every name `weakKeywords` can
|
|
18
|
+
* hold, for a page whose weak keywords cost a parse to read.
|
|
17
19
|
* @property {string} [description]
|
|
18
20
|
* @property {string[]} [prose]
|
|
19
21
|
* @property {string[]} [guidance]
|
|
@@ -40,6 +42,8 @@
|
|
|
40
42
|
* @property {'file'|'doc'} [_hold] - How an integration component holds its
|
|
41
43
|
* name, for the owner rule.
|
|
42
44
|
* @property {string} [_docPath] - An integration component's doc.
|
|
45
|
+
* @property {import('@astryxdesign/cli/authoring').ComponentDeprecation} [_deprecated] -
|
|
46
|
+
* A deprecated component's replacement, from its doc's `deprecated`.
|
|
43
47
|
*/
|
|
44
48
|
/**
|
|
45
49
|
* True when the query is the candidate's whole name or another name of it,
|
|
@@ -88,6 +92,11 @@ export type Candidate = {
|
|
|
88
92
|
*/
|
|
89
93
|
_declared?: string[] | undefined;
|
|
90
94
|
weakKeywords?: string[] | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* - Every name `weakKeywords` can
|
|
97
|
+
* hold, for a page whose weak keywords cost a parse to read.
|
|
98
|
+
*/
|
|
99
|
+
weakKeywordBound?: string[] | undefined;
|
|
91
100
|
description?: string | undefined;
|
|
92
101
|
prose?: string[] | undefined;
|
|
93
102
|
guidance?: string[] | undefined;
|
|
@@ -144,4 +153,9 @@ export type Candidate = {
|
|
|
144
153
|
* - An integration component's doc.
|
|
145
154
|
*/
|
|
146
155
|
_docPath?: string | undefined;
|
|
156
|
+
/**
|
|
157
|
+
* -
|
|
158
|
+
* A deprecated component's replacement, from its doc's `deprecated`.
|
|
159
|
+
*/
|
|
160
|
+
_deprecated?: import("@astryxdesign/cli/authoring").ComponentDeprecation | undefined;
|
|
147
161
|
};
|
package/api/search/_lexical.mjs
CHANGED
|
@@ -73,6 +73,8 @@ import {toResult, searchedComponentsOf} from './_result.mjs';
|
|
|
73
73
|
* author lists in `keywords`, without the code terms and table cells its
|
|
74
74
|
* other keywords add.
|
|
75
75
|
* @property {string[]} [weakKeywords]
|
|
76
|
+
* @property {string[]} [weakKeywordBound] - Every name `weakKeywords` can
|
|
77
|
+
* hold, for a page whose weak keywords cost a parse to read.
|
|
76
78
|
* @property {string} [description]
|
|
77
79
|
* @property {string[]} [prose]
|
|
78
80
|
* @property {string[]} [guidance]
|
|
@@ -99,6 +101,8 @@ import {toResult, searchedComponentsOf} from './_result.mjs';
|
|
|
99
101
|
* @property {'file'|'doc'} [_hold] - How an integration component holds its
|
|
100
102
|
* name, for the owner rule.
|
|
101
103
|
* @property {string} [_docPath] - An integration component's doc.
|
|
104
|
+
* @property {import('@astryxdesign/cli/authoring').ComponentDeprecation} [_deprecated] -
|
|
105
|
+
* A deprecated component's replacement, from its doc's `deprecated`.
|
|
102
106
|
*/
|
|
103
107
|
|
|
104
108
|
/**
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* domain the query wants. Its weights are static numbers in
|
|
9
9
|
* _main-searcher.weights.json.
|
|
10
10
|
* @input {query, options} and the gathered catalog with its static data
|
|
11
|
-
* @output the search response, the lexical response's shape and
|
|
11
|
+
* @output the search response, the lexical response's shape and count
|
|
12
12
|
* @position api/search; a child of the root dispatcher in tree.mjs
|
|
13
13
|
*/
|
|
14
14
|
|
package/api/search/_result.d.mts
CHANGED
|
@@ -17,16 +17,17 @@
|
|
|
17
17
|
* (spec AST-081 FR3).
|
|
18
18
|
*/
|
|
19
19
|
export function toResult(c: Candidate, score: number, reason: string, matchedTerms: number, queryTerms: number, outside?: boolean): {
|
|
20
|
-
domain: "template" | "component" | "
|
|
20
|
+
domain: "template" | "component" | "doc" | "theme" | "hook";
|
|
21
21
|
name: string;
|
|
22
22
|
package: string | undefined;
|
|
23
23
|
score: number;
|
|
24
24
|
reason: string;
|
|
25
25
|
description: string;
|
|
26
26
|
} | {
|
|
27
|
+
deprecated?: import("../../authoring/index.js").ComponentDeprecation | undefined;
|
|
27
28
|
import: string | undefined;
|
|
28
29
|
command: string;
|
|
29
|
-
domain: "template" | "component" | "
|
|
30
|
+
domain: "template" | "component" | "doc" | "theme" | "hook";
|
|
30
31
|
name: string;
|
|
31
32
|
package: string | undefined;
|
|
32
33
|
score: number;
|
|
@@ -38,7 +39,7 @@ export function toResult(c: Candidate, score: number, reason: string, matchedTer
|
|
|
38
39
|
command: string;
|
|
39
40
|
section?: string | undefined;
|
|
40
41
|
name: string;
|
|
41
|
-
domain: "template" | "component" | "
|
|
42
|
+
domain: "template" | "component" | "doc" | "theme" | "hook";
|
|
42
43
|
package: string | undefined;
|
|
43
44
|
score: number;
|
|
44
45
|
reason: string;
|
|
@@ -47,7 +48,7 @@ export function toResult(c: Candidate, score: number, reason: string, matchedTer
|
|
|
47
48
|
displayName: string | undefined;
|
|
48
49
|
kind: "page" | "block" | undefined;
|
|
49
50
|
command: string;
|
|
50
|
-
domain: "template" | "component" | "
|
|
51
|
+
domain: "template" | "component" | "doc" | "theme" | "hook";
|
|
51
52
|
name: string;
|
|
52
53
|
package: string | undefined;
|
|
53
54
|
score: number;
|
|
@@ -56,7 +57,7 @@ export function toResult(c: Candidate, score: number, reason: string, matchedTer
|
|
|
56
57
|
} | {
|
|
57
58
|
displayName: string | undefined;
|
|
58
59
|
command: string;
|
|
59
|
-
domain: "template" | "component" | "
|
|
60
|
+
domain: "template" | "component" | "doc" | "theme" | "hook";
|
|
60
61
|
name: string;
|
|
61
62
|
package: string | undefined;
|
|
62
63
|
score: number;
|
package/api/search/_result.mjs
CHANGED
package/api/search/_words.d.mts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* @file Word matching for search: stems and word forms, word starts,
|
|
6
|
-
* identifier spelling, joined names, and typo tolerance.
|
|
7
|
-
*/
|
|
8
4
|
/**
|
|
9
5
|
* Light stemmer: strips common English suffixes so "charts"/"charting" and
|
|
10
6
|
* "chart" share a root. Deliberately crude (no Porter) — good enough to bridge
|
|
@@ -14,9 +10,7 @@
|
|
|
14
10
|
*/
|
|
15
11
|
export function stem(w: string): string;
|
|
16
12
|
/**
|
|
17
|
-
* The forms of a word that count as the same word
|
|
18
|
-
* singular when it ends in a plural suffix — so "tables" is "table",
|
|
19
|
-
* "statuses" is "status", and "filtering" is "filter".
|
|
13
|
+
* The forms of a word that count as the same word (see someForm).
|
|
20
14
|
* @param {string} w - Lowercase word.
|
|
21
15
|
* @returns {Set<string>}
|
|
22
16
|
*/
|
|
@@ -28,6 +22,23 @@ export function wordForms(w: string): Set<string>;
|
|
|
28
22
|
* @returns {boolean}
|
|
29
23
|
*/
|
|
30
24
|
export function sameWord(a: string, b: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* A search term's forms and the word starts it matches, worked out once for
|
|
27
|
+
* every word the term is compared with.
|
|
28
|
+
* @typedef {{term: string, forms: Set<string>, starts: string[]}} TermWords
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* @param {string} term - Lowercase term.
|
|
32
|
+
* @returns {TermWords}
|
|
33
|
+
*/
|
|
34
|
+
export function termWords(term: string): TermWords;
|
|
35
|
+
/**
|
|
36
|
+
* Whether a lowercase word is the term's word, as sameWord answers.
|
|
37
|
+
* @param {TermWords} t
|
|
38
|
+
* @param {string} w
|
|
39
|
+
* @returns {boolean}
|
|
40
|
+
*/
|
|
41
|
+
export function sameTermWord(t: TermWords, w: string): boolean;
|
|
31
42
|
/**
|
|
32
43
|
* The lowercase words of a name or keyword: split at non-alphanumerics and at
|
|
33
44
|
* camelCase boundaries, so "TextInput" is ["text", "input"] and
|
|
@@ -45,6 +56,13 @@ export function wordsOf(text: string): string[];
|
|
|
45
56
|
* @returns {boolean}
|
|
46
57
|
*/
|
|
47
58
|
export function startsAWordOf(term: string, text: string): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* startsAWordOf for a term whose words are already worked out.
|
|
61
|
+
* @param {TermWords} t
|
|
62
|
+
* @param {string} text - The name or keyword as authored.
|
|
63
|
+
* @returns {boolean}
|
|
64
|
+
*/
|
|
65
|
+
export function startsATermWordOf(t: TermWords, text: string): boolean;
|
|
48
66
|
/**
|
|
49
67
|
* A query with its camelCase and PascalCase identifiers spelled as words, so
|
|
50
68
|
* `SidebarToggle` reads "sidebar toggle" and `useTablePaginationState` "use
|
|
@@ -61,4 +79,23 @@ export function spellIdentifiers(query: string): string;
|
|
|
61
79
|
* @returns {string}
|
|
62
80
|
*/
|
|
63
81
|
export function joined(text: string): string;
|
|
82
|
+
/**
|
|
83
|
+
* The edit distance between two words when it counts as a typo (isTypo), or
|
|
84
|
+
* null. The shorter word's length caps the distance that can count. A pair
|
|
85
|
+
* the cap rules out needs no distance table, and the others compute only the
|
|
86
|
+
* cells within the cap.
|
|
87
|
+
* @param {string} a
|
|
88
|
+
* @param {string} b
|
|
89
|
+
* @returns {1 | 2 | 3 | null}
|
|
90
|
+
*/
|
|
91
|
+
export function typoDistance(a: string, b: string): 1 | 2 | 3 | null;
|
|
64
92
|
export function isTypo(a: string, b: string, dist: number): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* A search term's forms and the word starts it matches, worked out once for
|
|
95
|
+
* every word the term is compared with.
|
|
96
|
+
*/
|
|
97
|
+
export type TermWords = {
|
|
98
|
+
term: string;
|
|
99
|
+
forms: Set<string>;
|
|
100
|
+
starts: string[];
|
|
101
|
+
};
|
package/api/search/_words.mjs
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* identifier spelling, joined names, and typo tolerance.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import {levenshteinDistance} from '../../foundation/text/levenshtein.mjs';
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
11
|
* Light stemmer: strips common English suffixes so "charts"/"charting" and
|
|
10
12
|
* "chart" share a root. Deliberately crude (no Porter) — good enough to bridge
|
|
@@ -24,27 +26,47 @@ export function stem(w) {
|
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* "
|
|
29
|
+
* Visits the forms of a word that count as the same word, in order, until a
|
|
30
|
+
* visit returns true. The forms are the word, its stem, and its singular when
|
|
31
|
+
* it ends in a plural suffix. So "tables" is "table", "statuses" is "status",
|
|
32
|
+
* and "filtering" is "filter".
|
|
30
33
|
* @param {string} w - Lowercase word.
|
|
31
|
-
* @
|
|
34
|
+
* @param {(form: string) => boolean} visit
|
|
35
|
+
* @returns {boolean} whether a visit returned true
|
|
32
36
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (w.length > 3 && w.endsWith('s')
|
|
36
|
-
if (w.length > 4 && w.endsWith('es')
|
|
37
|
-
if (w.length > 4 && w.endsWith('ies')
|
|
37
|
+
function someForm(w, visit) {
|
|
38
|
+
if (visit(w) || visit(stem(w))) return true;
|
|
39
|
+
if (w.length > 3 && w.endsWith('s') && visit(w.slice(0, -1))) return true;
|
|
40
|
+
if (w.length > 4 && w.endsWith('es') && visit(w.slice(0, -2))) return true;
|
|
41
|
+
if (w.length > 4 && w.endsWith('ies') && visit(w.slice(0, -3) + 'y')) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
38
44
|
// A gerund keeps its verb: "spacing" lost a final e ("space"), and
|
|
39
45
|
// "dragging" doubled a consonant ("drag"). A past participle does not: it
|
|
40
46
|
// usually describes a state ("archived notes"), not the action a catalog
|
|
41
47
|
// word names.
|
|
42
48
|
if (w.length >= 6 && w.endsWith('ing')) {
|
|
43
49
|
const base = w.slice(0, -3);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
if (visit(base) || visit(`${base}e`)) return true;
|
|
51
|
+
if (/([b-df-hj-np-tv-z])\1$/.test(base) && visit(base.slice(0, -1))) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
47
54
|
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The forms of a word that count as the same word (see someForm).
|
|
60
|
+
* @param {string} w - Lowercase word.
|
|
61
|
+
* @returns {Set<string>}
|
|
62
|
+
*/
|
|
63
|
+
export function wordForms(w) {
|
|
64
|
+
/** @type {Set<string>} */
|
|
65
|
+
const forms = new Set();
|
|
66
|
+
someForm(w, form => {
|
|
67
|
+
forms.add(form);
|
|
68
|
+
return false;
|
|
69
|
+
});
|
|
48
70
|
return forms;
|
|
49
71
|
}
|
|
50
72
|
|
|
@@ -72,8 +94,38 @@ function singulars(w) {
|
|
|
72
94
|
export function sameWord(a, b) {
|
|
73
95
|
if (a === b) return true;
|
|
74
96
|
const forms = wordForms(a);
|
|
75
|
-
|
|
76
|
-
|
|
97
|
+
return someForm(b, form => forms.has(form));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* A search term's forms and the word starts it matches, worked out once for
|
|
102
|
+
* every word the term is compared with.
|
|
103
|
+
* @typedef {{term: string, forms: Set<string>, starts: string[]}} TermWords
|
|
104
|
+
*/
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @param {string} term - Lowercase term.
|
|
108
|
+
* @returns {TermWords}
|
|
109
|
+
*/
|
|
110
|
+
export function termWords(term) {
|
|
111
|
+
return {
|
|
112
|
+
term,
|
|
113
|
+
forms: wordForms(term),
|
|
114
|
+
// The term or its singular may start the word: "tokens" starts
|
|
115
|
+
// "tokenizer" through "token". A singular needs five letters, so "stats"
|
|
116
|
+
// does not start "status".
|
|
117
|
+
starts: [term, ...singulars(term).filter(f => f.length >= 5)],
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Whether a lowercase word is the term's word, as sameWord answers.
|
|
123
|
+
* @param {TermWords} t
|
|
124
|
+
* @param {string} w
|
|
125
|
+
* @returns {boolean}
|
|
126
|
+
*/
|
|
127
|
+
export function sameTermWord(t, w) {
|
|
128
|
+
return w === t.term || someForm(w, form => t.forms.has(form));
|
|
77
129
|
}
|
|
78
130
|
|
|
79
131
|
/**
|
|
@@ -101,17 +153,33 @@ export function wordsOf(text) {
|
|
|
101
153
|
* @returns {boolean}
|
|
102
154
|
*/
|
|
103
155
|
export function startsAWordOf(term, text) {
|
|
104
|
-
if (term
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
156
|
+
if (!coversHalf(term, text)) return false;
|
|
157
|
+
return startsATermWordOf(termWords(term), text);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* startsAWordOf for a term whose words are already worked out.
|
|
162
|
+
* @param {TermWords} t
|
|
163
|
+
* @param {string} text - The name or keyword as authored.
|
|
164
|
+
* @returns {boolean}
|
|
165
|
+
*/
|
|
166
|
+
export function startsATermWordOf(t, text) {
|
|
167
|
+
if (!coversHalf(t.term, text)) return false;
|
|
110
168
|
return wordsOf(text).some(
|
|
111
|
-
w => starts.some(f => w.startsWith(f)) ||
|
|
169
|
+
w => t.starts.some(f => w.startsWith(f)) || sameTermWord(t, w),
|
|
112
170
|
);
|
|
113
171
|
}
|
|
114
172
|
|
|
173
|
+
/**
|
|
174
|
+
* Whether a term is long enough to match inside `text`: four letters, and at
|
|
175
|
+
* least half of the text.
|
|
176
|
+
* @param {string} term
|
|
177
|
+
* @param {string} text
|
|
178
|
+
*/
|
|
179
|
+
function coversHalf(term, text) {
|
|
180
|
+
return term.length >= 4 && term.length / String(text).length >= 0.5;
|
|
181
|
+
}
|
|
182
|
+
|
|
115
183
|
/**
|
|
116
184
|
* A query with its camelCase and PascalCase identifiers spelled as words, so
|
|
117
185
|
* `SidebarToggle` reads "sidebar toggle" and `useTablePaginationState` "use
|
|
@@ -155,3 +223,27 @@ export const isTypo = (a, b, dist) =>
|
|
|
155
223
|
dist <= 3 &&
|
|
156
224
|
Math.min(a.length, b.length) >=
|
|
157
225
|
TYPO_MIN_LENGTH[/** @type {1 | 2 | 3} */ (dist)];
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* The edit distance between two words when it counts as a typo (isTypo), or
|
|
229
|
+
* null. The shorter word's length caps the distance that can count. A pair
|
|
230
|
+
* the cap rules out needs no distance table, and the others compute only the
|
|
231
|
+
* cells within the cap.
|
|
232
|
+
* @param {string} a
|
|
233
|
+
* @param {string} b
|
|
234
|
+
* @returns {1 | 2 | 3 | null}
|
|
235
|
+
*/
|
|
236
|
+
export function typoDistance(a, b) {
|
|
237
|
+
const shorter = Math.min(a.length, b.length);
|
|
238
|
+
const cap =
|
|
239
|
+
shorter >= TYPO_MIN_LENGTH[3]
|
|
240
|
+
? 3
|
|
241
|
+
: shorter >= TYPO_MIN_LENGTH[2]
|
|
242
|
+
? 2
|
|
243
|
+
: shorter >= TYPO_MIN_LENGTH[1]
|
|
244
|
+
? 1
|
|
245
|
+
: 0;
|
|
246
|
+
if (cap === 0) return null;
|
|
247
|
+
const dist = levenshteinDistance(a, b, cap);
|
|
248
|
+
return dist >= 1 && dist <= cap ? /** @type {1 | 2 | 3} */ (dist) : null;
|
|
249
|
+
}
|
package/api/search/search.d.mts
CHANGED
|
@@ -13,12 +13,14 @@
|
|
|
13
13
|
*/
|
|
14
14
|
export function search(query: string, options?: {
|
|
15
15
|
cwd?: string | undefined;
|
|
16
|
-
type?: "template" | "component" | "
|
|
16
|
+
type?: "template" | "component" | "doc" | "theme" | "hook" | undefined;
|
|
17
17
|
limit?: number | undefined;
|
|
18
18
|
}): Promise<import("./search.type.mjs").SearchResponse>;
|
|
19
19
|
/**
|
|
20
20
|
* The lexical ranker alone: keyword and fuzzy scoring of every candidate.
|
|
21
|
-
* `build` ranks from it.
|
|
21
|
+
* `build` ranks from it. It ranks the candidates search gathers, reused the
|
|
22
|
+
* same way. A later query in the same folder, for the same `type`, gathers
|
|
23
|
+
* again only when an input changed.
|
|
22
24
|
*
|
|
23
25
|
* @param {string} query
|
|
24
26
|
* @param {{cwd?: string, type?: 'component'|'hook'|'doc'|'template'|'theme', limit?: number}} [options]
|