@hop-top/kit 0.4.0-alpha.1
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 +86 -0
- package/LICENSE +25 -0
- package/README.md +189 -0
- package/dist/aim.d.ts +116 -0
- package/dist/aim.js +417 -0
- package/dist/alias.d.ts +73 -0
- package/dist/alias.js +207 -0
- package/dist/api.d.ts +62 -0
- package/dist/api.js +165 -0
- package/dist/auth.d.ts +26 -0
- package/dist/auth.js +41 -0
- package/dist/cli.d.ts +309 -0
- package/dist/cli.js +885 -0
- package/dist/config.d.ts +97 -0
- package/dist/config.js +79 -0
- package/dist/errcorrect.d.ts +37 -0
- package/dist/errcorrect.js +69 -0
- package/dist/llm.d.ts +188 -0
- package/dist/llm.js +356 -0
- package/dist/output.d.ts +213 -0
- package/dist/output.js +447 -0
- package/dist/progress.d.ts +30 -0
- package/dist/progress.js +56 -0
- package/dist/provenance.d.ts +24 -0
- package/dist/provenance.js +32 -0
- package/dist/routellm.d.ts +64 -0
- package/dist/routellm.js +258 -0
- package/dist/rpc.d.ts +25 -0
- package/dist/rpc.js +101 -0
- package/dist/safety.d.ts +24 -0
- package/dist/safety.js +44 -0
- package/dist/scope.d.ts +121 -0
- package/dist/scope.js +380 -0
- package/dist/sqlstore.d.ts +84 -0
- package/dist/sqlstore.js +85 -0
- package/dist/stream.d.ts +35 -0
- package/dist/stream.js +52 -0
- package/dist/tui/index.d.ts +300 -0
- package/dist/tui/index.js +332 -0
- package/dist/upgrade.d.ts +95 -0
- package/dist/upgrade.js +115 -0
- package/dist/xdg.d.ts +169 -0
- package/dist/xdg.js +129 -0
- package/eslint.config.mjs +17 -0
- package/package.json +133 -0
- package/src/README.md +3 -0
- package/src/aim.test.ts +331 -0
- package/src/aim.ts +388 -0
- package/src/alias.test.ts +423 -0
- package/src/alias.ts +256 -0
- package/src/api.test.ts +190 -0
- package/src/api.ts +214 -0
- package/src/auth.test.ts +24 -0
- package/src/auth.ts +37 -0
- package/src/bus.test.ts +178 -0
- package/src/bus.ts +114 -0
- package/src/cli.test.ts +690 -0
- package/src/cli.ts +741 -0
- package/src/completion-values.test.ts +202 -0
- package/src/completion-values.ts +173 -0
- package/src/completion.test.ts +212 -0
- package/src/completion.ts +158 -0
- package/src/compliance.test.ts +134 -0
- package/src/compliance.ts +669 -0
- package/src/config.test.ts +110 -0
- package/src/config.ts +164 -0
- package/src/errcorrect.test.ts +134 -0
- package/src/errcorrect.ts +84 -0
- package/src/flagregister.test.ts +103 -0
- package/src/flagregister.ts +78 -0
- package/src/gen/crud_connect.ts +76 -0
- package/src/gen/crud_pb.ts +269 -0
- package/src/hint.test.ts +315 -0
- package/src/hint.ts +178 -0
- package/src/llm.test.ts +612 -0
- package/src/llm.ts +577 -0
- package/src/log.test.ts +145 -0
- package/src/log.ts +155 -0
- package/src/output/builtins.ts +34 -0
- package/src/output/dispatch.ts +195 -0
- package/src/output/flags.ts +151 -0
- package/src/output/format_help.ts +80 -0
- package/src/output/formatter.ts +167 -0
- package/src/output/formatters/csv.ts +72 -0
- package/src/output/formatters/json.ts +44 -0
- package/src/output/formatters/table.ts +44 -0
- package/src/output/formatters/text.ts +109 -0
- package/src/output/formatters/yaml.ts +47 -0
- package/src/output/projection.ts +126 -0
- package/src/output/registry.ts +88 -0
- package/src/output/template.ts +63 -0
- package/src/output.test.ts +117 -0
- package/src/output.ts +90 -0
- package/src/progress.test.ts +93 -0
- package/src/progress.ts +58 -0
- package/src/provenance.test.ts +59 -0
- package/src/provenance.ts +26 -0
- package/src/routellm.test.ts +179 -0
- package/src/routellm.ts +365 -0
- package/src/router/bert.test.ts +180 -0
- package/src/router/bert.ts +145 -0
- package/src/router/controller.test.ts +183 -0
- package/src/router/controller.ts +165 -0
- package/src/router/integration.test.ts +309 -0
- package/src/router/intent.test.ts +187 -0
- package/src/router/intent.ts +208 -0
- package/src/router/mf.test.ts +66 -0
- package/src/router/mf.ts +52 -0
- package/src/router/random.test.ts +23 -0
- package/src/router/random.ts +13 -0
- package/src/router/router.test.ts +31 -0
- package/src/router/router.ts +62 -0
- package/src/router/server.test.ts +193 -0
- package/src/router/server.ts +134 -0
- package/src/router/sw.test.ts +199 -0
- package/src/router/sw.ts +232 -0
- package/src/rpc.test.ts +47 -0
- package/src/rpc.ts +91 -0
- package/src/safety.test.ts +53 -0
- package/src/safety.ts +42 -0
- package/src/scope-defaults.json +72 -0
- package/src/scope.test.ts +177 -0
- package/src/scope.ts +382 -0
- package/src/setflag.test.ts +110 -0
- package/src/setflag.ts +102 -0
- package/src/sqlstore.test.ts +110 -0
- package/src/sqlstore.ts +144 -0
- package/src/stream.test.ts +69 -0
- package/src/stream.ts +47 -0
- package/src/textflag.test.ts +105 -0
- package/src/textflag.ts +68 -0
- package/src/toolspec.test.ts +187 -0
- package/src/toolspec.ts +279 -0
- package/src/triton/client.test.ts +205 -0
- package/src/triton/client.ts +261 -0
- package/src/tui/anim.test.ts +146 -0
- package/src/tui/anim.ts +134 -0
- package/src/tui/badge.test.ts +41 -0
- package/src/tui/badge.ts +55 -0
- package/src/tui/confirm.test.ts +68 -0
- package/src/tui/confirm.ts +49 -0
- package/src/tui/index.ts +29 -0
- package/src/tui/list.test.ts +84 -0
- package/src/tui/list.ts +72 -0
- package/src/tui/parity.ts +41 -0
- package/src/tui/pills.test.ts +40 -0
- package/src/tui/pills.ts +43 -0
- package/src/tui/progress.test.ts +164 -0
- package/src/tui/progress.ts +120 -0
- package/src/tui/spinner.test.ts +111 -0
- package/src/tui/spinner.ts +96 -0
- package/src/tui/status.test.ts +68 -0
- package/src/tui/status.ts +66 -0
- package/src/upgrade.test.ts +298 -0
- package/src/upgrade.ts +205 -0
- package/src/uri.ts +199 -0
- package/src/wizard.test.ts +441 -0
- package/src/wizard.ts +662 -0
- package/src/xdg.test.ts +202 -0
- package/src/xdg.ts +280 -0
- package/test/output/cols.test.ts +148 -0
- package/test/output/csv.test.ts +129 -0
- package/test/output/dispatch.test.ts +194 -0
- package/test/output/format_help.test.ts +131 -0
- package/test/output/formatter.test.ts +137 -0
- package/test/output/output_flag.test.ts +124 -0
- package/test/output/registry.test.ts +127 -0
- package/test/output/smoke-capture.ts +83 -0
- package/test/output/smoke.test.ts +142 -0
- package/test/output/template.test.ts +95 -0
- package/test/output/text.test.ts +75 -0
- package/test/testdata/api-fixture.json +115 -0
- package/test/testdata/query-vectors.json +187 -0
- package/tsconfig.json +12 -0
package/src/upgrade.ts
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* Version check and notify — compares the running tool version against the
|
|
5
|
+
* latest GitHub release and writes a human-readable upgrade notice to any
|
|
6
|
+
* {@link https://nodejs.org/api/stream.html#class-streamwritable | Writable}
|
|
7
|
+
* stream when a newer release is available.
|
|
8
|
+
*
|
|
9
|
+
* ### Cache behaviour
|
|
10
|
+
* Results are persisted to `{stateDir}/.upgrade-{name}-cache.json`.
|
|
11
|
+
* The cache stores `{ version, checkedAt }`. On the next call within `cacheTTL`
|
|
12
|
+
* milliseconds the remote API is not contacted; the cached version is used
|
|
13
|
+
* directly. After the TTL expires the cache is refreshed on the next call.
|
|
14
|
+
* Cache I/O errors are swallowed — a stale or missing cache simply causes a
|
|
15
|
+
* fresh fetch.
|
|
16
|
+
*
|
|
17
|
+
* ### Error handling philosophy
|
|
18
|
+
* Version checking is a best-effort, non-critical operation. Any failure —
|
|
19
|
+
* network error, bad JSON, HTTP error, filesystem error, invalid semver — is
|
|
20
|
+
* silently discarded. The function always resolves without throwing. If
|
|
21
|
+
* something goes wrong the user sees neither a notice nor an error.
|
|
22
|
+
*
|
|
23
|
+
* ### Notice format
|
|
24
|
+
* ```
|
|
25
|
+
* \nA new release of {name} is available: v{current} → v{latest}\nhttps://github.com/{owner}/{repo}/releases/latest\n
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* ### Usage example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { createChecker } from '@hop-top/kit/upgrade';
|
|
31
|
+
*
|
|
32
|
+
* const checker = createChecker({
|
|
33
|
+
* name: 'my-cli',
|
|
34
|
+
* currentVersion: '1.2.3',
|
|
35
|
+
* owner: 'myorg',
|
|
36
|
+
* repo: 'my-cli',
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* // At the end of your CLI command:
|
|
40
|
+
* await checker.notifyIfAvailable(process.stderr);
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
import * as fs from 'fs';
|
|
45
|
+
import * as os from 'os';
|
|
46
|
+
import * as path from 'path';
|
|
47
|
+
import semver from 'semver';
|
|
48
|
+
|
|
49
|
+
// ─── Public types ─────────────────────────────────────────────────────────────
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Static configuration for a version {@link Checker}.
|
|
53
|
+
*/
|
|
54
|
+
export interface CheckerOptions {
|
|
55
|
+
/** Human-readable tool name shown in the upgrade notice. */
|
|
56
|
+
name: string;
|
|
57
|
+
/** Currently running version string (semver, without leading `v`). */
|
|
58
|
+
currentVersion: string;
|
|
59
|
+
/** GitHub organisation or username that owns the repository. */
|
|
60
|
+
owner: string;
|
|
61
|
+
/** GitHub repository name. */
|
|
62
|
+
repo: string;
|
|
63
|
+
/**
|
|
64
|
+
* How long (ms) a cached result stays valid before a fresh fetch is made.
|
|
65
|
+
* @defaultValue 86_400_000 (24 hours)
|
|
66
|
+
*/
|
|
67
|
+
cacheTTL?: number;
|
|
68
|
+
/**
|
|
69
|
+
* Directory used to store the cache file.
|
|
70
|
+
* @defaultValue `os.tmpdir()`
|
|
71
|
+
*/
|
|
72
|
+
stateDir?: string;
|
|
73
|
+
/**
|
|
74
|
+
* HTTP request timeout in milliseconds.
|
|
75
|
+
* @defaultValue 10_000
|
|
76
|
+
*/
|
|
77
|
+
timeout?: number;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Returned by {@link createChecker}. Call {@link Checker.notifyIfAvailable}
|
|
82
|
+
* at the end of a CLI command to surface upgrade notices non-intrusively.
|
|
83
|
+
*/
|
|
84
|
+
export interface Checker {
|
|
85
|
+
/**
|
|
86
|
+
* Checks for a newer GitHub release and writes a one-line notice to `out`
|
|
87
|
+
* if one is available. Silently swallows all errors.
|
|
88
|
+
*
|
|
89
|
+
* @param out - Any Node.js writable stream (e.g. `process.stderr`).
|
|
90
|
+
*/
|
|
91
|
+
notifyIfAvailable(out: NodeJS.WritableStream): Promise<void>;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// ─── Internal types ───────────────────────────────────────────────────────────
|
|
95
|
+
|
|
96
|
+
interface CacheEntry {
|
|
97
|
+
version: string;
|
|
98
|
+
checkedAt: number;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// ─── Implementation ───────────────────────────────────────────────────────────
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Creates a {@link Checker} configured with the provided options.
|
|
105
|
+
*
|
|
106
|
+
* The checker is stateless beyond what is persisted in the cache file; it is
|
|
107
|
+
* safe to create multiple instances with the same options.
|
|
108
|
+
*
|
|
109
|
+
* @param opts - Configuration options; see {@link CheckerOptions}.
|
|
110
|
+
* @returns A {@link Checker} ready to call.
|
|
111
|
+
*/
|
|
112
|
+
export function createChecker(opts: CheckerOptions): Checker {
|
|
113
|
+
const {
|
|
114
|
+
name,
|
|
115
|
+
currentVersion,
|
|
116
|
+
owner,
|
|
117
|
+
repo,
|
|
118
|
+
cacheTTL = 24 * 60 * 60 * 1000,
|
|
119
|
+
stateDir = os.tmpdir(),
|
|
120
|
+
timeout = 10_000,
|
|
121
|
+
} = opts;
|
|
122
|
+
|
|
123
|
+
const cacheFile = path.join(stateDir, `.upgrade-${name}-cache.json`);
|
|
124
|
+
const releaseURL = `https://api.github.com/repos/${owner}/${repo}/releases/latest`;
|
|
125
|
+
const releasesPageURL = `https://github.com/${owner}/${repo}/releases/latest`;
|
|
126
|
+
|
|
127
|
+
// ── cache helpers ──────────────────────────────────────────────────────────
|
|
128
|
+
|
|
129
|
+
function readCache(): CacheEntry | null {
|
|
130
|
+
try {
|
|
131
|
+
const raw = fs.readFileSync(cacheFile, 'utf8');
|
|
132
|
+
const parsed = JSON.parse(raw) as CacheEntry;
|
|
133
|
+
if (typeof parsed.version === 'string' && typeof parsed.checkedAt === 'number') {
|
|
134
|
+
return parsed;
|
|
135
|
+
}
|
|
136
|
+
} catch {
|
|
137
|
+
// Missing or malformed cache — treat as miss.
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function writeCache(version: string): void {
|
|
143
|
+
try {
|
|
144
|
+
const entry: CacheEntry = { version, checkedAt: Date.now() };
|
|
145
|
+
fs.writeFileSync(cacheFile, JSON.stringify(entry), 'utf8');
|
|
146
|
+
} catch {
|
|
147
|
+
// Cache write failure is non-fatal.
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// ── fetch latest version ───────────────────────────────────────────────────
|
|
152
|
+
|
|
153
|
+
async function fetchLatestVersion(): Promise<string | null> {
|
|
154
|
+
const controller = new AbortController();
|
|
155
|
+
const timer = setTimeout(() => controller.abort(), timeout);
|
|
156
|
+
try {
|
|
157
|
+
const res = await fetch(releaseURL, {
|
|
158
|
+
signal: controller.signal,
|
|
159
|
+
headers: { Accept: 'application/vnd.github+json' },
|
|
160
|
+
});
|
|
161
|
+
if (!res.ok) return null;
|
|
162
|
+
const body = (await res.json()) as { tag_name?: string };
|
|
163
|
+
const tag = body.tag_name;
|
|
164
|
+
if (typeof tag !== 'string') return null;
|
|
165
|
+
// Strip leading 'v' so semver.gt works with or without prefix.
|
|
166
|
+
return tag.replace(/^v/, '');
|
|
167
|
+
} finally {
|
|
168
|
+
clearTimeout(timer);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// ── notifyIfAvailable ──────────────────────────────────────────────────────
|
|
173
|
+
|
|
174
|
+
async function notifyIfAvailable(out: NodeJS.WritableStream): Promise<void> {
|
|
175
|
+
try {
|
|
176
|
+
let latestVersion: string | null = null;
|
|
177
|
+
|
|
178
|
+
// Check cache first.
|
|
179
|
+
const cached = readCache();
|
|
180
|
+
if (cached !== null && Date.now() - cached.checkedAt < cacheTTL) {
|
|
181
|
+
latestVersion = cached.version;
|
|
182
|
+
} else {
|
|
183
|
+
latestVersion = await fetchLatestVersion();
|
|
184
|
+
if (latestVersion !== null) {
|
|
185
|
+
writeCache(latestVersion);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (latestVersion === null) return;
|
|
190
|
+
|
|
191
|
+
// Only notify when latest is strictly greater than current.
|
|
192
|
+
if (!semver.gt(latestVersion, currentVersion)) return;
|
|
193
|
+
|
|
194
|
+
const notice =
|
|
195
|
+
`\nA new release of ${name} is available: v${currentVersion} → v${latestVersion}\n` +
|
|
196
|
+
`${releasesPageURL}\n`;
|
|
197
|
+
|
|
198
|
+
out.write(notice);
|
|
199
|
+
} catch {
|
|
200
|
+
// Any unexpected error is silently swallowed.
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return { notifyIfAvailable };
|
|
205
|
+
}
|
package/src/uri.ts
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin facade over @hop-top/uri for kit SDK consumers.
|
|
3
|
+
*
|
|
4
|
+
* The URI implementation lives in @hop-top/uri; this module only adapts the
|
|
5
|
+
* kit-facing helper names used by the Go URI command group.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface URI {
|
|
9
|
+
readonly scheme: string;
|
|
10
|
+
readonly namespace: string;
|
|
11
|
+
readonly id: string;
|
|
12
|
+
readonly query: string;
|
|
13
|
+
readonly fragment: string;
|
|
14
|
+
readonly original: string;
|
|
15
|
+
readonly action: string;
|
|
16
|
+
canonical(): string;
|
|
17
|
+
vanity(): string;
|
|
18
|
+
toString(): string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface VanityAlias {
|
|
22
|
+
from: string;
|
|
23
|
+
to: string;
|
|
24
|
+
prefix?: boolean;
|
|
25
|
+
preserveSuffix?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ActionRoute {
|
|
29
|
+
command: string;
|
|
30
|
+
args?: string[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface ResolvedAction {
|
|
34
|
+
action: string;
|
|
35
|
+
command: string;
|
|
36
|
+
args: string[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface Policy {
|
|
40
|
+
defaultNamespaceSegments?: number;
|
|
41
|
+
schemeNamespaceSegments?: Record<string, number>;
|
|
42
|
+
vanityAliases?: VanityAlias[];
|
|
43
|
+
actionRoutes?: Record<string, ActionRoute>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface ParseOptions {
|
|
47
|
+
strict?: boolean;
|
|
48
|
+
jsonAmbiguity?: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface VanityCandidate {
|
|
52
|
+
from: string;
|
|
53
|
+
to: string;
|
|
54
|
+
distance: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type Parser = (input: string) => URI;
|
|
58
|
+
export type Completer = (prefix: string) => string[] | Promise<string[]>;
|
|
59
|
+
|
|
60
|
+
export interface TypeRegistration {
|
|
61
|
+
name: string;
|
|
62
|
+
parser?: Parser;
|
|
63
|
+
completer?: Completer;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface Registry {
|
|
67
|
+
register(reg: TypeRegistration): void;
|
|
68
|
+
parse(input: string): URI;
|
|
69
|
+
completeVanity(input: string): VanityCandidate[];
|
|
70
|
+
complete(typeName: string, prefix: string): Promise<string[]>;
|
|
71
|
+
types(): string[];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface CompletionResult {
|
|
75
|
+
suggestions: string[];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export type Language = 'go' | 'ts' | 'py' | 'rs' | 'php';
|
|
79
|
+
|
|
80
|
+
export interface HandlerSpec {
|
|
81
|
+
vendor: string;
|
|
82
|
+
app: string;
|
|
83
|
+
instance?: string;
|
|
84
|
+
language: Language | string;
|
|
85
|
+
scheme: string;
|
|
86
|
+
version?: string;
|
|
87
|
+
channel?: string;
|
|
88
|
+
appPath: string;
|
|
89
|
+
displayName?: string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export type HandlerPlatform = 'linux' | 'macos' | 'ios' | 'windows' | string;
|
|
93
|
+
|
|
94
|
+
interface UriModule {
|
|
95
|
+
defaultPolicy: Policy;
|
|
96
|
+
DefaultPolicy?: Policy;
|
|
97
|
+
parse(input: string, policy?: Policy, options?: ParseOptions): URI;
|
|
98
|
+
resolveAction(uri: URI, policy?: Policy): ResolvedAction;
|
|
99
|
+
vanityCandidates(input: string, policy?: Policy): VanityCandidate[];
|
|
100
|
+
newRegistry(policy?: Policy): Registry;
|
|
101
|
+
Registry: new (policy?: Policy) => Registry;
|
|
102
|
+
completeWithScheme(
|
|
103
|
+
registry: Registry,
|
|
104
|
+
typeName: string,
|
|
105
|
+
toComplete: string,
|
|
106
|
+
): Promise<CompletionResult>;
|
|
107
|
+
validateHandlerSpec(spec: HandlerSpec): void;
|
|
108
|
+
handlerID(spec: HandlerSpec): string;
|
|
109
|
+
desktopFilename(spec: HandlerSpec): string;
|
|
110
|
+
snippet(platform: string, spec: HandlerSpec): string;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// @hop-top/uri is intentionally a runtime dependency of the facade. Keeping the
|
|
114
|
+
// import as require avoids duplicating its declarations in this package.
|
|
115
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
116
|
+
const uri = require('@hop-top/uri') as UriModule;
|
|
117
|
+
|
|
118
|
+
export const defaultPolicy: Policy = uri.defaultPolicy;
|
|
119
|
+
export const DefaultPolicy: Policy = uri.DefaultPolicy ?? uri.defaultPolicy;
|
|
120
|
+
export const Registry: new (policy?: Policy) => Registry = uri.Registry;
|
|
121
|
+
|
|
122
|
+
/** Parse a custom URI using @hop-top/uri policy and parse options. */
|
|
123
|
+
export function parse(
|
|
124
|
+
input: string,
|
|
125
|
+
policy?: Policy,
|
|
126
|
+
options?: ParseOptions,
|
|
127
|
+
): URI {
|
|
128
|
+
return uri.parse(input, policy, options);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Resolve an action route to a command plan without executing it.
|
|
133
|
+
* Accepts either a parsed URI or a raw URI string.
|
|
134
|
+
*/
|
|
135
|
+
export function resolve(
|
|
136
|
+
input: string | URI,
|
|
137
|
+
policy?: Policy,
|
|
138
|
+
options?: ParseOptions,
|
|
139
|
+
): ResolvedAction {
|
|
140
|
+
const parsed = typeof input === 'string' ? uri.parse(input, policy, options) : input;
|
|
141
|
+
return uri.resolveAction(parsed, policy);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Resolve an already parsed URI action route without executing it. */
|
|
145
|
+
export function resolveAction(parsed: URI, policy?: Policy): ResolvedAction {
|
|
146
|
+
return uri.resolveAction(parsed, policy);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Return vanity alias completion candidates. */
|
|
150
|
+
export function completeVanity(
|
|
151
|
+
input: string,
|
|
152
|
+
policy?: Policy,
|
|
153
|
+
): VanityCandidate[] {
|
|
154
|
+
return uri.vanityCandidates(input, policy);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export const vanityCandidates = completeVanity;
|
|
158
|
+
|
|
159
|
+
/** Complete URI values using a @hop-top/uri registry. */
|
|
160
|
+
export function complete(
|
|
161
|
+
registry: Registry,
|
|
162
|
+
typeName: string,
|
|
163
|
+
input: string,
|
|
164
|
+
): Promise<CompletionResult> {
|
|
165
|
+
return uri.completeWithScheme(registry, typeName, input);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Create a @hop-top/uri registry with an optional policy. */
|
|
169
|
+
export function newRegistry(policy?: Policy): Registry {
|
|
170
|
+
return uri.newRegistry(policy);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function validateHandlerSpec(spec: HandlerSpec): void {
|
|
174
|
+
uri.validateHandlerSpec(spec);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export function handlerID(spec: HandlerSpec): string {
|
|
178
|
+
return uri.handlerID(spec);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function desktopFilename(spec: HandlerSpec): string {
|
|
182
|
+
return uri.desktopFilename(spec);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export function handlerSnippet(
|
|
186
|
+
platform: HandlerPlatform,
|
|
187
|
+
spec: HandlerSpec,
|
|
188
|
+
): string {
|
|
189
|
+
return uri.snippet(platform, spec);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export const snippet = handlerSnippet;
|
|
193
|
+
|
|
194
|
+
export const handler = {
|
|
195
|
+
validate: validateHandlerSpec,
|
|
196
|
+
id: handlerID,
|
|
197
|
+
desktopFilename,
|
|
198
|
+
snippet: handlerSnippet,
|
|
199
|
+
};
|