@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
package/dist/index.cjs
CHANGED
|
@@ -1,46 +1,67 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkVKMVRAMV_cjs = require('./chunk-VKMVRAMV.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 chunkVKMVRAMV_cjs.EXPERIENCE_EXIT; }
|
|
11
|
+
});
|
|
7
12
|
Object.defineProperty(exports, "EXPERIMENTS_EXIT_CODES", {
|
|
8
13
|
enumerable: true,
|
|
9
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkVKMVRAMV_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 chunkVKMVRAMV_cjs.EXIT; }
|
|
14
19
|
});
|
|
15
20
|
Object.defineProperty(exports, "SyncError", {
|
|
16
21
|
enumerable: true,
|
|
17
|
-
get: function () { return
|
|
22
|
+
get: function () { return chunkVKMVRAMV_cjs.SyncError; }
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "WHATSAPP_EXIT_CODES", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return chunkVKMVRAMV_cjs.WHATSAPP_EXIT; }
|
|
18
27
|
});
|
|
19
28
|
Object.defineProperty(exports, "generateAppTypes", {
|
|
20
29
|
enumerable: true,
|
|
21
|
-
get: function () { return
|
|
30
|
+
get: function () { return chunkVKMVRAMV_cjs.generateAppTypes; }
|
|
22
31
|
});
|
|
23
32
|
Object.defineProperty(exports, "runCli", {
|
|
24
33
|
enumerable: true,
|
|
25
|
-
get: function () { return
|
|
34
|
+
get: function () { return chunkVKMVRAMV_cjs.runCli; }
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "runExperienceCli", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () { return chunkVKMVRAMV_cjs.runExperienceCli; }
|
|
26
39
|
});
|
|
27
40
|
Object.defineProperty(exports, "runExperimentsCli", {
|
|
28
41
|
enumerable: true,
|
|
29
|
-
get: function () { return
|
|
42
|
+
get: function () { return chunkVKMVRAMV_cjs.runExperimentsCli; }
|
|
30
43
|
});
|
|
31
44
|
Object.defineProperty(exports, "runProvisioningCli", {
|
|
32
45
|
enumerable: true,
|
|
33
|
-
get: function () { return
|
|
46
|
+
get: function () { return chunkVKMVRAMV_cjs.runProvisioningCli; }
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "runWhatsAppCli", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () { return chunkVKMVRAMV_cjs.runWhatsAppCli; }
|
|
34
51
|
});
|
|
35
52
|
Object.defineProperty(exports, "schemaToType", {
|
|
36
53
|
enumerable: true,
|
|
37
|
-
get: function () { return
|
|
54
|
+
get: function () { return chunkVKMVRAMV_cjs.schemaToType; }
|
|
55
|
+
});
|
|
56
|
+
Object.defineProperty(exports, "serializeCatalog", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
get: function () { return chunkVKMVRAMV_cjs.serializeCatalog; }
|
|
38
59
|
});
|
|
39
60
|
Object.defineProperty(exports, "syncApp", {
|
|
40
61
|
enumerable: true,
|
|
41
|
-
get: function () { return
|
|
62
|
+
get: function () { return chunkVKMVRAMV_cjs.syncApp; }
|
|
42
63
|
});
|
|
43
64
|
Object.defineProperty(exports, "validateManifest", {
|
|
44
65
|
enumerable: true,
|
|
45
|
-
get: function () { return
|
|
66
|
+
get: function () { return chunkVKMVRAMV_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
|
|
|
@@ -299,7 +303,12 @@ declare function validateManifest(input: unknown): {
|
|
|
299
303
|
type SyncOptions = {
|
|
300
304
|
manifest: AppManifest;
|
|
301
305
|
accessUrl: string;
|
|
302
|
-
|
|
306
|
+
/** Token de administrador del Workspace: viaja como `Authorization: Bearer`. */
|
|
307
|
+
token?: string;
|
|
308
|
+
/** Secreto de administrador de Access: viaja como `x-admin-secret` (lo que acepta Access de producción). Manda sobre `token`. */
|
|
309
|
+
adminSecret?: string;
|
|
310
|
+
/** Quién opera (`x-actor`); Access con `ADMIN_SECRET_MODE=require-actor` lo exige junto a `x-reason` (8+ caracteres). */
|
|
311
|
+
actor?: string;
|
|
303
312
|
workspaceEnvironmentId: string;
|
|
304
313
|
reason: string;
|
|
305
314
|
fetch?: typeof fetch;
|
|
@@ -324,13 +333,16 @@ type SyncResult = {
|
|
|
324
333
|
applicationId: string;
|
|
325
334
|
environmentId: string;
|
|
326
335
|
revision: number;
|
|
336
|
+
/** Clave pública (`pk_…`) del entorno de la app; no es secreta. Va al `.env` de la app. `null` si Access no la devuelve. */
|
|
337
|
+
publishableKey: string | null;
|
|
327
338
|
/** Cómo quedó cada producto; vacío si Access no lo informa. */
|
|
328
339
|
reconciliation: Record<string, ProductReconciliation>;
|
|
329
340
|
};
|
|
330
341
|
declare class SyncError extends Error {
|
|
331
342
|
readonly code: string;
|
|
332
343
|
readonly status: number;
|
|
333
|
-
|
|
344
|
+
readonly hint?: string | undefined;
|
|
345
|
+
constructor(code: string, status: number, hint?: string | undefined);
|
|
334
346
|
}
|
|
335
347
|
declare function syncApp(options: SyncOptions): Promise<SyncResult>;
|
|
336
348
|
|
|
@@ -370,4 +382,62 @@ declare const EXPERIMENTS_EXIT: {
|
|
|
370
382
|
};
|
|
371
383
|
declare function runExperimentsCli(group: string, args: string[], io: CliIo): Promise<number>;
|
|
372
384
|
|
|
373
|
-
|
|
385
|
+
/**
|
|
386
|
+
* `catalog@1`: traducciones como DATOS versionados, en lugar de textos escritos en el código.
|
|
387
|
+
*
|
|
388
|
+
* Plan: docs/CUSTOMY_EXPERIENCE_CONTROL_PLANE_PLAN.md (§5.7). Es el contrato que usan, sin duplicarse, el motor `@customy/i18n`, el design system
|
|
389
|
+
* (`DesignSystemMessagesProvider` sustituye textos por clave) y los componentes propios (`{ $t: "clave" }` en `component-registry.ts`).
|
|
390
|
+
*
|
|
391
|
+
* 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**
|
|
392
|
+
* 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.
|
|
393
|
+
*
|
|
394
|
+
* Qué garantiza:
|
|
395
|
+
* 1. `validateCatalog`: forma, claves, mensajes ICU bien formados (llaves, plurales con `other`), sin HTML, límites por plan.
|
|
396
|
+
* 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.
|
|
397
|
+
* 3. `parityReport`: qué idioma no tiene una clave y dónde un mensaje cambió de variables entre idiomas.
|
|
398
|
+
* 4. `resolveCatalog`: capas (plataforma → organización → entorno) y cadena de respaldo de idiomas; nunca devuelve una clave cruda.
|
|
399
|
+
*/
|
|
400
|
+
|
|
401
|
+
declare const CatalogDocSchema: z.ZodObject<{
|
|
402
|
+
version: z.ZodLiteral<"catalog@1">;
|
|
403
|
+
namespace: z.ZodString;
|
|
404
|
+
locale: z.ZodString;
|
|
405
|
+
syntax: z.ZodDefault<z.ZodEnum<["icu1", "mf2"]>>;
|
|
406
|
+
messages: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
407
|
+
}, "strict", z.ZodTypeAny, {
|
|
408
|
+
locale: string;
|
|
409
|
+
version: "catalog@1";
|
|
410
|
+
namespace: string;
|
|
411
|
+
syntax: "icu1" | "mf2";
|
|
412
|
+
messages: Record<string, string>;
|
|
413
|
+
}, {
|
|
414
|
+
locale: string;
|
|
415
|
+
version: "catalog@1";
|
|
416
|
+
namespace: string;
|
|
417
|
+
messages: Record<string, string>;
|
|
418
|
+
syntax?: "icu1" | "mf2" | undefined;
|
|
419
|
+
}>;
|
|
420
|
+
type CatalogDoc = z.infer<typeof CatalogDocSchema>;
|
|
421
|
+
|
|
422
|
+
declare const EXPERIENCE_EXIT: {
|
|
423
|
+
readonly ok: 0;
|
|
424
|
+
readonly invalid: 1;
|
|
425
|
+
readonly usage: 2;
|
|
426
|
+
readonly auth: 3;
|
|
427
|
+
readonly conflict: 4;
|
|
428
|
+
readonly failure: 5;
|
|
429
|
+
};
|
|
430
|
+
/** El documento tal como se escribe a disco: orden fijo de campos y mensajes ordenados por clave (diffs estables en Git). */
|
|
431
|
+
declare function serializeCatalog(doc: CatalogDoc): string;
|
|
432
|
+
declare function runExperienceCli(args: string[], io: CliIo): Promise<number>;
|
|
433
|
+
|
|
434
|
+
declare const WHATSAPP_EXIT: {
|
|
435
|
+
readonly ok: 0;
|
|
436
|
+
readonly failure: 1;
|
|
437
|
+
readonly unsupported: 2;
|
|
438
|
+
readonly auth: 3;
|
|
439
|
+
readonly findings: 4;
|
|
440
|
+
};
|
|
441
|
+
declare function runWhatsAppCli(args: string[], io: CliIo): Promise<number>;
|
|
442
|
+
|
|
443
|
+
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 };
|
package/dist/index.d.ts
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
|
|
|
@@ -299,7 +303,12 @@ declare function validateManifest(input: unknown): {
|
|
|
299
303
|
type SyncOptions = {
|
|
300
304
|
manifest: AppManifest;
|
|
301
305
|
accessUrl: string;
|
|
302
|
-
|
|
306
|
+
/** Token de administrador del Workspace: viaja como `Authorization: Bearer`. */
|
|
307
|
+
token?: string;
|
|
308
|
+
/** Secreto de administrador de Access: viaja como `x-admin-secret` (lo que acepta Access de producción). Manda sobre `token`. */
|
|
309
|
+
adminSecret?: string;
|
|
310
|
+
/** Quién opera (`x-actor`); Access con `ADMIN_SECRET_MODE=require-actor` lo exige junto a `x-reason` (8+ caracteres). */
|
|
311
|
+
actor?: string;
|
|
303
312
|
workspaceEnvironmentId: string;
|
|
304
313
|
reason: string;
|
|
305
314
|
fetch?: typeof fetch;
|
|
@@ -324,13 +333,16 @@ type SyncResult = {
|
|
|
324
333
|
applicationId: string;
|
|
325
334
|
environmentId: string;
|
|
326
335
|
revision: number;
|
|
336
|
+
/** Clave pública (`pk_…`) del entorno de la app; no es secreta. Va al `.env` de la app. `null` si Access no la devuelve. */
|
|
337
|
+
publishableKey: string | null;
|
|
327
338
|
/** Cómo quedó cada producto; vacío si Access no lo informa. */
|
|
328
339
|
reconciliation: Record<string, ProductReconciliation>;
|
|
329
340
|
};
|
|
330
341
|
declare class SyncError extends Error {
|
|
331
342
|
readonly code: string;
|
|
332
343
|
readonly status: number;
|
|
333
|
-
|
|
344
|
+
readonly hint?: string | undefined;
|
|
345
|
+
constructor(code: string, status: number, hint?: string | undefined);
|
|
334
346
|
}
|
|
335
347
|
declare function syncApp(options: SyncOptions): Promise<SyncResult>;
|
|
336
348
|
|
|
@@ -370,4 +382,62 @@ declare const EXPERIMENTS_EXIT: {
|
|
|
370
382
|
};
|
|
371
383
|
declare function runExperimentsCli(group: string, args: string[], io: CliIo): Promise<number>;
|
|
372
384
|
|
|
373
|
-
|
|
385
|
+
/**
|
|
386
|
+
* `catalog@1`: traducciones como DATOS versionados, en lugar de textos escritos en el código.
|
|
387
|
+
*
|
|
388
|
+
* Plan: docs/CUSTOMY_EXPERIENCE_CONTROL_PLANE_PLAN.md (§5.7). Es el contrato que usan, sin duplicarse, el motor `@customy/i18n`, el design system
|
|
389
|
+
* (`DesignSystemMessagesProvider` sustituye textos por clave) y los componentes propios (`{ $t: "clave" }` en `component-registry.ts`).
|
|
390
|
+
*
|
|
391
|
+
* 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**
|
|
392
|
+
* 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.
|
|
393
|
+
*
|
|
394
|
+
* Qué garantiza:
|
|
395
|
+
* 1. `validateCatalog`: forma, claves, mensajes ICU bien formados (llaves, plurales con `other`), sin HTML, límites por plan.
|
|
396
|
+
* 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.
|
|
397
|
+
* 3. `parityReport`: qué idioma no tiene una clave y dónde un mensaje cambió de variables entre idiomas.
|
|
398
|
+
* 4. `resolveCatalog`: capas (plataforma → organización → entorno) y cadena de respaldo de idiomas; nunca devuelve una clave cruda.
|
|
399
|
+
*/
|
|
400
|
+
|
|
401
|
+
declare const CatalogDocSchema: z.ZodObject<{
|
|
402
|
+
version: z.ZodLiteral<"catalog@1">;
|
|
403
|
+
namespace: z.ZodString;
|
|
404
|
+
locale: z.ZodString;
|
|
405
|
+
syntax: z.ZodDefault<z.ZodEnum<["icu1", "mf2"]>>;
|
|
406
|
+
messages: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
407
|
+
}, "strict", z.ZodTypeAny, {
|
|
408
|
+
locale: string;
|
|
409
|
+
version: "catalog@1";
|
|
410
|
+
namespace: string;
|
|
411
|
+
syntax: "icu1" | "mf2";
|
|
412
|
+
messages: Record<string, string>;
|
|
413
|
+
}, {
|
|
414
|
+
locale: string;
|
|
415
|
+
version: "catalog@1";
|
|
416
|
+
namespace: string;
|
|
417
|
+
messages: Record<string, string>;
|
|
418
|
+
syntax?: "icu1" | "mf2" | undefined;
|
|
419
|
+
}>;
|
|
420
|
+
type CatalogDoc = z.infer<typeof CatalogDocSchema>;
|
|
421
|
+
|
|
422
|
+
declare const EXPERIENCE_EXIT: {
|
|
423
|
+
readonly ok: 0;
|
|
424
|
+
readonly invalid: 1;
|
|
425
|
+
readonly usage: 2;
|
|
426
|
+
readonly auth: 3;
|
|
427
|
+
readonly conflict: 4;
|
|
428
|
+
readonly failure: 5;
|
|
429
|
+
};
|
|
430
|
+
/** El documento tal como se escribe a disco: orden fijo de campos y mensajes ordenados por clave (diffs estables en Git). */
|
|
431
|
+
declare function serializeCatalog(doc: CatalogDoc): string;
|
|
432
|
+
declare function runExperienceCli(args: string[], io: CliIo): Promise<number>;
|
|
433
|
+
|
|
434
|
+
declare const WHATSAPP_EXIT: {
|
|
435
|
+
readonly ok: 0;
|
|
436
|
+
readonly failure: 1;
|
|
437
|
+
readonly unsupported: 2;
|
|
438
|
+
readonly auth: 3;
|
|
439
|
+
readonly findings: 4;
|
|
440
|
+
};
|
|
441
|
+
declare function runWhatsAppCli(args: string[], io: CliIo): Promise<number>;
|
|
442
|
+
|
|
443
|
+
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 };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { EXPERIMENTS_EXIT as EXPERIMENTS_EXIT_CODES, EXIT as PROVISIONING_EXIT_CODES, SyncError, generateAppTypes, runCli, runExperimentsCli, runProvisioningCli, schemaToType, syncApp, validateManifest } from './chunk-
|
|
1
|
+
export { EXPERIENCE_EXIT as EXPERIENCE_EXIT_CODES, EXPERIMENTS_EXIT as EXPERIMENTS_EXIT_CODES, EXIT as PROVISIONING_EXIT_CODES, SyncError, WHATSAPP_EXIT as WHATSAPP_EXIT_CODES, generateAppTypes, runCli, runExperienceCli, runExperimentsCli, runProvisioningCli, runWhatsAppCli, schemaToType, serializeCatalog, syncApp, validateManifest } from './chunk-VA4VPLZ4.mjs';
|
|
2
|
+
import './chunk-QKIF4C5R.mjs';
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { utf8ByteLength, I18nToolsError, compareCodeUnits } from './chunk-BYMLRMNS.mjs';
|
|
2
|
+
import { CATALOG_KEY } from './chunk-QKIF4C5R.mjs';
|
|
3
|
+
|
|
4
|
+
// src/vendor/i18n-tools/json.ts
|
|
5
|
+
var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
6
|
+
function parseFlatJson(input, options = {}) {
|
|
7
|
+
const maxBytes = options.maxBytes ?? 4 * 1024 * 1024;
|
|
8
|
+
if (input.length > maxBytes || utf8ByteLength(input) > maxBytes) throw new I18nToolsError("too-large", `el JSON pasa de ${maxBytes} bytes`);
|
|
9
|
+
let data;
|
|
10
|
+
try {
|
|
11
|
+
data = JSON.parse(input.charCodeAt(0) === 65279 ? input.slice(1) : input);
|
|
12
|
+
} catch (e) {
|
|
13
|
+
throw new I18nToolsError("malformed-json", `JSON no v\xE1lido: ${e.message}`);
|
|
14
|
+
}
|
|
15
|
+
if (!isObject(data)) throw new I18nToolsError("malformed-json", "se esperaba un objeto en la ra\xEDz");
|
|
16
|
+
const strict = options.strictKeys !== false;
|
|
17
|
+
const maxDepth = options.maxDepth ?? 8;
|
|
18
|
+
const messages = [];
|
|
19
|
+
const descriptions = [];
|
|
20
|
+
const seen = /* @__PURE__ */ new Set();
|
|
21
|
+
const add = (key, value) => {
|
|
22
|
+
if (strict && !CATALOG_KEY.test(key)) throw new I18nToolsError("invalid-key", `clave no v\xE1lida \xAB${key}\xBB`);
|
|
23
|
+
if (seen.has(key)) throw new I18nToolsError("duplicate-key", `clave repetida \xAB${key}\xBB (tras aplanar)`);
|
|
24
|
+
seen.add(key);
|
|
25
|
+
if (typeof value === "string") {
|
|
26
|
+
messages.push([key, value]);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (isObject(value)) {
|
|
30
|
+
const message = value["message"] ?? value["defaultMessage"];
|
|
31
|
+
if (typeof message === "string") {
|
|
32
|
+
messages.push([key, message]);
|
|
33
|
+
const d = value["description"];
|
|
34
|
+
if (typeof d === "string" && d !== "") descriptions.push([key, d]);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
throw new I18nToolsError("malformed-json", `el valor de \xAB${key}\xBB debe ser un texto o un objeto con \xABmessage\xBB`);
|
|
39
|
+
};
|
|
40
|
+
const stack = [{ prefix: "", obj: data, depth: 1 }];
|
|
41
|
+
while (stack.length > 0) {
|
|
42
|
+
const { prefix, obj, depth } = stack.pop();
|
|
43
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
44
|
+
const key = prefix ? `${prefix}.${k}` : k;
|
|
45
|
+
const isLeafObject = isObject(v) && (typeof v["message"] === "string" || typeof v["defaultMessage"] === "string");
|
|
46
|
+
if (options.nested && isObject(v) && !isLeafObject) {
|
|
47
|
+
if (depth >= maxDepth) throw new I18nToolsError("too-deep", `anidamiento de m\xE1s de ${maxDepth} niveles`);
|
|
48
|
+
stack.push({ prefix: key, obj: v, depth: depth + 1 });
|
|
49
|
+
} else add(key, v);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
messages.sort((a, b) => compareCodeUnits(a[0], b[0]));
|
|
53
|
+
descriptions.sort((a, b) => compareCodeUnits(a[0], b[0]));
|
|
54
|
+
return { messages: Object.fromEntries(messages), descriptions: Object.fromEntries(descriptions) };
|
|
55
|
+
}
|
|
56
|
+
function stringifyFlatJson(messages, options = {}) {
|
|
57
|
+
const entries = Object.keys(messages).sort(compareCodeUnits).map((k) => {
|
|
58
|
+
const message = messages[k] ?? "";
|
|
59
|
+
const description = options.descriptions?.[k];
|
|
60
|
+
const value = options.style === "described" ? description ? { message, description } : { message } : message;
|
|
61
|
+
return [k, value];
|
|
62
|
+
});
|
|
63
|
+
return `${JSON.stringify(Object.fromEntries(entries), null, options.indent ?? 2)}
|
|
64
|
+
`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { parseFlatJson, stringifyFlatJson };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkMFJL3NO5_cjs = require('./chunk-MFJL3NO5.cjs');
|
|
4
|
+
var chunk2A6WFLXS_cjs = require('./chunk-2A6WFLXS.cjs');
|
|
5
|
+
|
|
6
|
+
// src/vendor/i18n-tools/json.ts
|
|
7
|
+
var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
8
|
+
function parseFlatJson(input, options = {}) {
|
|
9
|
+
const maxBytes = options.maxBytes ?? 4 * 1024 * 1024;
|
|
10
|
+
if (input.length > maxBytes || chunkMFJL3NO5_cjs.utf8ByteLength(input) > maxBytes) throw new chunkMFJL3NO5_cjs.I18nToolsError("too-large", `el JSON pasa de ${maxBytes} bytes`);
|
|
11
|
+
let data;
|
|
12
|
+
try {
|
|
13
|
+
data = JSON.parse(input.charCodeAt(0) === 65279 ? input.slice(1) : input);
|
|
14
|
+
} catch (e) {
|
|
15
|
+
throw new chunkMFJL3NO5_cjs.I18nToolsError("malformed-json", `JSON no v\xE1lido: ${e.message}`);
|
|
16
|
+
}
|
|
17
|
+
if (!isObject(data)) throw new chunkMFJL3NO5_cjs.I18nToolsError("malformed-json", "se esperaba un objeto en la ra\xEDz");
|
|
18
|
+
const strict = options.strictKeys !== false;
|
|
19
|
+
const maxDepth = options.maxDepth ?? 8;
|
|
20
|
+
const messages = [];
|
|
21
|
+
const descriptions = [];
|
|
22
|
+
const seen = /* @__PURE__ */ new Set();
|
|
23
|
+
const add = (key, value) => {
|
|
24
|
+
if (strict && !chunk2A6WFLXS_cjs.CATALOG_KEY.test(key)) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-key", `clave no v\xE1lida \xAB${key}\xBB`);
|
|
25
|
+
if (seen.has(key)) throw new chunkMFJL3NO5_cjs.I18nToolsError("duplicate-key", `clave repetida \xAB${key}\xBB (tras aplanar)`);
|
|
26
|
+
seen.add(key);
|
|
27
|
+
if (typeof value === "string") {
|
|
28
|
+
messages.push([key, value]);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (isObject(value)) {
|
|
32
|
+
const message = value["message"] ?? value["defaultMessage"];
|
|
33
|
+
if (typeof message === "string") {
|
|
34
|
+
messages.push([key, message]);
|
|
35
|
+
const d = value["description"];
|
|
36
|
+
if (typeof d === "string" && d !== "") descriptions.push([key, d]);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
throw new chunkMFJL3NO5_cjs.I18nToolsError("malformed-json", `el valor de \xAB${key}\xBB debe ser un texto o un objeto con \xABmessage\xBB`);
|
|
41
|
+
};
|
|
42
|
+
const stack = [{ prefix: "", obj: data, depth: 1 }];
|
|
43
|
+
while (stack.length > 0) {
|
|
44
|
+
const { prefix, obj, depth } = stack.pop();
|
|
45
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
46
|
+
const key = prefix ? `${prefix}.${k}` : k;
|
|
47
|
+
const isLeafObject = isObject(v) && (typeof v["message"] === "string" || typeof v["defaultMessage"] === "string");
|
|
48
|
+
if (options.nested && isObject(v) && !isLeafObject) {
|
|
49
|
+
if (depth >= maxDepth) throw new chunkMFJL3NO5_cjs.I18nToolsError("too-deep", `anidamiento de m\xE1s de ${maxDepth} niveles`);
|
|
50
|
+
stack.push({ prefix: key, obj: v, depth: depth + 1 });
|
|
51
|
+
} else add(key, v);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
messages.sort((a, b) => chunkMFJL3NO5_cjs.compareCodeUnits(a[0], b[0]));
|
|
55
|
+
descriptions.sort((a, b) => chunkMFJL3NO5_cjs.compareCodeUnits(a[0], b[0]));
|
|
56
|
+
return { messages: Object.fromEntries(messages), descriptions: Object.fromEntries(descriptions) };
|
|
57
|
+
}
|
|
58
|
+
function stringifyFlatJson(messages, options = {}) {
|
|
59
|
+
const entries = Object.keys(messages).sort(chunkMFJL3NO5_cjs.compareCodeUnits).map((k) => {
|
|
60
|
+
const message = messages[k] ?? "";
|
|
61
|
+
const description = options.descriptions?.[k];
|
|
62
|
+
const value = options.style === "described" ? description ? { message, description } : { message } : message;
|
|
63
|
+
return [k, value];
|
|
64
|
+
});
|
|
65
|
+
return `${JSON.stringify(Object.fromEntries(entries), null, options.indent ?? 2)}
|
|
66
|
+
`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
exports.parseFlatJson = parseFlatJson;
|
|
70
|
+
exports.stringifyFlatJson = stringifyFlatJson;
|