@customyai/cli 0.7.2 → 0.10.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 +76 -0
- package/LICENSE +2 -1
- package/README.md +77 -0
- 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-57NNDUEX.mjs +3246 -0
- package/dist/chunk-6X3AX6PB.cjs +3266 -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/index.cjs +32 -11
- package/dist/index.d.cts +63 -1
- package/dist/index.d.ts +63 -1
- 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,244 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/vendor/i18n-tools/icu.ts
|
|
4
|
+
var NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
5
|
+
var SIMPLE_TYPES = /* @__PURE__ */ new Set(["number", "date", "time"]);
|
|
6
|
+
var COMPLEX_TYPES = /* @__PURE__ */ new Set(["plural", "select", "selectordinal"]);
|
|
7
|
+
var MAX_NESTING = 16;
|
|
8
|
+
var WS = /\s/;
|
|
9
|
+
var Parser = class {
|
|
10
|
+
constructor(s) {
|
|
11
|
+
this.s = s;
|
|
12
|
+
}
|
|
13
|
+
s;
|
|
14
|
+
i = 0;
|
|
15
|
+
parseText(inPlural, depth) {
|
|
16
|
+
const { s } = this;
|
|
17
|
+
const out = [];
|
|
18
|
+
let buf = "";
|
|
19
|
+
const flush = () => {
|
|
20
|
+
if (buf) {
|
|
21
|
+
out.push({ t: "text", text: buf });
|
|
22
|
+
buf = "";
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
while (this.i < s.length) {
|
|
26
|
+
const c = s[this.i];
|
|
27
|
+
if (c === "'") {
|
|
28
|
+
const next = s[this.i + 1];
|
|
29
|
+
if (next === "'") {
|
|
30
|
+
flush();
|
|
31
|
+
out.push({ t: "quote", raw: "''" });
|
|
32
|
+
this.i += 2;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (next === "{" || next === "}") {
|
|
36
|
+
const end = s.indexOf("'", this.i + 2);
|
|
37
|
+
const stop = end === -1 ? s.length : end + 1;
|
|
38
|
+
flush();
|
|
39
|
+
out.push({ t: "quote", raw: s.slice(this.i, stop) });
|
|
40
|
+
this.i = stop;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
buf += c;
|
|
44
|
+
this.i += 1;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (c === "}") {
|
|
48
|
+
if (depth > 0) break;
|
|
49
|
+
buf += c;
|
|
50
|
+
this.i += 1;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (c === "{") {
|
|
54
|
+
const save = this.i;
|
|
55
|
+
const node = this.tryArgument(depth);
|
|
56
|
+
if (node) {
|
|
57
|
+
flush();
|
|
58
|
+
out.push(node);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
this.i = save + 1;
|
|
62
|
+
buf += c;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (c === "#" && inPlural) {
|
|
66
|
+
flush();
|
|
67
|
+
out.push({ t: "hash" });
|
|
68
|
+
this.i += 1;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
buf += c;
|
|
72
|
+
this.i += 1;
|
|
73
|
+
}
|
|
74
|
+
flush();
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
/** Intenta leer un argumento desde `{`. Si no es válido devuelve null (quien llama restaura `i`). */
|
|
78
|
+
tryArgument(depth) {
|
|
79
|
+
const { s } = this;
|
|
80
|
+
const start = this.i;
|
|
81
|
+
let j = start + 1;
|
|
82
|
+
while (j < s.length && s[j] !== "}" && s[j] !== ",") j += 1;
|
|
83
|
+
if (j >= s.length) return null;
|
|
84
|
+
const name = s.slice(start + 1, j).trim();
|
|
85
|
+
if (!NAME.test(name)) return null;
|
|
86
|
+
if (s[j] === "}") {
|
|
87
|
+
this.i = j + 1;
|
|
88
|
+
return { t: "arg", raw: s.slice(start, j + 1), name, type: null };
|
|
89
|
+
}
|
|
90
|
+
let k = j + 1;
|
|
91
|
+
while (k < s.length && s[k] !== "}" && s[k] !== ",") k += 1;
|
|
92
|
+
if (k >= s.length) return null;
|
|
93
|
+
const type = s.slice(j + 1, k).trim();
|
|
94
|
+
const simple = SIMPLE_TYPES.has(type);
|
|
95
|
+
if (!simple && !COMPLEX_TYPES.has(type)) return null;
|
|
96
|
+
if (s[k] === "}") {
|
|
97
|
+
if (!simple) return null;
|
|
98
|
+
this.i = k + 1;
|
|
99
|
+
return { t: "arg", raw: s.slice(start, k + 1), name, type };
|
|
100
|
+
}
|
|
101
|
+
if (simple) {
|
|
102
|
+
const end = s.indexOf("}", k + 1);
|
|
103
|
+
if (end === -1) return null;
|
|
104
|
+
this.i = end + 1;
|
|
105
|
+
return { t: "arg", raw: s.slice(start, end + 1), name, type };
|
|
106
|
+
}
|
|
107
|
+
if (depth >= MAX_NESTING) return null;
|
|
108
|
+
let headEnd = k + 1;
|
|
109
|
+
if (type !== "select") {
|
|
110
|
+
const off = /^\s*offset:\s*\d+/.exec(s.slice(headEnd, headEnd + 40));
|
|
111
|
+
if (off) headEnd += off[0].length;
|
|
112
|
+
}
|
|
113
|
+
const head = s.slice(start, headEnd);
|
|
114
|
+
let p = headEnd;
|
|
115
|
+
const options = [];
|
|
116
|
+
for (; ; ) {
|
|
117
|
+
const wsStart = p;
|
|
118
|
+
while (p < s.length && WS.test(s[p])) p += 1;
|
|
119
|
+
if (p >= s.length) return null;
|
|
120
|
+
if (s[p] === "}") {
|
|
121
|
+
const tail = s.slice(wsStart, p + 1);
|
|
122
|
+
this.i = p + 1;
|
|
123
|
+
return { t: "complex", name, type, head, options, tail };
|
|
124
|
+
}
|
|
125
|
+
const selStart = p;
|
|
126
|
+
while (p < s.length && s[p] !== "{" && s[p] !== "}" && !WS.test(s[p])) p += 1;
|
|
127
|
+
const selector = s.slice(selStart, p);
|
|
128
|
+
while (p < s.length && WS.test(s[p])) p += 1;
|
|
129
|
+
if (!selector || s[p] !== "{") return null;
|
|
130
|
+
const open = s.slice(wsStart, p + 1);
|
|
131
|
+
this.i = p + 1;
|
|
132
|
+
const body = this.parseText(type !== "select", depth + 1);
|
|
133
|
+
if (this.i >= s.length || s[this.i] !== "}") return null;
|
|
134
|
+
p = this.i + 1;
|
|
135
|
+
options.push({ selector, open, body });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
function parseIcu(message) {
|
|
140
|
+
const parser = new Parser(message);
|
|
141
|
+
return parser.parseText(false, 0);
|
|
142
|
+
}
|
|
143
|
+
function unparseIcu(nodes) {
|
|
144
|
+
let out = "";
|
|
145
|
+
for (const n of nodes) {
|
|
146
|
+
switch (n.t) {
|
|
147
|
+
case "text":
|
|
148
|
+
out += n.text;
|
|
149
|
+
break;
|
|
150
|
+
case "arg":
|
|
151
|
+
case "quote":
|
|
152
|
+
out += n.raw;
|
|
153
|
+
break;
|
|
154
|
+
case "hash":
|
|
155
|
+
out += "#";
|
|
156
|
+
break;
|
|
157
|
+
case "complex":
|
|
158
|
+
out += n.head;
|
|
159
|
+
for (const o of n.options) out += `${o.open}${unparseIcu(o.body)}}`;
|
|
160
|
+
out += n.tail;
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return out;
|
|
165
|
+
}
|
|
166
|
+
function tokenizeIcu(message) {
|
|
167
|
+
const tokens = [];
|
|
168
|
+
const push = (t) => {
|
|
169
|
+
const last = tokens[tokens.length - 1];
|
|
170
|
+
if (last && t.kind === "text" && last.kind === "text") {
|
|
171
|
+
tokens[tokens.length - 1] = { kind: "text", text: last.text + t.text };
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (last && t.kind === "ph" && last.kind === "ph" && t.role === "syntax" && last.role === "syntax") {
|
|
175
|
+
tokens[tokens.length - 1] = { kind: "ph", raw: last.raw + t.raw, role: "syntax", name: last.name };
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
tokens.push(t);
|
|
179
|
+
};
|
|
180
|
+
const walk = (nodes) => {
|
|
181
|
+
for (const n of nodes) {
|
|
182
|
+
switch (n.t) {
|
|
183
|
+
case "text":
|
|
184
|
+
push({ kind: "text", text: n.text });
|
|
185
|
+
break;
|
|
186
|
+
case "arg":
|
|
187
|
+
push({ kind: "ph", raw: n.raw, role: "arg", name: n.name });
|
|
188
|
+
break;
|
|
189
|
+
case "hash":
|
|
190
|
+
push({ kind: "ph", raw: "#", role: "hash", name: null });
|
|
191
|
+
break;
|
|
192
|
+
case "quote":
|
|
193
|
+
push({ kind: "ph", raw: n.raw, role: "quote", name: null });
|
|
194
|
+
break;
|
|
195
|
+
case "complex":
|
|
196
|
+
push({ kind: "ph", raw: n.head, role: "syntax", name: n.name });
|
|
197
|
+
for (const o of n.options) {
|
|
198
|
+
push({ kind: "ph", raw: o.open, role: "syntax", name: n.name });
|
|
199
|
+
walk(o.body);
|
|
200
|
+
push({ kind: "ph", raw: "}", role: "syntax", name: n.name });
|
|
201
|
+
}
|
|
202
|
+
push({ kind: "ph", raw: n.tail, role: "syntax", name: n.name });
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
walk(parseIcu(message));
|
|
208
|
+
return tokens;
|
|
209
|
+
}
|
|
210
|
+
function collectComplex(message) {
|
|
211
|
+
const found = [];
|
|
212
|
+
const walk = (nodes) => {
|
|
213
|
+
for (const n of nodes) {
|
|
214
|
+
if (n.t !== "complex") continue;
|
|
215
|
+
found.push({ name: n.name, type: n.type, selectors: n.options.map((o) => o.selector) });
|
|
216
|
+
for (const o of n.options) walk(o.body);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
walk(parseIcu(message));
|
|
220
|
+
return found;
|
|
221
|
+
}
|
|
222
|
+
var CATEGORY_ORDER = ["zero", "one", "two", "few", "many", "other"];
|
|
223
|
+
function pluralCategories(locale, type = "cardinal") {
|
|
224
|
+
try {
|
|
225
|
+
const cats = new Intl.PluralRules(locale, { type }).resolvedOptions().pluralCategories;
|
|
226
|
+
const set = new Set(cats);
|
|
227
|
+
const ordered = CATEGORY_ORDER.filter((c) => set.has(c));
|
|
228
|
+
return ordered.length > 0 ? ordered : ["other"];
|
|
229
|
+
} catch {
|
|
230
|
+
return ["one", "other"];
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
function plainText(message, placeholder = "\uFFFC") {
|
|
234
|
+
let out = "";
|
|
235
|
+
for (const t of tokenizeIcu(message)) out += t.kind === "text" ? t.text : placeholder;
|
|
236
|
+
return out;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
exports.collectComplex = collectComplex;
|
|
240
|
+
exports.parseIcu = parseIcu;
|
|
241
|
+
exports.plainText = plainText;
|
|
242
|
+
exports.pluralCategories = pluralCategories;
|
|
243
|
+
exports.tokenizeIcu = tokenizeIcu;
|
|
244
|
+
exports.unparseIcu = unparseIcu;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/vendor/i18n-tools/errors.ts
|
|
2
|
+
var I18nToolsError = class extends Error {
|
|
3
|
+
code;
|
|
4
|
+
constructor(code, message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "I18nToolsError";
|
|
7
|
+
this.code = code;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
function utf8ByteLength(text) {
|
|
11
|
+
let bytes = 0;
|
|
12
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
13
|
+
const c = text.charCodeAt(i);
|
|
14
|
+
if (c < 128) bytes += 1;
|
|
15
|
+
else if (c < 2048) bytes += 2;
|
|
16
|
+
else if (c >= 55296 && c <= 56319 && i + 1 < text.length && (text.charCodeAt(i + 1) & 64512) === 56320) {
|
|
17
|
+
bytes += 4;
|
|
18
|
+
i += 1;
|
|
19
|
+
} else bytes += 3;
|
|
20
|
+
}
|
|
21
|
+
return bytes;
|
|
22
|
+
}
|
|
23
|
+
function compareCodeUnits(a, b) {
|
|
24
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { I18nToolsError, compareCodeUnits, utf8ByteLength };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/vendor/i18n-tools/errors.ts
|
|
4
|
+
var I18nToolsError = class extends Error {
|
|
5
|
+
code;
|
|
6
|
+
constructor(code, message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "I18nToolsError";
|
|
9
|
+
this.code = code;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
function utf8ByteLength(text) {
|
|
13
|
+
let bytes = 0;
|
|
14
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
15
|
+
const c = text.charCodeAt(i);
|
|
16
|
+
if (c < 128) bytes += 1;
|
|
17
|
+
else if (c < 2048) bytes += 2;
|
|
18
|
+
else if (c >= 55296 && c <= 56319 && i + 1 < text.length && (text.charCodeAt(i + 1) & 64512) === 56320) {
|
|
19
|
+
bytes += 4;
|
|
20
|
+
i += 1;
|
|
21
|
+
} else bytes += 3;
|
|
22
|
+
}
|
|
23
|
+
return bytes;
|
|
24
|
+
}
|
|
25
|
+
function compareCodeUnits(a, b) {
|
|
26
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
exports.I18nToolsError = I18nToolsError;
|
|
30
|
+
exports.compareCodeUnits = compareCodeUnits;
|
|
31
|
+
exports.utf8ByteLength = utf8ByteLength;
|
|
@@ -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 };
|
package/dist/index.cjs
CHANGED
|
@@ -1,46 +1,67 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunk6X3AX6PB_cjs = require('./chunk-6X3AX6PB.cjs');
|
|
4
|
+
require('./chunk-2A6WFLXS.cjs');
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
|
|
8
|
+
Object.defineProperty(exports, "EXPERIENCE_EXIT_CODES", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return chunk6X3AX6PB_cjs.EXPERIENCE_EXIT; }
|
|
11
|
+
});
|
|
7
12
|
Object.defineProperty(exports, "EXPERIMENTS_EXIT_CODES", {
|
|
8
13
|
enumerable: true,
|
|
9
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunk6X3AX6PB_cjs.EXPERIMENTS_EXIT; }
|
|
10
15
|
});
|
|
11
16
|
Object.defineProperty(exports, "PROVISIONING_EXIT_CODES", {
|
|
12
17
|
enumerable: true,
|
|
13
|
-
get: function () { return
|
|
18
|
+
get: function () { return chunk6X3AX6PB_cjs.EXIT; }
|
|
14
19
|
});
|
|
15
20
|
Object.defineProperty(exports, "SyncError", {
|
|
16
21
|
enumerable: true,
|
|
17
|
-
get: function () { return
|
|
22
|
+
get: function () { return chunk6X3AX6PB_cjs.SyncError; }
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "WHATSAPP_EXIT_CODES", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return chunk6X3AX6PB_cjs.WHATSAPP_EXIT; }
|
|
18
27
|
});
|
|
19
28
|
Object.defineProperty(exports, "generateAppTypes", {
|
|
20
29
|
enumerable: true,
|
|
21
|
-
get: function () { return
|
|
30
|
+
get: function () { return chunk6X3AX6PB_cjs.generateAppTypes; }
|
|
22
31
|
});
|
|
23
32
|
Object.defineProperty(exports, "runCli", {
|
|
24
33
|
enumerable: true,
|
|
25
|
-
get: function () { return
|
|
34
|
+
get: function () { return chunk6X3AX6PB_cjs.runCli; }
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "runExperienceCli", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () { return chunk6X3AX6PB_cjs.runExperienceCli; }
|
|
26
39
|
});
|
|
27
40
|
Object.defineProperty(exports, "runExperimentsCli", {
|
|
28
41
|
enumerable: true,
|
|
29
|
-
get: function () { return
|
|
42
|
+
get: function () { return chunk6X3AX6PB_cjs.runExperimentsCli; }
|
|
30
43
|
});
|
|
31
44
|
Object.defineProperty(exports, "runProvisioningCli", {
|
|
32
45
|
enumerable: true,
|
|
33
|
-
get: function () { return
|
|
46
|
+
get: function () { return chunk6X3AX6PB_cjs.runProvisioningCli; }
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "runWhatsAppCli", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () { return chunk6X3AX6PB_cjs.runWhatsAppCli; }
|
|
34
51
|
});
|
|
35
52
|
Object.defineProperty(exports, "schemaToType", {
|
|
36
53
|
enumerable: true,
|
|
37
|
-
get: function () { return
|
|
54
|
+
get: function () { return chunk6X3AX6PB_cjs.schemaToType; }
|
|
55
|
+
});
|
|
56
|
+
Object.defineProperty(exports, "serializeCatalog", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
get: function () { return chunk6X3AX6PB_cjs.serializeCatalog; }
|
|
38
59
|
});
|
|
39
60
|
Object.defineProperty(exports, "syncApp", {
|
|
40
61
|
enumerable: true,
|
|
41
|
-
get: function () { return
|
|
62
|
+
get: function () { return chunk6X3AX6PB_cjs.syncApp; }
|
|
42
63
|
});
|
|
43
64
|
Object.defineProperty(exports, "validateManifest", {
|
|
44
65
|
enumerable: true,
|
|
45
|
-
get: function () { return
|
|
66
|
+
get: function () { return chunk6X3AX6PB_cjs.validateManifest; }
|
|
46
67
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -10,6 +10,10 @@ type CliIo = {
|
|
|
10
10
|
isTTY?: boolean;
|
|
11
11
|
/** Asks a question on the terminal (the prompt goes to stderr) and returns the typed line. */
|
|
12
12
|
prompt?: (question: string) => Promise<string>;
|
|
13
|
+
/** Cancela los comandos que no terminan solos (`customy whatsapp tail`); la terminal lo dispara con Ctrl+C. */
|
|
14
|
+
signal?: AbortSignal;
|
|
15
|
+
/** Espera entre sondeos de `tail` (inyectable en pruebas). */
|
|
16
|
+
sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
13
17
|
};
|
|
14
18
|
declare function runCli(argv: string[], io: CliIo): Promise<number>;
|
|
15
19
|
|
|
@@ -370,4 +374,62 @@ declare const EXPERIMENTS_EXIT: {
|
|
|
370
374
|
};
|
|
371
375
|
declare function runExperimentsCli(group: string, args: string[], io: CliIo): Promise<number>;
|
|
372
376
|
|
|
373
|
-
|
|
377
|
+
/**
|
|
378
|
+
* `catalog@1`: traducciones como DATOS versionados, en lugar de textos escritos en el código.
|
|
379
|
+
*
|
|
380
|
+
* Plan: docs/CUSTOMY_EXPERIENCE_CONTROL_PLANE_PLAN.md (§5.7). Es el contrato que usan, sin duplicarse, el motor `@customy/i18n`, el design system
|
|
381
|
+
* (`DesignSystemMessagesProvider` sustituye textos por clave) y los componentes propios (`{ $t: "clave" }` en `component-registry.ts`).
|
|
382
|
+
*
|
|
383
|
+
* Un catálogo es PLANO (`clave.con.puntos → mensaje ICU`) y de UN idioma de UN espacio de nombres. Cada publicación es una **revisión inmutable**
|
|
384
|
+
* identificada por su número y por la huella de su contenido; restaurar crea una revisión nueva. Puro: sin DOM ni I/O; nunca lanza al validar.
|
|
385
|
+
*
|
|
386
|
+
* Qué garantiza:
|
|
387
|
+
* 1. `validateCatalog`: forma, claves, mensajes ICU bien formados (llaves, plurales con `other`), sin HTML, límites por plan.
|
|
388
|
+
* 2. `checkCatalogPublish`: una revisión nueva no puede quitar una clave ni cambiar sus variables sin reconocerlo, porque eso rompe a quien ya la usa.
|
|
389
|
+
* 3. `parityReport`: qué idioma no tiene una clave y dónde un mensaje cambió de variables entre idiomas.
|
|
390
|
+
* 4. `resolveCatalog`: capas (plataforma → organización → entorno) y cadena de respaldo de idiomas; nunca devuelve una clave cruda.
|
|
391
|
+
*/
|
|
392
|
+
|
|
393
|
+
declare const CatalogDocSchema: z.ZodObject<{
|
|
394
|
+
version: z.ZodLiteral<"catalog@1">;
|
|
395
|
+
namespace: z.ZodString;
|
|
396
|
+
locale: z.ZodString;
|
|
397
|
+
syntax: z.ZodDefault<z.ZodEnum<["icu1", "mf2"]>>;
|
|
398
|
+
messages: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
399
|
+
}, "strict", z.ZodTypeAny, {
|
|
400
|
+
locale: string;
|
|
401
|
+
version: "catalog@1";
|
|
402
|
+
namespace: string;
|
|
403
|
+
syntax: "icu1" | "mf2";
|
|
404
|
+
messages: Record<string, string>;
|
|
405
|
+
}, {
|
|
406
|
+
locale: string;
|
|
407
|
+
version: "catalog@1";
|
|
408
|
+
namespace: string;
|
|
409
|
+
messages: Record<string, string>;
|
|
410
|
+
syntax?: "icu1" | "mf2" | undefined;
|
|
411
|
+
}>;
|
|
412
|
+
type CatalogDoc = z.infer<typeof CatalogDocSchema>;
|
|
413
|
+
|
|
414
|
+
declare const EXPERIENCE_EXIT: {
|
|
415
|
+
readonly ok: 0;
|
|
416
|
+
readonly invalid: 1;
|
|
417
|
+
readonly usage: 2;
|
|
418
|
+
readonly auth: 3;
|
|
419
|
+
readonly conflict: 4;
|
|
420
|
+
readonly failure: 5;
|
|
421
|
+
};
|
|
422
|
+
/** El documento tal como se escribe a disco: orden fijo de campos y mensajes ordenados por clave (diffs estables en Git). */
|
|
423
|
+
declare function serializeCatalog(doc: CatalogDoc): string;
|
|
424
|
+
declare function runExperienceCli(args: string[], io: CliIo): Promise<number>;
|
|
425
|
+
|
|
426
|
+
declare const WHATSAPP_EXIT: {
|
|
427
|
+
readonly ok: 0;
|
|
428
|
+
readonly failure: 1;
|
|
429
|
+
readonly unsupported: 2;
|
|
430
|
+
readonly auth: 3;
|
|
431
|
+
readonly findings: 4;
|
|
432
|
+
};
|
|
433
|
+
declare function runWhatsAppCli(args: string[], io: CliIo): Promise<number>;
|
|
434
|
+
|
|
435
|
+
export { type CliIo, EXPERIENCE_EXIT as EXPERIENCE_EXIT_CODES, EXPERIMENTS_EXIT as EXPERIMENTS_EXIT_CODES, EXIT as PROVISIONING_EXIT_CODES, SyncError, type SyncOptions, type SyncResult, WHATSAPP_EXIT as WHATSAPP_EXIT_CODES, generateAppTypes, runCli, runExperienceCli, runExperimentsCli, runProvisioningCli, runWhatsAppCli, schemaToType, serializeCatalog, syncApp, validateManifest };
|