@x18n/ui 0.0.0-stage → 0.0.0

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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-PRESENT Anthony Fu <https://github.com/antfu>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,255 @@
1
+ import { DevframeDefinition } from "devframe";
2
+ import { ExtractCandidate } from "@x18n/builtins/extractors";
3
+ import { Decision, EditOp, FileChange, KeyString, LocaleCode, MessageLeaf, PlaceholderProblem, Project, ProjectExplanation, Severity, TextRange, UsageKind, WireDiagnostic } from "@x18n/core";
4
+ //#region src/node/types.d.ts
5
+ /** A loaded project as the UI sees it. */
6
+ interface UiProject {
7
+ readonly name: string;
8
+ /** Absolute root. */
9
+ readonly root: string;
10
+ readonly project: Project;
11
+ }
12
+ /** A file position in a project, for "open in editor". */
13
+ interface UiLocation {
14
+ readonly project: UiProject;
15
+ /** Path relative to the project root. */
16
+ readonly path: string;
17
+ /** 1-based. */
18
+ readonly line: number;
19
+ /** 1-based. */
20
+ readonly column: number;
21
+ }
22
+ /** ---- Inputs ---- */
23
+ interface ProjectQuery {
24
+ /** Project name; may be omitted when the workspace has one project. */
25
+ readonly project?: string | undefined;
26
+ }
27
+ interface KeyQuery extends ProjectQuery {
28
+ readonly key: KeyString;
29
+ }
30
+ interface UsageQuery extends ProjectQuery {
31
+ readonly key?: KeyString | undefined;
32
+ readonly path?: string | undefined;
33
+ }
34
+ interface PromptQuery extends ProjectQuery {
35
+ readonly locale: LocaleCode;
36
+ readonly keys?: string | readonly KeyString[] | undefined;
37
+ readonly namespace?: string | undefined;
38
+ readonly limit?: number | undefined;
39
+ readonly cursor?: string | undefined;
40
+ }
41
+ /** Edit ops the UI and agents send; extraction has its own functions. */
42
+ type UiEditOp = Exclude<EditOp, {
43
+ readonly type: "extract" | "format";
44
+ }>;
45
+ interface PlanQuery extends ProjectQuery {
46
+ readonly ops: readonly UiEditOp[];
47
+ }
48
+ interface ApplyQuery extends PlanQuery {
49
+ /** Decision id to option id; unanswered decisions take their default. */
50
+ readonly answers?: Readonly<Record<string, string>> | undefined;
51
+ /** Write values whose placeholders differ from the source value. */
52
+ readonly force?: boolean | undefined;
53
+ }
54
+ interface ExtractQuery extends ProjectQuery {
55
+ readonly files?: readonly string[] | undefined;
56
+ }
57
+ type ExtractPlanItem = Pick<ExtractCandidate, "path" | "range" | "original" | "key" | "value" | "replacement" | "imports">;
58
+ interface ExtractApplyQuery extends ProjectQuery {
59
+ readonly items: readonly ExtractPlanItem[];
60
+ }
61
+ interface OpenQuery extends ProjectQuery {
62
+ readonly path: string;
63
+ readonly line: number;
64
+ readonly column: number;
65
+ }
66
+ interface PageQuery {
67
+ readonly limit?: number | undefined;
68
+ readonly cursor?: string | undefined;
69
+ }
70
+ interface AgentKeysQuery extends ProjectQuery, PageQuery {
71
+ readonly glob?: string | undefined;
72
+ readonly missing?: LocaleCode | undefined;
73
+ readonly unused?: boolean | undefined;
74
+ readonly namespace?: string | undefined;
75
+ readonly values?: boolean | undefined;
76
+ }
77
+ interface AgentUsagesQuery extends UsageQuery, PageQuery {}
78
+ interface AgentCheckQuery extends ProjectQuery, PageQuery {
79
+ readonly only?: readonly string[] | undefined;
80
+ readonly locale?: readonly LocaleCode[] | undefined;
81
+ }
82
+ interface AgentSetQuery extends ProjectQuery {
83
+ readonly messages: Readonly<Record<LocaleCode, Readonly<Record<string, MessageLeaf>>>>;
84
+ readonly force?: boolean | undefined;
85
+ }
86
+ interface Confirmable {
87
+ readonly confirm?: boolean | undefined;
88
+ readonly answers?: Readonly<Record<string, string>> | undefined;
89
+ }
90
+ interface AgentRenameQuery extends ProjectQuery, Confirmable {
91
+ readonly from: KeyString;
92
+ readonly to: KeyString;
93
+ readonly usages?: boolean | undefined;
94
+ }
95
+ interface AgentDeleteQuery extends ProjectQuery, Confirmable {
96
+ readonly key: KeyString;
97
+ readonly locales?: readonly LocaleCode[] | undefined;
98
+ }
99
+ /** ---- Outputs ---- */
100
+ interface LocaleSummary {
101
+ readonly code: LocaleCode;
102
+ readonly displayName: string | undefined;
103
+ readonly flag: string | undefined;
104
+ readonly total: number;
105
+ readonly translated: number;
106
+ readonly missing: number;
107
+ readonly empty: number;
108
+ /** One decimal, rounded down. */
109
+ readonly percent: number;
110
+ }
111
+ interface DiagnosticCounts {
112
+ readonly errors: number;
113
+ readonly warnings: number;
114
+ /** Infos and hints. */
115
+ readonly infos: number;
116
+ readonly byCode: readonly {
117
+ readonly code: string;
118
+ readonly severity: Severity;
119
+ readonly count: number;
120
+ }[];
121
+ }
122
+ interface ProjectSummary {
123
+ readonly name: string;
124
+ readonly sourceLocale: LocaleCode;
125
+ readonly namespaced: boolean;
126
+ readonly locales: readonly LocaleSummary[];
127
+ readonly resources: number;
128
+ readonly keys: number;
129
+ readonly usages: number;
130
+ readonly diagnostics: DiagnosticCounts;
131
+ /** Presets that are listed in the config or detected. */
132
+ readonly presets: readonly string[];
133
+ }
134
+ interface ProjectList {
135
+ readonly projects: readonly ProjectSummary[];
136
+ readonly openInEditor: boolean;
137
+ }
138
+ interface KeyRow {
139
+ readonly key: KeyString;
140
+ readonly namespace: string | undefined;
141
+ /** Stored value per locale; locales without the key are absent. */
142
+ readonly values: Readonly<Record<LocaleCode, MessageLeaf>>;
143
+ /** Locales where the key is missing or empty. */
144
+ readonly missing: readonly LocaleCode[];
145
+ readonly unused: boolean;
146
+ readonly diagnostics: number;
147
+ }
148
+ interface KeyTable {
149
+ readonly project: string;
150
+ readonly sourceLocale: LocaleCode;
151
+ readonly locales: readonly LocaleCode[];
152
+ readonly rows: readonly KeyRow[];
153
+ }
154
+ /** Lines of code around a position. */
155
+ interface Snippet {
156
+ /** 1-based number of the first line. */
157
+ readonly line: number;
158
+ readonly lines: readonly string[];
159
+ }
160
+ interface UsageView {
161
+ readonly key: KeyString | undefined;
162
+ readonly raw: string;
163
+ readonly path: string;
164
+ /** 1-based. */
165
+ readonly line: number;
166
+ /** 1-based. */
167
+ readonly column: number;
168
+ readonly kind: UsageKind;
169
+ readonly dynamic: false | "prefix" | "unknown";
170
+ /** True for prefix usages that may refer to the key. */
171
+ readonly possible: boolean;
172
+ readonly snippet: Snippet;
173
+ }
174
+ interface MessageView {
175
+ readonly locale: LocaleCode;
176
+ readonly value: MessageLeaf;
177
+ readonly path: string;
178
+ readonly line: number;
179
+ /** Placeholders in a string value, with offsets in the value. */
180
+ readonly placeholders: readonly ({
181
+ readonly text: string;
182
+ } & TextRange)[];
183
+ }
184
+ interface KeyDetail {
185
+ readonly project: string;
186
+ readonly key: KeyString;
187
+ readonly namespace: string | undefined;
188
+ readonly messages: readonly MessageView[];
189
+ readonly missing: readonly LocaleCode[];
190
+ readonly usages: readonly UsageView[];
191
+ readonly diagnostics: readonly WireDiagnostic[];
192
+ }
193
+ interface AnalysisView {
194
+ readonly project: string;
195
+ readonly diagnostics: readonly WireDiagnostic[];
196
+ readonly unused: readonly KeyString[];
197
+ /** Usages whose key is not defined in the source locale. */
198
+ readonly undefinedUsages: readonly UsageView[];
199
+ }
200
+ type ExplainView = Omit<ProjectExplanation, "root">;
201
+ interface ExplainList {
202
+ readonly projects: readonly ExplainView[];
203
+ }
204
+ interface ChangeView {
205
+ readonly type: FileChange["type"];
206
+ readonly path: string;
207
+ }
208
+ interface PlanView {
209
+ readonly keys: readonly KeyString[];
210
+ readonly warnings: readonly string[];
211
+ readonly decisions: readonly Decision[];
212
+ readonly changes: readonly ChangeView[];
213
+ /** Set values whose placeholders differ from the source value. */
214
+ readonly problems: readonly PlaceholderProblem[];
215
+ }
216
+ interface ApplyView extends PlanView {
217
+ /** False when placeholder problems blocked the write. */
218
+ readonly applied: boolean;
219
+ readonly revision: number;
220
+ }
221
+ /** Shared state `x18n:state`: bumps on every change in any project. Mutable: it is the draft type of `mutate`. */
222
+ interface X18nState {
223
+ revision: number;
224
+ changedKeys: KeyString[];
225
+ }
226
+ declare module "devframe" {
227
+ interface DevframeRpcServerFunctions {
228
+ "x18n:project": () => ProjectList;
229
+ "x18n:keys": (query: ProjectQuery) => KeyTable;
230
+ "x18n:key": (query: KeyQuery) => KeyDetail | null;
231
+ "x18n:usages": (query: UsageQuery) => UsageView[];
232
+ "x18n:analysis": (query: ProjectQuery) => AnalysisView;
233
+ "x18n:explain": () => ExplainList;
234
+ "x18n:translate-prompt": (query: PromptQuery) => string;
235
+ "x18n:plan": (query: PlanQuery) => PlanView;
236
+ "x18n:apply": (query: ApplyQuery) => Promise<ApplyView>;
237
+ "x18n:extract-candidates": (query: ExtractQuery) => ExtractCandidate[];
238
+ "x18n:extract-apply": (query: ExtractApplyQuery) => Promise<ApplyView>;
239
+ "x18n:open-in-editor": (query: OpenQuery) => Promise<void>;
240
+ }
241
+ interface DevframeRpcSharedStates {
242
+ "x18n:state": X18nState;
243
+ }
244
+ }
245
+ //#endregion
246
+ //#region src/node/rpc.d.ts
247
+ interface RpcOptions {
248
+ readonly openInEditor?: ((location: UiLocation) => Promise<void>) | undefined;
249
+ }
250
+ //#endregion
251
+ //#region src/node/index.d.ts
252
+ /** The x18n UI, RPC functions and MCP tools over loaded projects, as a devframe definition. */
253
+ export declare function createX18nDevframe(projects: readonly UiProject[], options?: RpcOptions): DevframeDefinition;
254
+ //#endregion
255
+ export type { AgentCheckQuery, AgentDeleteQuery, AgentKeysQuery, AgentRenameQuery, AgentSetQuery, AgentUsagesQuery, AnalysisView, ApplyQuery, ApplyView, ChangeView, DiagnosticCounts, ExplainList, ExplainView, ExtractApplyQuery, ExtractPlanItem, ExtractQuery, KeyDetail, KeyQuery, KeyRow, KeyTable, LocaleSummary, MessageView, OpenQuery, PlanQuery, PlanView, ProjectList, ProjectQuery, ProjectSummary, PromptQuery, Snippet, UiEditOp, UiLocation, UiProject, UsageQuery, UsageView, RpcOptions as X18nDevframeOptions, X18nState };