@astryxdesign/cli 0.7.3-canary.ca48bb7 → 0.7.3-canary.cac3d8d
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/api/build/_adapter.mjs +37 -25
- package/api/build/blocks/blocks.d.mts +68 -20
- package/api/build/blocks/blocks.mjs +472 -196
- package/api/build/blocks/blocks.test.mjs +185 -168
- package/api/build/blocks/blocks.weights.json +1 -1
- package/api/build/build.type.mjs +1 -1
- package/api/build/kit/answer.d.mts +4 -1
- package/api/build/kit/answer.mjs +11 -3
- package/api/build/kit/signals.d.mts +11 -0
- package/api/build/kit/signals.mjs +8 -7
- package/api/build/kit/weights.d.mts +8 -22
- package/api/build/kit/weights.mjs +87 -8
- package/api/build/kit/weights.test.mjs +96 -0
- package/api/build/tree.mjs +2 -1
- package/api/build/tree.test.mjs +27 -27
- package/api/component/_adapter.mjs +39 -5
- package/api/discover/_adapter.d.mts +1 -2
- package/api/discover/_adapter.mjs +6 -8
- package/api/discover/discover.mjs +0 -1
- package/api/docs/_adapter.mjs +4 -0
- package/api/doctor/_adapter.d.mts +33 -13
- package/api/doctor/_adapter.mjs +55 -25
- package/api/doctor/doctor.d.mts +23 -5
- package/api/doctor/doctor.mjs +81 -16
- package/api/doctor/doctor.test.mjs +58 -0
- package/api/search/_gather-templates.d.mts +0 -1
- package/api/search/_gather-templates.mjs +25 -0
- package/api/search/search.integration-block.test.mjs +100 -0
- package/api/template/template.mjs +5 -1
- package/assets/docs/tree/ci-and-containers.doc.mjs +13 -0
- package/clients/cli/commands/doctor.doc.mjs +1 -1
- package/clients/cli/commands/outside-project.test.mjs +99 -0
- package/clients/cli/commands/setup-nudge.test.mjs +17 -0
- package/clients/cli/index.mjs +25 -8
- package/foundation/agent-docs/agent-doc-state.d.mts +12 -0
- package/foundation/agent-docs/agent-doc-state.mjs +24 -2
- package/foundation/agent-docs/agent-docs.mjs +5 -5
- package/foundation/agent-docs/computer-agent-text.d.mts +39 -2
- package/foundation/agent-docs/computer-agent-text.mjs +135 -8
- package/foundation/agent-docs/computer-agent-text.test.mjs +99 -2
- package/foundation/integrations/public-imports.mjs +1 -1
- package/foundation/release/cache.test.mjs +24 -21
- package/foundation/release/global-state.d.mts +8 -4
- package/foundation/release/global-state.mjs +4 -2
- package/foundation/release/notices.d.mts +62 -8
- package/foundation/release/notices.mjs +136 -25
- package/foundation/release/notices.test.mjs +21 -0
- package/foundation/text/string-utils.d.mts +2 -1
- package/foundation/text/string-utils.mjs +16 -5
- package/foundation/text/suggest-order.d.mts +72 -0
- package/foundation/text/suggest-order.mjs +363 -0
- package/foundation/text/suggest-order.test.mjs +259 -0
- package/package.json +9 -9
|
@@ -43,9 +43,11 @@ import {userConfigDir} from '../env/user-dirs.mjs';
|
|
|
43
43
|
import {astryxCommandsOnSearchPath} from '../env/search-path.mjs';
|
|
44
44
|
import {
|
|
45
45
|
CLI_PACKAGE,
|
|
46
|
+
commandInFolder,
|
|
46
47
|
detectPackageManager,
|
|
47
48
|
getCliInvocation,
|
|
48
49
|
} from '../env/package-manager.mjs';
|
|
50
|
+
import {findAstryxProject, findPackageRoot} from '../fs/paths.mjs';
|
|
49
51
|
import {satisfiesRange, semverCompare} from '../env/semver.mjs';
|
|
50
52
|
import {isInReleaseCache, isReleaseVersion} from './cache.mjs';
|
|
51
53
|
import {
|
|
@@ -55,7 +57,12 @@ import {
|
|
|
55
57
|
tryStateLock,
|
|
56
58
|
writeGlobalState,
|
|
57
59
|
} from './global-state.mjs';
|
|
58
|
-
import {
|
|
60
|
+
import {
|
|
61
|
+
coreVersionOf,
|
|
62
|
+
globalFolderOf,
|
|
63
|
+
isGlobalCopy,
|
|
64
|
+
projectRootOf,
|
|
65
|
+
} from './choose.mjs';
|
|
59
66
|
import {readReleaseFacts} from './project.mjs';
|
|
60
67
|
import {samePath} from '../fs/path-compare.mjs';
|
|
61
68
|
import {updateNoticesOff} from './update-notice-env.mjs';
|
|
@@ -375,16 +382,49 @@ const ADD = {
|
|
|
375
382
|
bun: 'bun add',
|
|
376
383
|
};
|
|
377
384
|
|
|
385
|
+
/**
|
|
386
|
+
* The command that adds a package to the project of a run in `cwd`, with the
|
|
387
|
+
* project's package manager (spec AST-081 FR12). Null when `cwd` belongs to
|
|
388
|
+
* no project `spec:AST-040` FR9 defines, and in a folder inside the project
|
|
389
|
+
* whose package.json is not the project's (see {@link installFolder}): a run
|
|
390
|
+
* there loads integrations from that package.json, so a package added to the
|
|
391
|
+
* project would stay unused there, and the advice is
|
|
392
|
+
* {@link RUN_FROM_PROJECT}.
|
|
393
|
+
* @param {string} cwd
|
|
394
|
+
* @returns {((name: string) => string) | null}
|
|
395
|
+
*/
|
|
396
|
+
export function projectAddCommand(cwd) {
|
|
397
|
+
const target = installFolder(cwd);
|
|
398
|
+
if (target == null || target.moved) return null;
|
|
399
|
+
const add = ADD[detectPackageManager(cwd)] ?? ADD.npm;
|
|
400
|
+
return name => `${add} ${name}`;
|
|
401
|
+
}
|
|
402
|
+
|
|
378
403
|
/**
|
|
379
404
|
* The commands that bring a project's own CLI and Core to one release, with
|
|
380
405
|
* the project's package manager: when the CLI is newer, Core up to it and then
|
|
381
406
|
* the codemods from Core's release; otherwise the CLI to Core's release.
|
|
407
|
+
* Null in a folder that belongs to no project, or whose package.json is not
|
|
408
|
+
* the project's (see {@link installFolder}).
|
|
382
409
|
* @param {{cwd: string, cli: string, core: string}} options
|
|
383
|
-
* @returns {string}
|
|
410
|
+
* @returns {string | null}
|
|
384
411
|
*/
|
|
385
412
|
export function alignCliAndCore({cwd, cli, core}) {
|
|
386
|
-
const
|
|
387
|
-
|
|
413
|
+
const target = installFolder(cwd);
|
|
414
|
+
if (target == null || target.moved) return null;
|
|
415
|
+
const root = projectRootOf(readReleaseFacts(cwd)) ?? cwd;
|
|
416
|
+
return alignIn(root, cli, core);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* The commands that bring the CLI and Core of the project at `root` to one
|
|
421
|
+
* release, run in `root`.
|
|
422
|
+
* @param {string} root
|
|
423
|
+
* @param {string} cli
|
|
424
|
+
* @param {string} core
|
|
425
|
+
* @returns {string}
|
|
426
|
+
*/
|
|
427
|
+
function alignIn(root, cli, core) {
|
|
388
428
|
const add = ADD[detectPackageManager(root)] ?? ADD.npm;
|
|
389
429
|
if (semverCompare(cli, core) > 0) {
|
|
390
430
|
return `${add} @astryxdesign/core@${cli}, then ${getCliInvocation(root, {installed: true})} upgrade --from ${core} --apply`;
|
|
@@ -392,27 +432,81 @@ export function alignCliAndCore({cwd, cli, core}) {
|
|
|
392
432
|
return `${add} ${CLI_PACKAGE}@${core}`;
|
|
393
433
|
}
|
|
394
434
|
|
|
435
|
+
/**
|
|
436
|
+
* Where a command that adds an Astryx package runs, for a run in `cwd`: in
|
|
437
|
+
* the project `spec:AST-040` FR9 defines, which stops at a repository root
|
|
438
|
+
* and never counts the home folder (spec AST-081 FR2, FR10). Null when `cwd`
|
|
439
|
+
* belongs to no such project, so no command adds anything. When `cwd`'s
|
|
440
|
+
* nearest package.json is not the project's, as in a tool folder that
|
|
441
|
+
* installs its own Core, a package manager would add to the tool's
|
|
442
|
+
* package.json, so `moved` says the command runs in the project's folder.
|
|
443
|
+
* @param {string} cwd
|
|
444
|
+
* @returns {{dir: string, moved: boolean} | null}
|
|
445
|
+
*/
|
|
446
|
+
export function installFolder(cwd) {
|
|
447
|
+
const project = findAstryxProject(cwd);
|
|
448
|
+
if (project == null) return null;
|
|
449
|
+
const nearest = findPackageRoot(cwd);
|
|
450
|
+
if (nearest == null || nearest === project) return {dir: cwd, moved: false};
|
|
451
|
+
return {dir: project, moved: true};
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* What to tell a run in a folder inside a project whose package.json is not
|
|
456
|
+
* the project's: run from the project's folder, since adding there would make
|
|
457
|
+
* the folder a project of its own (spec AST-081 FR2).
|
|
458
|
+
*/
|
|
459
|
+
export const RUN_FROM_PROJECT =
|
|
460
|
+
"Run this from the Astryx project's folder, or declare an Astryx package in this folder's package.json to make it a project of its own.";
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* The command that adds the CLI at Core's version, for a run in `cwd` whose
|
|
464
|
+
* Core is `core`, with the project's package manager in the project root.
|
|
465
|
+
* `command` is null in a folder inside the project whose package.json is not
|
|
466
|
+
* the project's (see {@link installFolder}), where the advice is
|
|
467
|
+
* {@link RUN_FROM_PROJECT}. Null when the folder belongs to no project.
|
|
468
|
+
* @param {{cwd: string, core: string}} options
|
|
469
|
+
* @returns {{root: string, core: string, command: string | null} | null}
|
|
470
|
+
*/
|
|
471
|
+
export function cliInstallAdvice({cwd, core}) {
|
|
472
|
+
const target = installFolder(cwd);
|
|
473
|
+
if (target == null) return null;
|
|
474
|
+
if (target.moved) return {root: target.dir, core, command: null};
|
|
475
|
+
const root = projectRootOf(readReleaseFacts(cwd)) ?? cwd;
|
|
476
|
+
return {root, core, command: addCliCommand(root, core)};
|
|
477
|
+
}
|
|
478
|
+
|
|
395
479
|
/**
|
|
396
480
|
* The hint for a project with no CLI of its own, answered by `answered` while
|
|
397
481
|
* its Core is `core`: the command that adds the CLI at Core's version, with
|
|
398
|
-
* the project's package manager.
|
|
482
|
+
* the project's package manager (see {@link cliInstallAdvice}). Null when no
|
|
483
|
+
* command fits, or when the project the command adds to already matches.
|
|
399
484
|
* @param {{cwd: string, answered: string, core: string}} options
|
|
400
|
-
* @returns {{root: string, line: string}}
|
|
485
|
+
* @returns {{root: string, line: string} | null}
|
|
401
486
|
*/
|
|
402
487
|
export function noCliHint({cwd, answered, core}) {
|
|
403
|
-
|
|
404
|
-
|
|
488
|
+
if (core === answered) return null;
|
|
489
|
+
const advice = cliInstallAdvice({cwd, core});
|
|
490
|
+
if (advice == null) return null;
|
|
491
|
+
return {
|
|
492
|
+
root: advice.root,
|
|
493
|
+
line: noCliHintLine(answered, core, advice.command),
|
|
494
|
+
};
|
|
405
495
|
}
|
|
406
496
|
|
|
407
497
|
/**
|
|
408
498
|
* The hint's text.
|
|
409
499
|
* @param {string} answered
|
|
410
500
|
* @param {string} core
|
|
411
|
-
* @param {string} command the command that adds the CLI at Core's
|
|
501
|
+
* @param {string | null} command the command that adds the CLI at Core's
|
|
502
|
+
* version; null in a folder whose package.json is not the project's
|
|
412
503
|
* @returns {string}
|
|
413
504
|
*/
|
|
414
505
|
export function noCliHintLine(answered, core, command) {
|
|
415
|
-
|
|
506
|
+
const head = `astryx: this project has no Astryx CLI installed; answered by CLI ${answered} while its Core is ${core}.`;
|
|
507
|
+
return command
|
|
508
|
+
? `${head} To match, run: ${command}`
|
|
509
|
+
: `${head} ${RUN_FROM_PROJECT}`;
|
|
416
510
|
}
|
|
417
511
|
|
|
418
512
|
/**
|
|
@@ -432,17 +526,29 @@ export function addCliCommand(root, version) {
|
|
|
432
526
|
* @param {{cwd: string, current: string, stateDir?: string}} options
|
|
433
527
|
* @returns {ProjectLag | null}
|
|
434
528
|
*/
|
|
435
|
-
export function projectLag({cwd, current, stateDir = userConfigDir()}) {
|
|
529
|
+
export function projectLag({cwd, current: given, stateDir = userConfigDir()}) {
|
|
436
530
|
const latest = knownLatest(stateDir);
|
|
437
|
-
if (!latest
|
|
438
|
-
const newest = latest.version;
|
|
531
|
+
if (!latest) return null;
|
|
439
532
|
const facts = readReleaseFacts(cwd);
|
|
440
533
|
if (!facts.inProject) return null;
|
|
441
|
-
const
|
|
534
|
+
const target = installFolder(cwd);
|
|
535
|
+
if (target == null) return null;
|
|
536
|
+
const root = target.moved ? target.dir : (projectRootOf(facts) ?? cwd);
|
|
537
|
+
// From a folder inside the project, the project's own release: its CLI's,
|
|
538
|
+
// else its Core's, so the project gets one notice and one --from.
|
|
539
|
+
const projectFacts = target.moved ? readReleaseFacts(root) : null;
|
|
540
|
+
const current = projectFacts
|
|
541
|
+
? (projectFacts.cli?.version ?? coreVersionOf(projectFacts) ?? given)
|
|
542
|
+
: given;
|
|
543
|
+
if (!isBehind(current, latest.version)) return null;
|
|
544
|
+
const newest = latest.version;
|
|
442
545
|
const pm = detectPackageManager(root);
|
|
443
546
|
// The CLI is always installed beside Core: a project that installed only
|
|
444
547
|
// Core gets it too, as recommended, so its version is pinned with Core's.
|
|
445
|
-
|
|
548
|
+
// From a folder inside the project whose package.json is not the
|
|
549
|
+
// project's, the install runs in the project's folder (see installFolder).
|
|
550
|
+
const add = `${ADD[pm] ?? ADD.npm} @astryxdesign/core@${newest} ${CLI_PACKAGE}@${newest}`;
|
|
551
|
+
const install = target.moved ? commandInFolder(root, add) : add;
|
|
446
552
|
// The command runs after the install above, so the picker's guess is the
|
|
447
553
|
// project's own CLI (spec AST-081 FR5).
|
|
448
554
|
const stem = getCliInvocation(root, {installed: true});
|
|
@@ -452,7 +558,9 @@ export function projectLag({cwd, current, stateDir = userConfigDir()}) {
|
|
|
452
558
|
newest,
|
|
453
559
|
node: latest.node,
|
|
454
560
|
install,
|
|
455
|
-
upgrade:
|
|
561
|
+
upgrade: target.moved
|
|
562
|
+
? commandInFolder(root, `${stem} upgrade --from ${current} --apply`)
|
|
563
|
+
: `${stem} upgrade --from ${current} --apply`,
|
|
456
564
|
};
|
|
457
565
|
}
|
|
458
566
|
|
|
@@ -536,18 +644,13 @@ export function noticeLines({
|
|
|
536
644
|
try {
|
|
537
645
|
// A project with no CLI of its own, answered by a release other than its
|
|
538
646
|
// Core's: once a day per project, how to match them (FR2).
|
|
539
|
-
if (
|
|
540
|
-
choice.inProject &&
|
|
541
|
-
choice.copy === 'starting' &&
|
|
542
|
-
choice.coreVersion &&
|
|
543
|
-
choice.coreVersion !== choice.version
|
|
544
|
-
) {
|
|
647
|
+
if (choice.inProject && choice.copy === 'starting' && choice.coreVersion) {
|
|
545
648
|
const hint = noCliHint({
|
|
546
649
|
cwd,
|
|
547
650
|
answered: choice.version,
|
|
548
651
|
core: choice.coreVersion,
|
|
549
652
|
});
|
|
550
|
-
if (take(`no-cli:${hint.root}`)) lines.push(hint.line);
|
|
653
|
+
if (hint && take(`no-cli:${hint.root}`)) lines.push(hint.line);
|
|
551
654
|
}
|
|
552
655
|
} catch {
|
|
553
656
|
// A hint never fails a run.
|
|
@@ -559,8 +662,16 @@ export function noticeLines({
|
|
|
559
662
|
choice.copy === 'starting' && choice.coreVersion
|
|
560
663
|
? choice.coreVersion
|
|
561
664
|
: choice.version;
|
|
562
|
-
|
|
563
|
-
|
|
665
|
+
// A folder that belongs to no project (spec AST-040 FR9) gets no
|
|
666
|
+
// project notice; the skip says why.
|
|
667
|
+
const noProject = installFolder(cwd) == null;
|
|
668
|
+
const lag = noProject ? null : projectLag({cwd, current, stateDir});
|
|
669
|
+
if (!lag) {
|
|
670
|
+
recordNoticeSkip('project', noProject ? 'no-project' : 'no-newer', {
|
|
671
|
+
stateDir,
|
|
672
|
+
now,
|
|
673
|
+
});
|
|
674
|
+
}
|
|
564
675
|
if (lag && take(`project:${lag.root}`)) {
|
|
565
676
|
lines.push(
|
|
566
677
|
availableLine(lag.current, lag.newest),
|
|
@@ -355,6 +355,27 @@ describe('globalBehind and projectLag', () => {
|
|
|
355
355
|
});
|
|
356
356
|
});
|
|
357
357
|
|
|
358
|
+
describe('projectLag from a tool folder inside a project', () => {
|
|
359
|
+
it("uses the project's own CLI release, so the project gets one notice and one --from", () => {
|
|
360
|
+
const stateDir = checked('0.7.3');
|
|
361
|
+
const app = project(tempDir(), {
|
|
362
|
+
'@astryxdesign/core': '0.7.1',
|
|
363
|
+
'@astryxdesign/cli': '0.7.2',
|
|
364
|
+
});
|
|
365
|
+
writeJson(path.join(app, 'package-lock.json'), {lockfileVersion: 3});
|
|
366
|
+
installCore(app, '0.7.1');
|
|
367
|
+
installStandInCli(app, '0.7.2');
|
|
368
|
+
const tool = path.join(app, 'tools', 'codegen');
|
|
369
|
+
writeJson(path.join(tool, 'package.json'), {name: 'codegen'});
|
|
370
|
+
installCore(tool, '0.7.0');
|
|
371
|
+
|
|
372
|
+
const fromApp = projectLag({cwd: app, current: '0.7.2', stateDir});
|
|
373
|
+
const fromTool = projectLag({cwd: tool, current: '0.7.0', stateDir});
|
|
374
|
+
expect(fromTool).toMatchObject({root: app, current: '0.7.2'});
|
|
375
|
+
expect(fromTool?.upgrade).toBe(`cd ${app} && ${fromApp?.upgrade}`);
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
|
|
358
379
|
describe('the commands notices print go through the command-name picker (spec AST-081 FR5)', () => {
|
|
359
380
|
/** A Core-only npm project behind the newest release. */
|
|
360
381
|
const coreOnlyProject = () => {
|
|
@@ -28,7 +28,8 @@ export function findClosestComponents(name: string, components: Record<string, s
|
|
|
28
28
|
* 30 keyword Levenshtein distance 2
|
|
29
29
|
* 20 name Levenshtein distance 3
|
|
30
30
|
*
|
|
31
|
-
* Each result: { name, score, reason }
|
|
31
|
+
* Each result: { name, score, reason }, plus `keywordAt` when a keyword set
|
|
32
|
+
* the component's score: the position of the keyword that set it.
|
|
32
33
|
*
|
|
33
34
|
* @param {string} needle
|
|
34
35
|
* @param {string} coreDir
|
|
@@ -48,7 +48,8 @@ export function findClosestComponents(name, components, maxDistance = 3) {
|
|
|
48
48
|
* 30 keyword Levenshtein distance 2
|
|
49
49
|
* 20 name Levenshtein distance 3
|
|
50
50
|
*
|
|
51
|
-
* Each result: { name, score, reason }
|
|
51
|
+
* Each result: { name, score, reason }, plus `keywordAt` when a keyword set
|
|
52
|
+
* the component's score: the position of the keyword that set it.
|
|
52
53
|
*
|
|
53
54
|
* @param {string} needle
|
|
54
55
|
* @param {string} coreDir
|
|
@@ -64,6 +65,9 @@ export async function searchComponents(needle, coreDir, components) {
|
|
|
64
65
|
const allNames = Object.values(components).flat();
|
|
65
66
|
/** @type {Map<string, {name: string, score: number, reason: string}>} */
|
|
66
67
|
const scored = new Map();
|
|
68
|
+
/** Position of the keyword that set each component's score. */
|
|
69
|
+
/** @type {Map<string, number>} */
|
|
70
|
+
const keywordAt = new Map();
|
|
67
71
|
|
|
68
72
|
/**
|
|
69
73
|
* @param {string} name
|
|
@@ -146,12 +150,14 @@ export async function searchComponents(needle, coreDir, components) {
|
|
|
146
150
|
|
|
147
151
|
// Keyword matching
|
|
148
152
|
if (docs.keywords && Array.isArray(docs.keywords)) {
|
|
149
|
-
for (const kw of docs.keywords) {
|
|
153
|
+
for (const [at, kw] of docs.keywords.entries()) {
|
|
150
154
|
const kwLower = kw.toLowerCase();
|
|
155
|
+
const before = scored.get(comp)?.score ?? 0;
|
|
151
156
|
|
|
152
157
|
// Exact keyword
|
|
153
158
|
if (kwLower === term) {
|
|
154
159
|
addMatch(comp, 90, 'keyword "' + kw + '"');
|
|
160
|
+
if (!keywordAt.has(comp) || before < 90) keywordAt.set(comp, at);
|
|
155
161
|
break;
|
|
156
162
|
}
|
|
157
163
|
|
|
@@ -170,6 +176,7 @@ export async function searchComponents(needle, coreDir, components) {
|
|
|
170
176
|
addMatch(comp, 70, 'keyword "' + kw + '" (distance ' + dist + ')');
|
|
171
177
|
else if (dist === 2)
|
|
172
178
|
addMatch(comp, 30, 'keyword "' + kw + '" (distance ' + dist + ')');
|
|
179
|
+
if ((scored.get(comp)?.score ?? 0) > before) keywordAt.set(comp, at);
|
|
173
180
|
}
|
|
174
181
|
}
|
|
175
182
|
|
|
@@ -202,9 +209,13 @@ export async function searchComponents(needle, coreDir, components) {
|
|
|
202
209
|
}
|
|
203
210
|
}
|
|
204
211
|
|
|
205
|
-
const results = Array.from(scored.values())
|
|
206
|
-
(
|
|
207
|
-
|
|
212
|
+
const results = Array.from(scored.values())
|
|
213
|
+
.map(r =>
|
|
214
|
+
keywordAt.has(r.name)
|
|
215
|
+
? {...r, keywordAt: /** @type {number} */ (keywordAt.get(r.name))}
|
|
216
|
+
: r,
|
|
217
|
+
)
|
|
218
|
+
.sort((a, b) => b.score - a.score || a.name.localeCompare(b.name));
|
|
208
219
|
|
|
209
220
|
return results;
|
|
210
221
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A name's words, lowercase and singular: camelCase, PascalCase, kebab-case,
|
|
6
|
+
* snake_case, slashes and spaces all split.
|
|
7
|
+
* @param {string} text
|
|
8
|
+
* @returns {string[]}
|
|
9
|
+
*/
|
|
10
|
+
export function nameWords(text: string): string[];
|
|
11
|
+
/**
|
|
12
|
+
* The same items, closest to the typed name first; each item is as close as
|
|
13
|
+
* its closest name. Equal matches keep their original order.
|
|
14
|
+
* @template T
|
|
15
|
+
* @param {string} typedName
|
|
16
|
+
* @param {T[]} items
|
|
17
|
+
* @param {(item: T) => Array<string | undefined>} namesOf
|
|
18
|
+
* @returns {T[]}
|
|
19
|
+
*/
|
|
20
|
+
export function orderByAffinity<T>(typedName: string, items: T[], namesOf: (item: T) => Array<string | undefined>): T[];
|
|
21
|
+
/**
|
|
22
|
+
* Docs route suggestions, closest to the typed route first. When every
|
|
23
|
+
* suggestion sits under one namespace the typed route also starts with, that
|
|
24
|
+
* shared part is left out of the comparison: it says nothing about which page
|
|
25
|
+
* was meant. Equal matches keep their order.
|
|
26
|
+
* @template {{name: string}} T
|
|
27
|
+
* @param {string} topic - the typed route
|
|
28
|
+
* @param {T[]} suggestions
|
|
29
|
+
* @returns {T[]}
|
|
30
|
+
*/
|
|
31
|
+
export function orderRouteSuggestions<T extends {
|
|
32
|
+
name: string;
|
|
33
|
+
}>(topic: string, suggestions: T[]): T[];
|
|
34
|
+
/**
|
|
35
|
+
* The components whose synonyms name what was typed. A synonym matches when
|
|
36
|
+
* its words, with or without a leading library name, are the typed words
|
|
37
|
+
* (`MUI TextField` matches `MUI TextField`, `TextField` and `text-field`).
|
|
38
|
+
* @param {string} needle
|
|
39
|
+
* @param {Record<string, {synonyms?: string[]}>} cards - component name → its search card
|
|
40
|
+
* @returns {Set<string>}
|
|
41
|
+
*/
|
|
42
|
+
export function synonymMatches(needle: string, cards: Record<string, {
|
|
43
|
+
synonyms?: string[];
|
|
44
|
+
}>): Set<string>;
|
|
45
|
+
/**
|
|
46
|
+
* Rank component suggestions for a name that resolved to nothing.
|
|
47
|
+
*
|
|
48
|
+
* Every component `searchComponents` scored keeps its score. A component whose
|
|
49
|
+
* name has exactly the typed words (`chat-messages` for `ChatMessage`) scores
|
|
50
|
+
* like an exact name; one of whose synonyms is the typed name (see
|
|
51
|
+
* {@link synonymMatches}) like an exact keyword; one whose name shares the
|
|
52
|
+
* typed compound name's words (see {@link compoundMatch}) just below a
|
|
53
|
+
* one-letter typo of a name. Equal scores put synonym matches first, then order by how many of the typed words the
|
|
54
|
+
* name carries, then by how early the keyword that matched sits in the
|
|
55
|
+
* component's keywords, then by edit distance, then by shared leading letters,
|
|
56
|
+
* then by name. The caller decides how many to print.
|
|
57
|
+
* @param {string} needle - the typed component name (no `XDS` prefix)
|
|
58
|
+
* @param {Array<{name: string, score: number, reason: string, keywordAt?: number}>} results - `searchComponents` output
|
|
59
|
+
* @param {string[]} allNames - every component name
|
|
60
|
+
* @param {Set<string>} [synonyms] - {@link synonymMatches} for the typed name
|
|
61
|
+
* @returns {Array<{name: string, score: number, reason: string}>}
|
|
62
|
+
*/
|
|
63
|
+
export function rankComponentSuggestions(needle: string, results: Array<{
|
|
64
|
+
name: string;
|
|
65
|
+
score: number;
|
|
66
|
+
reason: string;
|
|
67
|
+
keywordAt?: number;
|
|
68
|
+
}>, allNames: string[], synonyms?: Set<string>): Array<{
|
|
69
|
+
name: string;
|
|
70
|
+
score: number;
|
|
71
|
+
reason: string;
|
|
72
|
+
}>;
|