@puzzle-ui/i18n 0.0.0-stage → 0.16.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/README.md +94 -2
- package/ai/instructions.md +141 -0
- package/ai/manifest.json +10 -0
- package/dist/LICENSE +21 -0
- package/dist/_virtual/_rolldown/runtime.cjs +22 -0
- package/dist/adapters/next.cjs +11 -0
- package/dist/adapters/next.cjs.map +1 -0
- package/dist/adapters/next.d.cts +7 -0
- package/dist/adapters/next.d.ts +7 -0
- package/dist/adapters/next.js +10 -0
- package/dist/adapters/next.js.map +1 -0
- package/dist/adapters/react-router.cjs +13 -0
- package/dist/adapters/react-router.cjs.map +1 -0
- package/dist/adapters/react-router.d.cts +10 -0
- package/dist/adapters/react-router.d.ts +10 -0
- package/dist/adapters/react-router.js +12 -0
- package/dist/adapters/react-router.js.map +1 -0
- package/dist/adapters/request.cjs +67 -0
- package/dist/adapters/request.cjs.map +1 -0
- package/dist/adapters/request.d.cts +16 -0
- package/dist/adapters/request.d.ts +16 -0
- package/dist/adapters/request.js +65 -0
- package/dist/adapters/request.js.map +1 -0
- package/dist/adapters/tanstack.cjs +13 -0
- package/dist/adapters/tanstack.cjs.map +1 -0
- package/dist/adapters/tanstack.d.cts +10 -0
- package/dist/adapters/tanstack.d.ts +10 -0
- package/dist/adapters/tanstack.js +12 -0
- package/dist/adapters/tanstack.js.map +1 -0
- package/dist/ai/index.cjs +205 -0
- package/dist/ai/index.cjs.map +1 -0
- package/dist/ai/index.d.cts +75 -0
- package/dist/ai/index.d.ts +75 -0
- package/dist/ai/index.js +195 -0
- package/dist/ai/index.js.map +1 -0
- package/dist/ai/review.cjs +319 -0
- package/dist/ai/review.cjs.map +1 -0
- package/dist/ai/review.d.cts +91 -0
- package/dist/ai/review.d.ts +91 -0
- package/dist/ai/review.js +315 -0
- package/dist/ai/review.js.map +1 -0
- package/dist/cli/bin.cjs +10 -0
- package/dist/cli/bin.cjs.map +1 -0
- package/dist/cli/bin.d.cts +1 -0
- package/dist/cli/bin.d.ts +1 -0
- package/dist/cli/bin.js +12 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/cli/index.cjs +310 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/cli/index.d.cts +7 -0
- package/dist/cli/index.d.ts +7 -0
- package/dist/cli/index.js +309 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/compiler/index.cjs +218 -0
- package/dist/compiler/index.cjs.map +1 -0
- package/dist/compiler/index.d.cts +18 -0
- package/dist/compiler/index.d.ts +18 -0
- package/dist/compiler/index.js +210 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/compiler/typescript.cjs +251 -0
- package/dist/compiler/typescript.cjs.map +1 -0
- package/dist/compiler/typescript.d.cts +27 -0
- package/dist/compiler/typescript.d.ts +27 -0
- package/dist/compiler/typescript.js +247 -0
- package/dist/compiler/typescript.js.map +1 -0
- package/dist/compiler/vite.cjs +94 -0
- package/dist/compiler/vite.cjs.map +1 -0
- package/dist/compiler/vite.d.cts +13 -0
- package/dist/compiler/vite.d.ts +13 -0
- package/dist/compiler/vite.js +92 -0
- package/dist/compiler/vite.js.map +1 -0
- package/dist/content/index.cjs +156 -0
- package/dist/content/index.cjs.map +1 -0
- package/dist/content/index.d.cts +75 -0
- package/dist/content/index.d.ts +75 -0
- package/dist/content/index.js +151 -0
- package/dist/content/index.js.map +1 -0
- package/dist/content/sanity.cjs +74 -0
- package/dist/content/sanity.cjs.map +1 -0
- package/dist/content/sanity.d.cts +19 -0
- package/dist/content/sanity.d.ts +19 -0
- package/dist/content/sanity.js +73 -0
- package/dist/content/sanity.js.map +1 -0
- package/dist/devtools/index.cjs +77 -0
- package/dist/devtools/index.cjs.map +1 -0
- package/dist/devtools/index.d.cts +29 -0
- package/dist/devtools/index.d.ts +29 -0
- package/dist/devtools/index.js +75 -0
- package/dist/devtools/index.js.map +1 -0
- package/dist/format.cjs +17 -0
- package/dist/format.cjs.map +1 -0
- package/dist/format.d.cts +9 -0
- package/dist/format.d.ts +9 -0
- package/dist/format.js +13 -0
- package/dist/format.js.map +1 -0
- package/dist/index.cjs +20 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/locale.cjs +158 -0
- package/dist/locale.cjs.map +1 -0
- package/dist/locale.d.cts +42 -0
- package/dist/locale.d.ts +42 -0
- package/dist/locale.js +155 -0
- package/dist/locale.js.map +1 -0
- package/dist/react/index.cjs +239 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +105 -0
- package/dist/react/index.d.ts +105 -0
- package/dist/react/index.js +238 -0
- package/dist/react/index.js.map +1 -0
- package/dist/routing/index.cjs +381 -0
- package/dist/routing/index.cjs.map +1 -0
- package/dist/routing/index.d.cts +44 -0
- package/dist/routing/index.d.ts +44 -0
- package/dist/routing/index.js +380 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/runtime.cjs +261 -0
- package/dist/runtime.cjs.map +1 -0
- package/dist/runtime.d.cts +74 -0
- package/dist/runtime.d.ts +74 -0
- package/dist/runtime.js +257 -0
- package/dist/runtime.js.map +1 -0
- package/dist/seo/index.cjs +212 -0
- package/dist/seo/index.cjs.map +1 -0
- package/dist/seo/index.d.cts +52 -0
- package/dist/seo/index.d.ts +52 -0
- package/dist/seo/index.js +209 -0
- package/dist/seo/index.js.map +1 -0
- package/dist/seo/origin.cjs +27 -0
- package/dist/seo/origin.cjs.map +1 -0
- package/dist/seo/origin.js +26 -0
- package/dist/seo/origin.js.map +1 -0
- package/dist/seo/sitemap.cjs +74 -0
- package/dist/seo/sitemap.cjs.map +1 -0
- package/dist/seo/sitemap.d.cts +16 -0
- package/dist/seo/sitemap.d.ts +16 -0
- package/dist/seo/sitemap.js +72 -0
- package/dist/seo/sitemap.js.map +1 -0
- package/dist/sources/index.cjs +227 -0
- package/dist/sources/index.cjs.map +1 -0
- package/dist/sources/index.d.cts +41 -0
- package/dist/sources/index.d.ts +41 -0
- package/dist/sources/index.js +222 -0
- package/dist/sources/index.js.map +1 -0
- package/dist/sources/node.cjs +50 -0
- package/dist/sources/node.cjs.map +1 -0
- package/dist/sources/node.d.cts +5 -0
- package/dist/sources/node.d.ts +5 -0
- package/dist/sources/node.js +49 -0
- package/dist/sources/node.js.map +1 -0
- package/package.json +256 -4
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { TranslationSuggestionError, suggestTranslation } from "./index.js";
|
|
2
|
+
// src/ai/review.ts
|
|
3
|
+
var TranslationReviewConflictError = class extends Error {
|
|
4
|
+
constructor(message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "TranslationReviewConflictError";
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
const translationId = (locale, key) => `${locale}\u0000${key}`;
|
|
10
|
+
const immutable = (value) => Object.freeze({ ...value });
|
|
11
|
+
const requireReviewer = (reviewer) => {
|
|
12
|
+
const normalized = reviewer.trim();
|
|
13
|
+
if (!normalized) throw new Error("A reviewer identity is required.");
|
|
14
|
+
return normalized;
|
|
15
|
+
};
|
|
16
|
+
const timestamp = (clock) => clock().toISOString();
|
|
17
|
+
const canonicalLocale = (locale) => {
|
|
18
|
+
try {
|
|
19
|
+
const [canonical] = Intl.getCanonicalLocales(locale);
|
|
20
|
+
if (canonical) return canonical;
|
|
21
|
+
} catch {}
|
|
22
|
+
throw new TranslationSuggestionError("invalid-source", `Invalid BCP 47 locale "${locale}".`);
|
|
23
|
+
};
|
|
24
|
+
const assertServerOnly = () => {
|
|
25
|
+
if (typeof window !== "undefined") throw new TranslationSuggestionError("server-only", "Translation review workflows must only be used from a server environment.");
|
|
26
|
+
};
|
|
27
|
+
const createInMemoryTranslationReviewStore = (options = {}) => {
|
|
28
|
+
const clock = options.clock ?? (() => /* @__PURE__ */ new Date());
|
|
29
|
+
const translations = /* @__PURE__ */ new Map();
|
|
30
|
+
const suggestions = /* @__PURE__ */ new Map();
|
|
31
|
+
const auditTrail = [];
|
|
32
|
+
return {
|
|
33
|
+
async getTranslation(locale, key) {
|
|
34
|
+
const current = translations.get(translationId(locale, key));
|
|
35
|
+
return current ? immutable(current) : void 0;
|
|
36
|
+
},
|
|
37
|
+
async getSuggestion(id) {
|
|
38
|
+
const record = suggestions.get(id);
|
|
39
|
+
return record ? immutable(record) : void 0;
|
|
40
|
+
},
|
|
41
|
+
async createPendingSuggestion(record) {
|
|
42
|
+
if (suggestions.has(record.id)) throw new TranslationReviewConflictError(`Suggestion "${record.id}" already exists.`);
|
|
43
|
+
const revision = translations.get(translationId(record.locale, record.key))?.revision ?? 0;
|
|
44
|
+
if (revision !== record.baseRevision) throw new TranslationReviewConflictError(`Translation "${record.key}" changed while its suggestion was being created.`);
|
|
45
|
+
suggestions.set(record.id, immutable(record));
|
|
46
|
+
auditTrail.push(immutable({
|
|
47
|
+
suggestionId: record.id,
|
|
48
|
+
key: record.key,
|
|
49
|
+
locale: record.locale,
|
|
50
|
+
action: "suggested",
|
|
51
|
+
actor: "ai",
|
|
52
|
+
at: timestamp(clock),
|
|
53
|
+
previousRevision: revision,
|
|
54
|
+
revision,
|
|
55
|
+
value: record.value
|
|
56
|
+
}));
|
|
57
|
+
},
|
|
58
|
+
async approveSuggestion(id, reviewer, expectedRevision) {
|
|
59
|
+
const record = suggestions.get(id);
|
|
60
|
+
if (!record) throw new Error(`Unknown translation suggestion "${id}".`);
|
|
61
|
+
if (record.status !== "pending") throw new TranslationReviewConflictError(`Suggestion "${id}" is already ${record.status}.`);
|
|
62
|
+
const currentKey = translationId(record.locale, record.key);
|
|
63
|
+
const current = translations.get(currentKey);
|
|
64
|
+
const currentRevision = current?.revision ?? 0;
|
|
65
|
+
if (record.baseRevision !== expectedRevision || currentRevision !== expectedRevision) throw new TranslationReviewConflictError(`Translation "${record.key}" changed after the suggestion was created.`);
|
|
66
|
+
const at = timestamp(clock);
|
|
67
|
+
const normalizedReviewer = requireReviewer(reviewer);
|
|
68
|
+
const translation = immutable({
|
|
69
|
+
key: record.key,
|
|
70
|
+
locale: record.locale,
|
|
71
|
+
value: record.value,
|
|
72
|
+
revision: currentRevision + 1
|
|
73
|
+
});
|
|
74
|
+
const suggestion = immutable({
|
|
75
|
+
...record,
|
|
76
|
+
status: "approved",
|
|
77
|
+
reviewedAt: at,
|
|
78
|
+
reviewedBy: normalizedReviewer
|
|
79
|
+
});
|
|
80
|
+
translations.set(currentKey, translation);
|
|
81
|
+
suggestions.set(id, suggestion);
|
|
82
|
+
auditTrail.push(immutable({
|
|
83
|
+
suggestionId: id,
|
|
84
|
+
key: record.key,
|
|
85
|
+
locale: record.locale,
|
|
86
|
+
action: "approved",
|
|
87
|
+
actor: normalizedReviewer,
|
|
88
|
+
at,
|
|
89
|
+
previousRevision: currentRevision,
|
|
90
|
+
revision: translation.revision,
|
|
91
|
+
previousValue: current?.value,
|
|
92
|
+
value: translation.value
|
|
93
|
+
}));
|
|
94
|
+
return {
|
|
95
|
+
suggestion: immutable(suggestion),
|
|
96
|
+
translation: immutable(translation)
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
async rejectSuggestion(id, reviewer, reason) {
|
|
100
|
+
const record = suggestions.get(id);
|
|
101
|
+
if (!record) throw new Error(`Unknown translation suggestion "${id}".`);
|
|
102
|
+
if (record.status !== "pending") throw new TranslationReviewConflictError(`Suggestion "${id}" is already ${record.status}.`);
|
|
103
|
+
const normalizedReviewer = requireReviewer(reviewer);
|
|
104
|
+
const at = timestamp(clock);
|
|
105
|
+
const normalizedReason = reason?.trim() || void 0;
|
|
106
|
+
const suggestion = immutable({
|
|
107
|
+
...record,
|
|
108
|
+
status: "rejected",
|
|
109
|
+
reviewedAt: at,
|
|
110
|
+
reviewedBy: normalizedReviewer,
|
|
111
|
+
rejectionReason: normalizedReason
|
|
112
|
+
});
|
|
113
|
+
suggestions.set(id, suggestion);
|
|
114
|
+
auditTrail.push(immutable({
|
|
115
|
+
suggestionId: id,
|
|
116
|
+
key: record.key,
|
|
117
|
+
locale: record.locale,
|
|
118
|
+
action: "rejected",
|
|
119
|
+
actor: normalizedReviewer,
|
|
120
|
+
at,
|
|
121
|
+
previousRevision: record.baseRevision,
|
|
122
|
+
revision: record.baseRevision,
|
|
123
|
+
value: record.value,
|
|
124
|
+
reason: normalizedReason
|
|
125
|
+
}));
|
|
126
|
+
return immutable(suggestion);
|
|
127
|
+
},
|
|
128
|
+
async listAuditTrail() {
|
|
129
|
+
return Object.freeze(auditTrail.map((record) => immutable(record)));
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
const createTransactionalTranslationReviewStore = (persistence, options = {}) => {
|
|
134
|
+
const clock = options.clock ?? (() => /* @__PURE__ */ new Date());
|
|
135
|
+
return {
|
|
136
|
+
getTranslation(locale, key) {
|
|
137
|
+
assertServerOnly();
|
|
138
|
+
return persistence.transaction(async (transaction) => {
|
|
139
|
+
const translation = await transaction.getTranslation(locale, key);
|
|
140
|
+
return translation ? immutable(translation) : void 0;
|
|
141
|
+
});
|
|
142
|
+
},
|
|
143
|
+
getSuggestion(id) {
|
|
144
|
+
assertServerOnly();
|
|
145
|
+
return persistence.transaction(async (transaction) => {
|
|
146
|
+
const suggestion = await transaction.getSuggestion(id);
|
|
147
|
+
return suggestion ? immutable(suggestion) : void 0;
|
|
148
|
+
});
|
|
149
|
+
},
|
|
150
|
+
async createPendingSuggestion(record) {
|
|
151
|
+
assertServerOnly();
|
|
152
|
+
await persistence.transaction(async (transaction) => {
|
|
153
|
+
if (await transaction.getSuggestion(record.id)) throw new TranslationReviewConflictError(`Suggestion "${record.id}" already exists.`);
|
|
154
|
+
const revision = (await transaction.getTranslation(record.locale, record.key))?.revision ?? 0;
|
|
155
|
+
if (revision !== record.baseRevision) throw new TranslationReviewConflictError(`Translation "${record.key}" changed while its suggestion was being created.`);
|
|
156
|
+
if (!await transaction.insertSuggestionIfAbsent(immutable(record))) throw new TranslationReviewConflictError(`Suggestion "${record.id}" already exists.`);
|
|
157
|
+
await transaction.appendAuditRecord(immutable({
|
|
158
|
+
suggestionId: record.id,
|
|
159
|
+
key: record.key,
|
|
160
|
+
locale: record.locale,
|
|
161
|
+
action: "suggested",
|
|
162
|
+
actor: "ai",
|
|
163
|
+
at: timestamp(clock),
|
|
164
|
+
previousRevision: revision,
|
|
165
|
+
revision,
|
|
166
|
+
value: record.value
|
|
167
|
+
}));
|
|
168
|
+
});
|
|
169
|
+
},
|
|
170
|
+
approveSuggestion(id, reviewer, expectedRevision) {
|
|
171
|
+
assertServerOnly();
|
|
172
|
+
return persistence.transaction(async (transaction) => {
|
|
173
|
+
const record = await transaction.getSuggestion(id);
|
|
174
|
+
if (!record) throw new Error(`Unknown translation suggestion "${id}".`);
|
|
175
|
+
if (record.status !== "pending") throw new TranslationReviewConflictError(`Suggestion "${id}" is already ${record.status}.`);
|
|
176
|
+
const current = await transaction.getTranslation(record.locale, record.key);
|
|
177
|
+
const currentRevision = current?.revision ?? 0;
|
|
178
|
+
if (record.baseRevision !== expectedRevision || currentRevision !== expectedRevision) throw new TranslationReviewConflictError(`Translation "${record.key}" changed after the suggestion was created.`);
|
|
179
|
+
const normalizedReviewer = requireReviewer(reviewer);
|
|
180
|
+
const at = timestamp(clock);
|
|
181
|
+
const translation = immutable({
|
|
182
|
+
key: record.key,
|
|
183
|
+
locale: record.locale,
|
|
184
|
+
value: record.value,
|
|
185
|
+
revision: currentRevision + 1
|
|
186
|
+
});
|
|
187
|
+
const suggestion = immutable({
|
|
188
|
+
...record,
|
|
189
|
+
status: "approved",
|
|
190
|
+
reviewedAt: at,
|
|
191
|
+
reviewedBy: normalizedReviewer
|
|
192
|
+
});
|
|
193
|
+
if (!await transaction.compareAndSetTranslation(record.locale, record.key, expectedRevision, translation)) throw new TranslationReviewConflictError(`Translation "${record.key}" changed after the suggestion was created.`);
|
|
194
|
+
if (!await transaction.updateSuggestionIfPending(id, suggestion)) throw new TranslationReviewConflictError(`Suggestion "${id}" is no longer pending.`);
|
|
195
|
+
await transaction.appendAuditRecord(immutable({
|
|
196
|
+
suggestionId: id,
|
|
197
|
+
key: record.key,
|
|
198
|
+
locale: record.locale,
|
|
199
|
+
action: "approved",
|
|
200
|
+
actor: normalizedReviewer,
|
|
201
|
+
at,
|
|
202
|
+
previousRevision: currentRevision,
|
|
203
|
+
revision: translation.revision,
|
|
204
|
+
previousValue: current?.value,
|
|
205
|
+
value: translation.value
|
|
206
|
+
}));
|
|
207
|
+
return {
|
|
208
|
+
suggestion: immutable(suggestion),
|
|
209
|
+
translation: immutable(translation)
|
|
210
|
+
};
|
|
211
|
+
});
|
|
212
|
+
},
|
|
213
|
+
rejectSuggestion(id, reviewer, reason) {
|
|
214
|
+
assertServerOnly();
|
|
215
|
+
return persistence.transaction(async (transaction) => {
|
|
216
|
+
const record = await transaction.getSuggestion(id);
|
|
217
|
+
if (!record) throw new Error(`Unknown translation suggestion "${id}".`);
|
|
218
|
+
if (record.status !== "pending") throw new TranslationReviewConflictError(`Suggestion "${id}" is already ${record.status}.`);
|
|
219
|
+
const normalizedReviewer = requireReviewer(reviewer);
|
|
220
|
+
const at = timestamp(clock);
|
|
221
|
+
const normalizedReason = reason?.trim() || void 0;
|
|
222
|
+
const suggestion = immutable({
|
|
223
|
+
...record,
|
|
224
|
+
status: "rejected",
|
|
225
|
+
reviewedAt: at,
|
|
226
|
+
reviewedBy: normalizedReviewer,
|
|
227
|
+
rejectionReason: normalizedReason
|
|
228
|
+
});
|
|
229
|
+
if (!await transaction.updateSuggestionIfPending(id, suggestion)) throw new TranslationReviewConflictError(`Suggestion "${id}" is no longer pending.`);
|
|
230
|
+
await transaction.appendAuditRecord(immutable({
|
|
231
|
+
suggestionId: id,
|
|
232
|
+
key: record.key,
|
|
233
|
+
locale: record.locale,
|
|
234
|
+
action: "rejected",
|
|
235
|
+
actor: normalizedReviewer,
|
|
236
|
+
at,
|
|
237
|
+
previousRevision: record.baseRevision,
|
|
238
|
+
revision: record.baseRevision,
|
|
239
|
+
value: record.value,
|
|
240
|
+
reason: normalizedReason
|
|
241
|
+
}));
|
|
242
|
+
return immutable(suggestion);
|
|
243
|
+
});
|
|
244
|
+
},
|
|
245
|
+
listAuditTrail() {
|
|
246
|
+
assertServerOnly();
|
|
247
|
+
return persistence.transaction(async (transaction) => Object.freeze((await transaction.listAuditTrail()).map((record) => immutable(record))));
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
const createId = () => {
|
|
252
|
+
const cryptoApi = globalThis.crypto;
|
|
253
|
+
if (!cryptoApi?.randomUUID) throw new Error("A secure random UUID implementation is required to create suggestions.");
|
|
254
|
+
return cryptoApi.randomUUID();
|
|
255
|
+
};
|
|
256
|
+
const createTranslationReviewWorkflow = (provider, store, options = {}) => {
|
|
257
|
+
const idFactory = options.idFactory ?? createId;
|
|
258
|
+
const clock = options.clock ?? (() => /* @__PURE__ */ new Date());
|
|
259
|
+
return {
|
|
260
|
+
async suggest(request, signal) {
|
|
261
|
+
assertServerOnly();
|
|
262
|
+
const sourceLocale = canonicalLocale(request.sourceLocale);
|
|
263
|
+
const targetLocale = canonicalLocale(request.targetLocale);
|
|
264
|
+
const workflowRequest = Object.freeze({
|
|
265
|
+
...request,
|
|
266
|
+
sourceLocale,
|
|
267
|
+
targetLocale,
|
|
268
|
+
terminology: request.terminology ? Object.freeze([...request.terminology]) : void 0
|
|
269
|
+
});
|
|
270
|
+
const current = await store.getTranslation(targetLocale, workflowRequest.key);
|
|
271
|
+
const suggestion = await suggestTranslation(provider, workflowRequest, signal, { quality: options.quality });
|
|
272
|
+
const id = idFactory();
|
|
273
|
+
if (!id.trim()) throw new Error("Suggestion IDs must not be empty.");
|
|
274
|
+
const record = immutable({
|
|
275
|
+
id,
|
|
276
|
+
key: suggestion.key,
|
|
277
|
+
locale: suggestion.locale,
|
|
278
|
+
sourceLocale,
|
|
279
|
+
sourceMessage: workflowRequest.sourceMessage,
|
|
280
|
+
value: suggestion.value,
|
|
281
|
+
baseRevision: current?.revision ?? 0,
|
|
282
|
+
status: "pending",
|
|
283
|
+
createdAt: timestamp(clock),
|
|
284
|
+
...suggestion.quality ? { quality: suggestion.quality } : {}
|
|
285
|
+
});
|
|
286
|
+
await store.createPendingSuggestion(record);
|
|
287
|
+
return record;
|
|
288
|
+
},
|
|
289
|
+
async approve(id, reviewer) {
|
|
290
|
+
assertServerOnly();
|
|
291
|
+
const suggestion = await store.getSuggestion(id);
|
|
292
|
+
if (!suggestion) throw new Error(`Unknown translation suggestion "${id}".`);
|
|
293
|
+
return store.approveSuggestion(id, reviewer, suggestion.baseRevision);
|
|
294
|
+
},
|
|
295
|
+
reject(id, reviewer, reason) {
|
|
296
|
+
assertServerOnly();
|
|
297
|
+
return store.rejectSuggestion(id, reviewer, reason);
|
|
298
|
+
},
|
|
299
|
+
getSuggestion(id) {
|
|
300
|
+
assertServerOnly();
|
|
301
|
+
return store.getSuggestion(id);
|
|
302
|
+
},
|
|
303
|
+
getTranslation(locale, key) {
|
|
304
|
+
assertServerOnly();
|
|
305
|
+
return store.getTranslation(locale, key);
|
|
306
|
+
},
|
|
307
|
+
listAuditTrail() {
|
|
308
|
+
assertServerOnly();
|
|
309
|
+
return store.listAuditTrail();
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
};
|
|
313
|
+
export { TranslationReviewConflictError, createInMemoryTranslationReviewStore, createTransactionalTranslationReviewStore, createTranslationReviewWorkflow };
|
|
314
|
+
|
|
315
|
+
//# sourceMappingURL=review.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"review.js","names":[],"sources":["../../src/ai/review.ts"],"sourcesContent":["import {\n suggestTranslation,\n type SuggestTranslationOptions,\n type TranslationQualityReport,\n TranslationSuggestionError,\n type TranslationSuggestionProvider,\n type TranslationSuggestionRequest,\n} from \"./index\";\n\nexport type TranslationReviewStatus = \"pending\" | \"approved\" | \"rejected\";\n\nexport interface VersionedTranslation {\n readonly key: string;\n readonly locale: string;\n readonly value: string;\n readonly revision: number;\n}\n\nexport interface TranslationReviewRecord {\n readonly id: string;\n readonly key: string;\n readonly locale: string;\n readonly sourceLocale: string;\n readonly sourceMessage: string;\n readonly value: string;\n readonly baseRevision: number;\n readonly status: TranslationReviewStatus;\n readonly createdAt: string;\n readonly quality?: TranslationQualityReport;\n readonly reviewedAt?: string;\n readonly reviewedBy?: string;\n readonly rejectionReason?: string;\n}\n\nexport interface TranslationReviewAuditRecord {\n readonly suggestionId: string;\n readonly key: string;\n readonly locale: string;\n readonly action: \"suggested\" | \"approved\" | \"rejected\";\n readonly actor: string;\n readonly at: string;\n readonly previousRevision: number;\n readonly revision: number;\n readonly previousValue?: string;\n readonly value: string;\n readonly reason?: string;\n}\n\nexport class TranslationReviewConflictError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"TranslationReviewConflictError\";\n }\n}\n\nexport interface TranslationReviewStore {\n getTranslation(\n locale: string,\n key: string,\n ): Promise<VersionedTranslation | undefined>;\n getSuggestion(id: string): Promise<TranslationReviewRecord | undefined>;\n createPendingSuggestion(record: TranslationReviewRecord): Promise<void>;\n approveSuggestion(\n id: string,\n reviewer: string,\n expectedRevision: number,\n ): Promise<{\n suggestion: TranslationReviewRecord;\n translation: VersionedTranslation;\n }>;\n rejectSuggestion(\n id: string,\n reviewer: string,\n reason?: string,\n ): Promise<TranslationReviewRecord>;\n listAuditTrail(): Promise<readonly TranslationReviewAuditRecord[]>;\n}\n\nexport interface TransactionalTranslationReviewTransaction {\n getTranslation(\n locale: string,\n key: string,\n ): Promise<VersionedTranslation | undefined>;\n getSuggestion(id: string): Promise<TranslationReviewRecord | undefined>;\n /** Atomically inserts the record only when its ID is unused. */\n insertSuggestionIfAbsent(\n record: TranslationReviewRecord,\n ): Promise<boolean>;\n /** Atomically updates the record only while its stored status is pending. */\n updateSuggestionIfPending(\n id: string,\n record: TranslationReviewRecord,\n ): Promise<boolean>;\n /** Atomically writes only when the current revision equals expectedRevision. */\n compareAndSetTranslation(\n locale: string,\n key: string,\n expectedRevision: number,\n translation: VersionedTranslation,\n ): Promise<boolean>;\n appendAuditRecord(record: TranslationReviewAuditRecord): Promise<void>;\n listAuditTrail(): Promise<readonly TranslationReviewAuditRecord[]>;\n}\n\nexport interface TransactionalTranslationReviewPersistence {\n /** Commits all callback writes together and rolls them back if it throws. */\n transaction<Result>(\n operation: (\n transaction: TransactionalTranslationReviewTransaction,\n ) => Promise<Result>,\n ): Promise<Result>;\n}\n\nexport interface CreateInMemoryTranslationReviewStoreOptions {\n clock?: () => Date;\n}\n\nconst translationId = (locale: string, key: string): string =>\n `${locale}\\u0000${key}`;\n\nconst immutable = <Value extends object>(value: Value): Readonly<Value> =>\n Object.freeze({ ...value });\n\nconst requireReviewer = (reviewer: string): string => {\n const normalized = reviewer.trim();\n\n if (!normalized) {\n throw new Error(\"A reviewer identity is required.\");\n }\n\n return normalized;\n};\n\nconst timestamp = (clock: () => Date): string => clock().toISOString();\n\nconst canonicalLocale = (locale: string): string => {\n try {\n const [canonical] = Intl.getCanonicalLocales(locale);\n\n if (canonical) {\n return canonical;\n }\n } catch {\n // Let the caller handle invalid locale values as a typed suggestion error.\n }\n\n throw new TranslationSuggestionError(\n \"invalid-source\",\n `Invalid BCP 47 locale \"${locale}\".`,\n );\n};\n\nconst assertServerOnly = (): void => {\n if (typeof window !== \"undefined\") {\n throw new TranslationSuggestionError(\n \"server-only\",\n \"Translation review workflows must only be used from a server environment.\",\n );\n }\n};\n\nexport const createInMemoryTranslationReviewStore = (\n options: CreateInMemoryTranslationReviewStoreOptions = {},\n): TranslationReviewStore => {\n const clock = options.clock ?? (() => new Date());\n const translations = new Map<string, VersionedTranslation>();\n const suggestions = new Map<string, TranslationReviewRecord>();\n const auditTrail: TranslationReviewAuditRecord[] = [];\n\n return {\n async getTranslation(locale, key) {\n const current = translations.get(translationId(locale, key));\n return current ? immutable(current) : undefined;\n },\n\n async getSuggestion(id) {\n const record = suggestions.get(id);\n return record ? immutable(record) : undefined;\n },\n\n async createPendingSuggestion(record) {\n if (suggestions.has(record.id)) {\n throw new TranslationReviewConflictError(\n `Suggestion \"${record.id}\" already exists.`,\n );\n }\n\n const current =\n translations.get(translationId(record.locale, record.key));\n const revision = current?.revision ?? 0;\n\n if (revision !== record.baseRevision) {\n throw new TranslationReviewConflictError(\n `Translation \"${record.key}\" changed while its suggestion was being created.`,\n );\n }\n\n suggestions.set(record.id, immutable(record));\n auditTrail.push(\n immutable({\n suggestionId: record.id,\n key: record.key,\n locale: record.locale,\n action: \"suggested\" as const,\n actor: \"ai\",\n at: timestamp(clock),\n previousRevision: revision,\n revision,\n value: record.value,\n }),\n );\n },\n\n async approveSuggestion(id, reviewer, expectedRevision) {\n const record = suggestions.get(id);\n\n if (!record) {\n throw new Error(`Unknown translation suggestion \"${id}\".`);\n }\n\n if (record.status !== \"pending\") {\n throw new TranslationReviewConflictError(\n `Suggestion \"${id}\" is already ${record.status}.`,\n );\n }\n\n const currentKey = translationId(record.locale, record.key);\n const current = translations.get(currentKey);\n const currentRevision = current?.revision ?? 0;\n\n if (\n record.baseRevision !== expectedRevision ||\n currentRevision !== expectedRevision\n ) {\n throw new TranslationReviewConflictError(\n `Translation \"${record.key}\" changed after the suggestion was created.`,\n );\n }\n\n const at = timestamp(clock);\n const normalizedReviewer = requireReviewer(reviewer);\n const translation = immutable({\n key: record.key,\n locale: record.locale,\n value: record.value,\n revision: currentRevision + 1,\n });\n const suggestion = immutable({\n ...record,\n status: \"approved\" as const,\n reviewedAt: at,\n reviewedBy: normalizedReviewer,\n });\n\n translations.set(currentKey, translation);\n suggestions.set(id, suggestion);\n auditTrail.push(\n immutable({\n suggestionId: id,\n key: record.key,\n locale: record.locale,\n action: \"approved\" as const,\n actor: normalizedReviewer,\n at,\n previousRevision: currentRevision,\n revision: translation.revision,\n previousValue: current?.value,\n value: translation.value,\n }),\n );\n\n return {\n suggestion: immutable(suggestion),\n translation: immutable(translation),\n };\n },\n\n async rejectSuggestion(id, reviewer, reason) {\n const record = suggestions.get(id);\n\n if (!record) {\n throw new Error(`Unknown translation suggestion \"${id}\".`);\n }\n\n if (record.status !== \"pending\") {\n throw new TranslationReviewConflictError(\n `Suggestion \"${id}\" is already ${record.status}.`,\n );\n }\n\n const normalizedReviewer = requireReviewer(reviewer);\n const at = timestamp(clock);\n const normalizedReason = reason?.trim() || undefined;\n const suggestion = immutable({\n ...record,\n status: \"rejected\" as const,\n reviewedAt: at,\n reviewedBy: normalizedReviewer,\n rejectionReason: normalizedReason,\n });\n\n suggestions.set(id, suggestion);\n auditTrail.push(\n immutable({\n suggestionId: id,\n key: record.key,\n locale: record.locale,\n action: \"rejected\" as const,\n actor: normalizedReviewer,\n at,\n previousRevision: record.baseRevision,\n revision: record.baseRevision,\n value: record.value,\n reason: normalizedReason,\n }),\n );\n\n return immutable(suggestion);\n },\n\n async listAuditTrail() {\n return Object.freeze(auditTrail.map((record) => immutable(record)));\n },\n };\n};\n\nexport interface CreateTransactionalTranslationReviewStoreOptions {\n clock?: () => Date;\n}\n\nexport const createTransactionalTranslationReviewStore = (\n persistence: TransactionalTranslationReviewPersistence,\n options: CreateTransactionalTranslationReviewStoreOptions = {},\n): TranslationReviewStore => {\n const clock = options.clock ?? (() => new Date());\n\n return {\n getTranslation(locale, key) {\n assertServerOnly();\n return persistence.transaction(async (transaction) => {\n const translation = await transaction.getTranslation(locale, key);\n return translation ? immutable(translation) : undefined;\n });\n },\n\n getSuggestion(id) {\n assertServerOnly();\n return persistence.transaction(async (transaction) => {\n const suggestion = await transaction.getSuggestion(id);\n return suggestion ? immutable(suggestion) : undefined;\n });\n },\n\n async createPendingSuggestion(record) {\n assertServerOnly();\n await persistence.transaction(async (transaction) => {\n if (await transaction.getSuggestion(record.id)) {\n throw new TranslationReviewConflictError(\n `Suggestion \"${record.id}\" already exists.`,\n );\n }\n\n const current = await transaction.getTranslation(\n record.locale,\n record.key,\n );\n const revision = current?.revision ?? 0;\n\n if (revision !== record.baseRevision) {\n throw new TranslationReviewConflictError(\n `Translation \"${record.key}\" changed while its suggestion was being created.`,\n );\n }\n\n if (!(await transaction.insertSuggestionIfAbsent(immutable(record)))) {\n throw new TranslationReviewConflictError(\n `Suggestion \"${record.id}\" already exists.`,\n );\n }\n\n await transaction.appendAuditRecord(\n immutable({\n suggestionId: record.id,\n key: record.key,\n locale: record.locale,\n action: \"suggested\" as const,\n actor: \"ai\",\n at: timestamp(clock),\n previousRevision: revision,\n revision,\n value: record.value,\n }),\n );\n });\n },\n\n approveSuggestion(id, reviewer, expectedRevision) {\n assertServerOnly();\n return persistence.transaction(async (transaction) => {\n const record = await transaction.getSuggestion(id);\n\n if (!record) {\n throw new Error(`Unknown translation suggestion \"${id}\".`);\n }\n\n if (record.status !== \"pending\") {\n throw new TranslationReviewConflictError(\n `Suggestion \"${id}\" is already ${record.status}.`,\n );\n }\n\n const current = await transaction.getTranslation(\n record.locale,\n record.key,\n );\n const currentRevision = current?.revision ?? 0;\n\n if (\n record.baseRevision !== expectedRevision ||\n currentRevision !== expectedRevision\n ) {\n throw new TranslationReviewConflictError(\n `Translation \"${record.key}\" changed after the suggestion was created.`,\n );\n }\n\n const normalizedReviewer = requireReviewer(reviewer);\n const at = timestamp(clock);\n const translation = immutable({\n key: record.key,\n locale: record.locale,\n value: record.value,\n revision: currentRevision + 1,\n });\n const suggestion = immutable({\n ...record,\n status: \"approved\" as const,\n reviewedAt: at,\n reviewedBy: normalizedReviewer,\n });\n\n if (\n !(await transaction.compareAndSetTranslation(\n record.locale,\n record.key,\n expectedRevision,\n translation,\n ))\n ) {\n throw new TranslationReviewConflictError(\n `Translation \"${record.key}\" changed after the suggestion was created.`,\n );\n }\n\n if (!(await transaction.updateSuggestionIfPending(id, suggestion))) {\n throw new TranslationReviewConflictError(\n `Suggestion \"${id}\" is no longer pending.`,\n );\n }\n\n await transaction.appendAuditRecord(\n immutable({\n suggestionId: id,\n key: record.key,\n locale: record.locale,\n action: \"approved\" as const,\n actor: normalizedReviewer,\n at,\n previousRevision: currentRevision,\n revision: translation.revision,\n previousValue: current?.value,\n value: translation.value,\n }),\n );\n\n return {\n suggestion: immutable(suggestion),\n translation: immutable(translation),\n };\n });\n },\n\n rejectSuggestion(id, reviewer, reason) {\n assertServerOnly();\n return persistence.transaction(async (transaction) => {\n const record = await transaction.getSuggestion(id);\n\n if (!record) {\n throw new Error(`Unknown translation suggestion \"${id}\".`);\n }\n\n if (record.status !== \"pending\") {\n throw new TranslationReviewConflictError(\n `Suggestion \"${id}\" is already ${record.status}.`,\n );\n }\n\n const normalizedReviewer = requireReviewer(reviewer);\n const at = timestamp(clock);\n const normalizedReason = reason?.trim() || undefined;\n const suggestion = immutable({\n ...record,\n status: \"rejected\" as const,\n reviewedAt: at,\n reviewedBy: normalizedReviewer,\n rejectionReason: normalizedReason,\n });\n\n if (!(await transaction.updateSuggestionIfPending(id, suggestion))) {\n throw new TranslationReviewConflictError(\n `Suggestion \"${id}\" is no longer pending.`,\n );\n }\n\n await transaction.appendAuditRecord(\n immutable({\n suggestionId: id,\n key: record.key,\n locale: record.locale,\n action: \"rejected\" as const,\n actor: normalizedReviewer,\n at,\n previousRevision: record.baseRevision,\n revision: record.baseRevision,\n value: record.value,\n reason: normalizedReason,\n }),\n );\n\n return immutable(suggestion);\n });\n },\n\n listAuditTrail() {\n assertServerOnly();\n return persistence.transaction(async (transaction) =>\n Object.freeze(\n (await transaction.listAuditTrail()).map((record) =>\n immutable(record),\n ),\n ),\n );\n },\n };\n};\n\nexport interface CreateTranslationReviewWorkflowOptions {\n idFactory?: () => string;\n clock?: () => Date;\n quality?: SuggestTranslationOptions[\"quality\"];\n}\n\nexport interface TranslationReviewWorkflow {\n suggest(\n request: TranslationSuggestionRequest,\n signal?: AbortSignal,\n ): Promise<TranslationReviewRecord>;\n approve(\n id: string,\n reviewer: string,\n ): Promise<{\n suggestion: TranslationReviewRecord;\n translation: VersionedTranslation;\n }>;\n reject(\n id: string,\n reviewer: string,\n reason?: string,\n ): Promise<TranslationReviewRecord>;\n getSuggestion(id: string): Promise<TranslationReviewRecord | undefined>;\n getTranslation(\n locale: string,\n key: string,\n ): Promise<VersionedTranslation | undefined>;\n listAuditTrail(): Promise<readonly TranslationReviewAuditRecord[]>;\n}\n\nconst createId = (): string => {\n const cryptoApi = globalThis.crypto;\n\n if (!cryptoApi?.randomUUID) {\n throw new Error(\n \"A secure random UUID implementation is required to create suggestions.\",\n );\n }\n\n return cryptoApi.randomUUID();\n};\n\nexport const createTranslationReviewWorkflow = (\n provider: TranslationSuggestionProvider,\n store: TranslationReviewStore,\n options: CreateTranslationReviewWorkflowOptions = {},\n): TranslationReviewWorkflow => {\n const idFactory = options.idFactory ?? createId;\n const clock = options.clock ?? (() => new Date());\n\n return {\n async suggest(request, signal) {\n assertServerOnly();\n const sourceLocale = canonicalLocale(request.sourceLocale);\n const targetLocale = canonicalLocale(request.targetLocale);\n const workflowRequest = Object.freeze({\n ...request,\n sourceLocale,\n targetLocale,\n terminology: request.terminology\n ? Object.freeze([...request.terminology])\n : undefined,\n });\n const current = await store.getTranslation(\n targetLocale,\n workflowRequest.key,\n );\n const suggestion = await suggestTranslation(provider, workflowRequest, signal, {\n quality: options.quality,\n });\n const id = idFactory();\n\n if (!id.trim()) {\n throw new Error(\"Suggestion IDs must not be empty.\");\n }\n\n const record = immutable({\n id,\n key: suggestion.key,\n locale: suggestion.locale,\n sourceLocale,\n sourceMessage: workflowRequest.sourceMessage,\n value: suggestion.value,\n baseRevision: current?.revision ?? 0,\n status: \"pending\" as const,\n createdAt: timestamp(clock),\n ...(suggestion.quality ? { quality: suggestion.quality } : {}),\n });\n\n await store.createPendingSuggestion(record);\n return record;\n },\n\n async approve(id, reviewer) {\n assertServerOnly();\n const suggestion = await store.getSuggestion(id);\n\n if (!suggestion) {\n throw new Error(`Unknown translation suggestion \"${id}\".`);\n }\n\n return store.approveSuggestion(id, reviewer, suggestion.baseRevision);\n },\n\n reject(id, reviewer, reason) {\n assertServerOnly();\n return store.rejectSuggestion(id, reviewer, reason);\n },\n\n getSuggestion(id) {\n assertServerOnly();\n return store.getSuggestion(id);\n },\n\n getTranslation(locale, key) {\n assertServerOnly();\n return store.getTranslation(loc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mB,UAAU,iBAAiB,QAAQ,EAC7E,SAAS,QAAQ,QACnB,CAAC;GACD,MAAM,KAAK,UAAU;GAErB,IAAI,CAAC,GAAG,KAAK,GACX,MAAM,IAAI,MAAM,mCAAmC;GAGrD,MAAM,SAAS,UAAU;IACvB;IACA,KAAK,WAAW;IAChB,QAAQ,WAAW;IACnB;IACA,eAAe,gBAAgB;IAC/B,OAAO,WAAW;IAClB,cAAc,SAAS,YAAY;IACnC,QAAQ;IACR,WAAW,UAAU,KAAK;IAC1B,GAAI,WAAW,UAAU,EAAE,SAAS,WAAW,QAAQ,IAAI,CAAC;GAC9D,CAAC;GAED,MAAM,MAAM,wBAAwB,MAAM;GAC1C,OAAO;EACT;EAEA,MAAM,QAAQ,IAAI,UAAU;GAC1B,iBAAiB;GACjB,MAAM,aAAa,MAAM,MAAM,cAAc,EAAE;GAE/C,IAAI,CAAC,YACH,MAAM,IAAI,MAAM,mCAAmC,GAAG,GAAG;GAG3D,OAAO,MAAM,kBAAkB,IAAI,UAAU,WAAW,YAAY;EACtE;EAEA,OAAO,IAAI,UAAU,QAAQ;GAC3B,iBAAiB;GACjB,OAAO,MAAM,iBAAiB,IAAI,UAAU,MAAM;EACpD;EAEA,cAAc,IAAI;GAChB,iBAAiB;GACjB,OAAO,MAAM,cAAc,EAAE;EAC/B;EAEA,eAAe,QAAQ,KAAK;GAC1B,iBAAiB;GACjB,OAAO,MAAM,eAAe,QAAQ,GAAG;EACzC;EAEA,iBAAiB;GACf,iBAAiB;GACjB,OAAO,MAAM,eAAe;EAC9B;CACF;AACF"}
|
package/dist/cli/bin.cjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// src/cli/bin.ts
|
|
3
|
+
require("./index.cjs").runI18nCli(process.argv.slice(2)).then((exitCode) => {
|
|
4
|
+
process.exitCode = exitCode;
|
|
5
|
+
}, (error) => {
|
|
6
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
7
|
+
process.exitCode = 1;
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=bin.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.cjs","names":["runI18nCli"],"sources":["../../src/cli/bin.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { runI18nCli } from \"./index\";\n\nvoid runI18nCli(process.argv.slice(2)).then((exitCode) => {\n process.exitCode = exitCode;\n}, (error: unknown) => {\n console.error(error instanceof Error ? error.message : String(error));\n process.exitCode = 1;\n});\n"],"mappings":";;A,qBAIKA,CAAAA,CAAAA,WAAW,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,aAAa;CACxD,QAAQ,WAAW;AACrB,IAAI,UAAmB;CACrB,QAAQ,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;CACpE,QAAQ,WAAW;AACrB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/cli/bin.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { runI18nCli } from "./index.js";
|
|
3
|
+
// src/cli/bin.ts
|
|
4
|
+
runI18nCli(process.argv.slice(2)).then((exitCode) => {
|
|
5
|
+
process.exitCode = exitCode;
|
|
6
|
+
}, (error) => {
|
|
7
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
8
|
+
process.exitCode = 1;
|
|
9
|
+
});
|
|
10
|
+
export {};
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=bin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.js","names":[],"sources":["../../src/cli/bin.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { runI18nCli } from \"./index\";\n\nvoid runI18nCli(process.argv.slice(2)).then((exitCode) => {\n process.exitCode = exitCode;\n}, (error: unknown) => {\n console.error(error instanceof Error ? error.message : String(error));\n process.exitCode = 1;\n});\n"],"mappings":";;;AAIK,WAAW,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,aAAa;CACxD,QAAQ,WAAW;AACrB,IAAI,UAAmB;CACrB,QAAQ,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;CACpE,QAAQ,WAAW;AACrB,CAAC"}
|