@customyai/cli 0.7.2 → 0.11.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/CHANGELOG.md +82 -0
- package/LICENSE +2 -1
- package/README.md +84 -5
- package/dist/bin.cjs +6 -2
- package/dist/bin.mjs +5 -1
- package/dist/chunk-2A6WFLXS.cjs +235 -0
- package/dist/chunk-3M6ZLCSN.mjs +237 -0
- package/dist/chunk-ABK4QQWW.cjs +244 -0
- package/dist/chunk-BYMLRMNS.mjs +27 -0
- package/dist/chunk-MFJL3NO5.cjs +31 -0
- package/dist/chunk-QKIF4C5R.mjs +226 -0
- package/dist/chunk-VA4VPLZ4.mjs +3266 -0
- package/dist/chunk-VKMVRAMV.cjs +3286 -0
- package/dist/index.cjs +32 -11
- package/dist/index.d.cts +73 -3
- package/dist/index.d.ts +73 -3
- package/dist/index.mjs +2 -1
- package/dist/json-NETFQXLJ.mjs +67 -0
- package/dist/json-NSJMTBPP.cjs +70 -0
- package/dist/po-AKWHAYBL.mjs +387 -0
- package/dist/po-IJGMXNVY.cjs +394 -0
- package/dist/pseudo-CKYMJJBX.mjs +101 -0
- package/dist/pseudo-LBLMBD2T.cjs +106 -0
- package/dist/quality-6SEZNA6Q.cjs +207 -0
- package/dist/quality-ILK6IA5O.mjs +199 -0
- package/dist/xliff-DEJHB2SY.mjs +512 -0
- package/dist/xliff-DXICWMWC.cjs +518 -0
- package/package.json +9 -3
- package/dist/chunk-762M6SBX.mjs +0 -1098
- package/dist/chunk-TSPERSQL.cjs +0 -1113
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// src/vendor/translation-catalog.ts
|
|
4
|
+
function utf8Bytes(text) {
|
|
5
|
+
const out = [];
|
|
6
|
+
for (let i = 0; i < text.length; i++) {
|
|
7
|
+
let c = text.charCodeAt(i);
|
|
8
|
+
if (c >= 55296 && c <= 56319 && i + 1 < text.length) {
|
|
9
|
+
const d = text.charCodeAt(i + 1);
|
|
10
|
+
if (d >= 56320 && d <= 57343) {
|
|
11
|
+
c = 65536 + (c - 55296 << 10) + (d - 56320);
|
|
12
|
+
i++;
|
|
13
|
+
} else c = 65533;
|
|
14
|
+
} else if (c >= 55296 && c <= 57343) c = 65533;
|
|
15
|
+
if (c < 128) out.push(c);
|
|
16
|
+
else if (c < 2048) out.push(192 | c >> 6, 128 | c & 63);
|
|
17
|
+
else if (c < 65536) out.push(224 | c >> 12, 128 | c >> 6 & 63, 128 | c & 63);
|
|
18
|
+
else out.push(240 | c >> 18, 128 | c >> 12 & 63, 128 | c >> 6 & 63, 128 | c & 63);
|
|
19
|
+
}
|
|
20
|
+
return Uint8Array.from(out);
|
|
21
|
+
}
|
|
22
|
+
var utf8Length = (text) => utf8Bytes(text).length;
|
|
23
|
+
|
|
24
|
+
// src/vendor/safe-input.ts
|
|
25
|
+
var hasOwnKey = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
|
|
26
|
+
|
|
27
|
+
// src/vendor/translation-catalog.ts
|
|
28
|
+
var CATALOG_DOC_VERSION = "catalog@1";
|
|
29
|
+
var CATALOG_RESERVED_KEYS = ["constructor", "toString", "valueOf", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable", "toLocaleString", "__proto__", "__defineGetter__", "__defineSetter__", "__lookupGetter__", "__lookupSetter__"];
|
|
30
|
+
var isReservedCatalogKey = (key) => CATALOG_RESERVED_KEYS.includes(key);
|
|
31
|
+
var CATALOG_KEY = /^(?!(?:constructor|toString|valueOf|hasOwnProperty|isPrototypeOf|propertyIsEnumerable|toLocaleString)$)[a-z][A-Za-z0-9]*(\.[a-z][A-Za-z0-9-]*)*$/;
|
|
32
|
+
var CATALOG_NAMESPACE = /^[a-z][a-z0-9-]{1,31}$/;
|
|
33
|
+
var CATALOG_LOCALE = /^[a-z]{2,3}(-[A-Za-z0-9]{2,8}){0,2}$/;
|
|
34
|
+
var CATALOG_SYNTAXES = ["icu1", "mf2"];
|
|
35
|
+
var SUPPORTED_CATALOG_SYNTAXES = ["icu1"];
|
|
36
|
+
var CATALOG_MAX_KEY_LENGTH = 120;
|
|
37
|
+
var CATALOG_MAX_MESSAGE_LENGTH = 2e3;
|
|
38
|
+
var TRANSLATION_PLAN_LIMITS = {
|
|
39
|
+
free: { keys: 200, locales: 2, revisions: 20, bytes: 32768 },
|
|
40
|
+
pro: { keys: 5e3, locales: 8, revisions: 200, bytes: 524288 },
|
|
41
|
+
enterprise: { keys: 5e4, locales: 40, revisions: 2e3, bytes: 4194304 }
|
|
42
|
+
};
|
|
43
|
+
var CatalogDocSchema = z.object({
|
|
44
|
+
version: z.literal(CATALOG_DOC_VERSION),
|
|
45
|
+
namespace: z.string().regex(CATALOG_NAMESPACE),
|
|
46
|
+
locale: z.string().regex(CATALOG_LOCALE),
|
|
47
|
+
syntax: z.enum(CATALOG_SYNTAXES).default("icu1"),
|
|
48
|
+
messages: z.record(z.string(), z.string())
|
|
49
|
+
}).strict();
|
|
50
|
+
var ARG_TYPES = /* @__PURE__ */ new Set(["number", "date", "time", "plural", "select", "selectordinal"]);
|
|
51
|
+
var NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
52
|
+
function analyzeMessage(message) {
|
|
53
|
+
if (message.length > CATALOG_MAX_MESSAGE_LENGTH) return { ok: false, params: [], error: `el mensaje pasa de ${CATALOG_MAX_MESSAGE_LENGTH} caracteres` };
|
|
54
|
+
if (/[<>]/.test(message)) return { ok: false, params: [], error: "los mensajes no admiten HTML (< o >)" };
|
|
55
|
+
const params = /* @__PURE__ */ new Set();
|
|
56
|
+
let error = null;
|
|
57
|
+
let i = 0;
|
|
58
|
+
const parseText = (inPlural, depth) => {
|
|
59
|
+
while (i < message.length && !error) {
|
|
60
|
+
const c = message[i];
|
|
61
|
+
if (c === "'") {
|
|
62
|
+
if (message[i + 1] === "'") {
|
|
63
|
+
i += 2;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (message[i + 1] === "{" || message[i + 1] === "}") {
|
|
67
|
+
const end = message.indexOf("'", i + 2);
|
|
68
|
+
i = end === -1 ? message.length : end + 1;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
i += 1;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (c === "}") {
|
|
75
|
+
if (depth === 0) error = "llave de cierre sin abrir";
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (c === "{") {
|
|
79
|
+
i += 1;
|
|
80
|
+
parseArgument(depth + 1);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (c === "#" && inPlural) {
|
|
84
|
+
i += 1;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
i += 1;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const parseArgument = (depth) => {
|
|
91
|
+
const start = i;
|
|
92
|
+
while (i < message.length && message[i] !== "}" && message[i] !== ",") i += 1;
|
|
93
|
+
const name = message.slice(start, i).trim();
|
|
94
|
+
if (!NAME.test(name)) {
|
|
95
|
+
error = `nombre de variable no v\xE1lido \xAB${name}\xBB`;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
params.add(name);
|
|
99
|
+
if (message[i] === "}") {
|
|
100
|
+
i += 1;
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (i >= message.length) {
|
|
104
|
+
error = "falta cerrar una llave";
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
i += 1;
|
|
108
|
+
const tstart = i;
|
|
109
|
+
while (i < message.length && message[i] !== "}" && message[i] !== ",") i += 1;
|
|
110
|
+
const type = message.slice(tstart, i).trim();
|
|
111
|
+
if (!ARG_TYPES.has(type)) {
|
|
112
|
+
error = `tipo \xAB${type}\xBB no admitido`;
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (message[i] === "}") {
|
|
116
|
+
if (type === "plural" || type === "select" || type === "selectordinal") error = `\xAB${type}\xBB necesita opciones`;
|
|
117
|
+
else i += 1;
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
i += 1;
|
|
121
|
+
if (type !== "plural" && type !== "select" && type !== "selectordinal") {
|
|
122
|
+
const style = message.indexOf("}", i);
|
|
123
|
+
if (style === -1) {
|
|
124
|
+
error = "falta cerrar una llave";
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
i = style + 1;
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
let hasOther = false;
|
|
131
|
+
while (i < message.length && !error) {
|
|
132
|
+
while (message[i] === " " || message[i] === "\n" || message[i] === " ") i += 1;
|
|
133
|
+
if (message[i] === "}") {
|
|
134
|
+
i += 1;
|
|
135
|
+
if (!hasOther) error = `\xAB${type}\xBB de \xAB${name}\xBB necesita la opci\xF3n other`;
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const ostart = i;
|
|
139
|
+
while (i < message.length && message[i] !== "{" && message[i] !== "}" && !/\s/.test(message[i])) i += 1;
|
|
140
|
+
const option = message.slice(ostart, i);
|
|
141
|
+
while (message[i] === " ") i += 1;
|
|
142
|
+
if (!option || message[i] !== "{") {
|
|
143
|
+
error = `opci\xF3n mal formada en \xAB${name}\xBB`;
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (option === "other") hasOther = true;
|
|
147
|
+
i += 1;
|
|
148
|
+
parseText(type !== "select", depth);
|
|
149
|
+
if (error) return;
|
|
150
|
+
if (message[i] !== "}") {
|
|
151
|
+
error = "falta cerrar una llave";
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
i += 1;
|
|
155
|
+
}
|
|
156
|
+
if (!error) error = "falta cerrar una llave";
|
|
157
|
+
};
|
|
158
|
+
parseText(false, 0);
|
|
159
|
+
if (!error && i < message.length) error = "llave de cierre sin abrir";
|
|
160
|
+
return { ok: error === null, params: [...params].sort(), error };
|
|
161
|
+
}
|
|
162
|
+
function validateCatalog(input, options = {}) {
|
|
163
|
+
try {
|
|
164
|
+
return validateCatalogUnsafe(input, options);
|
|
165
|
+
} catch {
|
|
166
|
+
return { ok: false, doc: null, issues: [{ path: "", code: "invalid-shape", message: "el cat\xE1logo no se pudo analizar" }] };
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function validateCatalogUnsafe(input, options) {
|
|
170
|
+
const limits = options.limits ?? TRANSLATION_PLAN_LIMITS.pro;
|
|
171
|
+
const issues = [];
|
|
172
|
+
try {
|
|
173
|
+
let bytes = 0;
|
|
174
|
+
try {
|
|
175
|
+
bytes = utf8Length(JSON.stringify(input) ?? "");
|
|
176
|
+
} catch {
|
|
177
|
+
return { ok: false, doc: null, issues: [{ path: "", code: "invalid-shape", message: "el cat\xE1logo no es JSON o est\xE1 anidado en exceso" }] };
|
|
178
|
+
}
|
|
179
|
+
if (bytes > limits.bytes) return { ok: false, doc: null, issues: [{ path: "", code: "too-large", message: `el cat\xE1logo pesa ${bytes} bytes (m\xE1ximo ${limits.bytes})` }] };
|
|
180
|
+
const parsed = CatalogDocSchema.safeParse(input);
|
|
181
|
+
if (!parsed.success) return { ok: false, doc: null, issues: parsed.error.issues.slice(0, 20).map((i) => ({ path: i.path.join("."), code: "invalid-shape", message: i.message })) };
|
|
182
|
+
const doc = parsed.data;
|
|
183
|
+
if (!SUPPORTED_CATALOG_SYNTAXES.includes(doc.syntax)) return { ok: false, doc: null, issues: [{ path: "syntax", code: "unsupported-syntax", message: `la sintaxis \xAB${doc.syntax}\xBB todav\xEDa no est\xE1 soportada` }] };
|
|
184
|
+
const rawMessages = input.messages;
|
|
185
|
+
if (typeof rawMessages === "object" && rawMessages !== null && hasOwnKey(rawMessages, "__proto__")) issues.push({ path: "messages.__proto__", code: "invalid-key", message: "clave reservada \xAB__proto__\xBB: coincide con un nombre de Object.prototype" });
|
|
186
|
+
const keys = Object.keys(doc.messages);
|
|
187
|
+
if (keys.length > limits.keys) issues.push({ path: "messages", code: "too-many-keys", message: `m\xE1s de ${limits.keys} claves` });
|
|
188
|
+
for (const key of keys) {
|
|
189
|
+
if (isReservedCatalogKey(key)) {
|
|
190
|
+
issues.push({ path: `messages.${key}`, code: "invalid-key", message: `clave reservada \xAB${key}\xBB: coincide con un nombre de Object.prototype (ren\xF3mbrala, p. ej. \xAB${key}Label\xBB)` });
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (key.length > CATALOG_MAX_KEY_LENGTH || !CATALOG_KEY.test(key)) {
|
|
194
|
+
issues.push({ path: `messages.${key}`, code: "invalid-key", message: "clave no v\xE1lida (min\xFAscula inicial, segmentos con puntos, sin espacios)" });
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
const a = analyzeMessage(doc.messages[key]);
|
|
198
|
+
if (!a.ok) issues.push({ path: `messages.${key}`, code: "invalid-message", message: a.error ?? "mensaje no v\xE1lido" });
|
|
199
|
+
}
|
|
200
|
+
return { ok: issues.length === 0, doc: issues.length === 0 ? doc : null, issues };
|
|
201
|
+
} catch {
|
|
202
|
+
return { ok: false, doc: null, issues: [{ path: "", code: "invalid-shape", message: "el cat\xE1logo no se pudo analizar" }] };
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function parityReport(byLocale, required, base = required[0] ?? "en") {
|
|
206
|
+
const all = /* @__PURE__ */ new Set();
|
|
207
|
+
for (const messages of Object.values(byLocale)) for (const key of Object.keys(messages)) all.add(key);
|
|
208
|
+
const missing = {};
|
|
209
|
+
const placeholderMismatch = [];
|
|
210
|
+
const baseMessages = hasOwnKey(byLocale, base) ? byLocale[base] : {};
|
|
211
|
+
for (const locale of required) {
|
|
212
|
+
const messages = hasOwnKey(byLocale, locale) ? byLocale[locale] : {};
|
|
213
|
+
const gone = [...all].filter((key) => !hasOwnKey(messages, key) || typeof messages[key] !== "string" || !messages[key].trim()).sort();
|
|
214
|
+
if (gone.length) missing[locale] = gone;
|
|
215
|
+
if (locale === base) continue;
|
|
216
|
+
for (const key of Object.keys(messages).sort()) {
|
|
217
|
+
if (!hasOwnKey(baseMessages, key)) continue;
|
|
218
|
+
const expected = analyzeMessage(baseMessages[key]).params;
|
|
219
|
+
const got = analyzeMessage(messages[key]).params;
|
|
220
|
+
if (expected.join("|") !== got.join("|")) placeholderMismatch.push({ key, locale, expected, got });
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return { ok: Object.keys(missing).length === 0 && placeholderMismatch.length === 0, missing, placeholderMismatch };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export { CATALOG_DOC_VERSION, CATALOG_KEY, CATALOG_LOCALE, CATALOG_NAMESPACE, TRANSLATION_PLAN_LIMITS, analyzeMessage, parityReport, validateCatalog };
|