@vol-a/lookups 0.0.0-stage → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +11 -2
- package/dist/candidates.d.ts +48 -0
- package/dist/candidates.d.ts.map +1 -0
- package/dist/candidates.js +103 -0
- package/dist/candidates.js.map +1 -0
- package/dist/codegen.d.ts +21 -0
- package/dist/codegen.d.ts.map +1 -0
- package/dist/codegen.js +52 -0
- package/dist/codegen.js.map +1 -0
- package/dist/compile.d.ts +18 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +66 -0
- package/dist/compile.js.map +1 -0
- package/dist/csv.d.ts +37 -0
- package/dist/csv.d.ts.map +1 -0
- package/dist/csv.js +169 -0
- package/dist/csv.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/load.d.ts +21 -0
- package/dist/load.d.ts.map +1 -0
- package/dist/load.js +40 -0
- package/dist/load.js.map +1 -0
- package/dist/normalize.d.ts +7 -0
- package/dist/normalize.d.ts.map +1 -0
- package/dist/normalize.js +31 -0
- package/dist/normalize.js.map +1 -0
- package/dist/promote.d.ts +47 -0
- package/dist/promote.d.ts.map +1 -0
- package/dist/promote.js +196 -0
- package/dist/promote.js.map +1 -0
- package/dist/registry.d.ts +29 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +63 -0
- package/dist/registry.js.map +1 -0
- package/package.json +43 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Digital Cube
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @vol-a/lookups
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Controlled vocabularies for JSVola: the `lookups.yaml` compiler and registry, CSV
|
|
4
|
+
translations with a validator, candidate recording for unknown values, promotion of
|
|
5
|
+
candidates back into the vocabulary, and TypeScript/Zod codegen. Same format and API as
|
|
6
|
+
`@memento/lookups` (JSMemento); a copy, not a dependency.
|
|
7
|
+
|
|
8
|
+
Part of [JSVola](https://github.com/digital-cube/jsvola), self-hosted, multi-tenant
|
|
9
|
+
content-addressable file storage. The vocabulary itself (`lookups.yaml`,
|
|
10
|
+
`i18n/translations.csv`) lives at the repository root and is served by `GET /vola/lookups`.
|
|
11
|
+
|
|
12
|
+
Requires Node 24+. MIT licensed.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { LookupRegistry } from "./registry.js";
|
|
2
|
+
/** One unknown value seen at ingestion, waiting to be promoted into `lookups.yaml`. */
|
|
3
|
+
export interface Candidate {
|
|
4
|
+
value: string;
|
|
5
|
+
count: number;
|
|
6
|
+
first_seen: string;
|
|
7
|
+
last_seen: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const CANDIDATES_CSV = "translations_candidate.csv";
|
|
10
|
+
export interface CandidateRecorderOptions {
|
|
11
|
+
/** Where `<Section>.yaml` files and `translations_candidate.csv` are written. */
|
|
12
|
+
dir: string;
|
|
13
|
+
/** Known terms are never recorded. */
|
|
14
|
+
registry: LookupRegistry;
|
|
15
|
+
/** Locale columns pre-filled in the candidate CSV. Default `["en", "sr"]`. */
|
|
16
|
+
locales?: readonly string[];
|
|
17
|
+
/** Receives IO/parse failures; recording never throws. */
|
|
18
|
+
onError?: (error: unknown) => void;
|
|
19
|
+
now?: () => Date;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Records values that are not (yet) in the vocabulary — `var/candidates/EventTypes.yaml`
|
|
23
|
+
* gets `{ value, count, first_seen, last_seen }` per unknown term, and the shared
|
|
24
|
+
* `translations_candidate.csv` gets a row a translator can fill in and paste into
|
|
25
|
+
* `i18n/translations.csv`. Writes are serialized and best-effort: a failure is reported
|
|
26
|
+
* to `onError` and ingestion goes on.
|
|
27
|
+
*/
|
|
28
|
+
export declare class CandidateRecorder {
|
|
29
|
+
readonly dir: string;
|
|
30
|
+
private readonly registry;
|
|
31
|
+
private readonly locales;
|
|
32
|
+
private readonly onError;
|
|
33
|
+
private readonly now;
|
|
34
|
+
private queue;
|
|
35
|
+
constructor(options: CandidateRecorderOptions);
|
|
36
|
+
/**
|
|
37
|
+
* Records `value` under `section` unless it is empty or already a known term. Resolves
|
|
38
|
+
* to the normalized term when it was recorded, `null` otherwise.
|
|
39
|
+
*/
|
|
40
|
+
record(section: string, value: string | null | undefined): Promise<string | null>;
|
|
41
|
+
/** Every recorded candidate of `section`, sorted by value. */
|
|
42
|
+
list(section: string): Promise<Candidate[]>;
|
|
43
|
+
private read;
|
|
44
|
+
private yamlPath;
|
|
45
|
+
private write;
|
|
46
|
+
private appendCsv;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=candidates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"candidates.d.ts","sourceRoot":"","sources":["../src/candidates.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,uFAAuF;AACvF,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,cAAc,+BAA+B,CAAC;AAE3D,MAAM,WAAW,wBAAwB;IACvC,iFAAiF;IACjF,GAAG,EAAE,MAAM,CAAC;IACZ,sCAAsC;IACtC,QAAQ,EAAE,cAAc,CAAC;IACzB,8EAA8E;IAC9E,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,0DAA0D;IAC1D,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACnC,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAClB;AAED;;;;;;GAMG;AACH,qBAAa,iBAAiB;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAiB;IAC1C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;IAC5C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA2B;IACnD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAa;IACjC,OAAO,CAAC,KAAK,CAAoC;gBAErC,OAAO,EAAE,wBAAwB;IAQ7C;;;OAGG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAiBjF,8DAA8D;IACxD,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;YAKnC,IAAI;IAYlB,OAAO,CAAC,QAAQ;YAIF,KAAK;YAoBL,SAAS;CAexB"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { parse, stringify } from "yaml";
|
|
4
|
+
import { formatCsvRow, parseCsv } from "./csv.js";
|
|
5
|
+
import { normalizeTerm } from "./normalize.js";
|
|
6
|
+
export const CANDIDATES_CSV = "translations_candidate.csv";
|
|
7
|
+
/**
|
|
8
|
+
* Records values that are not (yet) in the vocabulary — `var/candidates/EventTypes.yaml`
|
|
9
|
+
* gets `{ value, count, first_seen, last_seen }` per unknown term, and the shared
|
|
10
|
+
* `translations_candidate.csv` gets a row a translator can fill in and paste into
|
|
11
|
+
* `i18n/translations.csv`. Writes are serialized and best-effort: a failure is reported
|
|
12
|
+
* to `onError` and ingestion goes on.
|
|
13
|
+
*/
|
|
14
|
+
export class CandidateRecorder {
|
|
15
|
+
dir;
|
|
16
|
+
registry;
|
|
17
|
+
locales;
|
|
18
|
+
onError;
|
|
19
|
+
now;
|
|
20
|
+
queue = Promise.resolve();
|
|
21
|
+
constructor(options) {
|
|
22
|
+
this.dir = options.dir;
|
|
23
|
+
this.registry = options.registry;
|
|
24
|
+
this.locales = options.locales ?? ["en", "sr"];
|
|
25
|
+
this.onError = options.onError ?? (() => { });
|
|
26
|
+
this.now = options.now ?? (() => new Date());
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Records `value` under `section` unless it is empty or already a known term. Resolves
|
|
30
|
+
* to the normalized term when it was recorded, `null` otherwise.
|
|
31
|
+
*/
|
|
32
|
+
record(section, value) {
|
|
33
|
+
const term = value ? normalizeTerm(value) : "";
|
|
34
|
+
if (!term || this.registry.has(section, term))
|
|
35
|
+
return Promise.resolve(null);
|
|
36
|
+
const task = this.queue.then(() => this.write(section, term));
|
|
37
|
+
this.queue = task.then(() => undefined, () => undefined);
|
|
38
|
+
return task.then(() => term, (error) => {
|
|
39
|
+
this.onError(error);
|
|
40
|
+
return null;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/** Every recorded candidate of `section`, sorted by value. */
|
|
44
|
+
async list(section) {
|
|
45
|
+
await this.queue;
|
|
46
|
+
return this.read(section);
|
|
47
|
+
}
|
|
48
|
+
async read(section) {
|
|
49
|
+
let text;
|
|
50
|
+
try {
|
|
51
|
+
text = await readFile(this.yamlPath(section), "utf8");
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
if (error.code === "ENOENT")
|
|
55
|
+
return [];
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
const data = parse(text);
|
|
59
|
+
return Array.isArray(data) ? data : [];
|
|
60
|
+
}
|
|
61
|
+
yamlPath(section) {
|
|
62
|
+
return join(this.dir, `${section}.yaml`);
|
|
63
|
+
}
|
|
64
|
+
async write(section, term) {
|
|
65
|
+
await mkdir(this.dir, { recursive: true });
|
|
66
|
+
const candidates = await this.read(section);
|
|
67
|
+
const now = this.now()
|
|
68
|
+
.toISOString()
|
|
69
|
+
.replace(/\.\d{3}Z$/, "Z");
|
|
70
|
+
const existing = candidates.find((candidate) => candidate.value === term);
|
|
71
|
+
if (existing) {
|
|
72
|
+
existing.count += 1;
|
|
73
|
+
existing.last_seen = now;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
candidates.push({ value: term, count: 1, first_seen: now, last_seen: now });
|
|
77
|
+
candidates.sort((a, b) => a.value.localeCompare(b.value));
|
|
78
|
+
}
|
|
79
|
+
const path = this.yamlPath(section);
|
|
80
|
+
await writeFile(`${path}.tmp`, stringify(candidates));
|
|
81
|
+
await rename(`${path}.tmp`, path);
|
|
82
|
+
if (!existing)
|
|
83
|
+
await this.appendCsv(section, term);
|
|
84
|
+
}
|
|
85
|
+
async appendCsv(section, term) {
|
|
86
|
+
const path = join(this.dir, CANDIDATES_CSV);
|
|
87
|
+
let text;
|
|
88
|
+
try {
|
|
89
|
+
text = await readFile(path, "utf8");
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
if (error.code !== "ENOENT")
|
|
93
|
+
throw error;
|
|
94
|
+
text = `${formatCsvRow(["section", "term", ...this.locales])}\n`;
|
|
95
|
+
}
|
|
96
|
+
if (parseCsv(text, ",").some(({ cells }) => cells[0] === section && cells[1] === term)) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const row = formatCsvRow([section, term, ...this.locales.map(() => term)]);
|
|
100
|
+
await writeFile(path, `${text}${row}\n`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=candidates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"candidates.js","sourceRoot":"","sources":["../src/candidates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAW/C,MAAM,CAAC,MAAM,cAAc,GAAG,4BAA4B,CAAC;AAc3D;;;;;;GAMG;AACH,MAAM,OAAO,iBAAiB;IACnB,GAAG,CAAS;IACJ,QAAQ,CAAiB;IACzB,OAAO,CAAoB;IAC3B,OAAO,CAA2B;IAClC,GAAG,CAAa;IACzB,KAAK,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IAEjD,YAAY,OAAiC;QAC3C,IAAI,CAAC,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AAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,EAAE,CAAC;YACvF,OAAO;QACT,CAAC;QACD,MAAM,GAAG,GAAG,YAAY,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC3E,MAAM,SAAS,CAAC,IAAI,EAAE,GAAG,IAAI,GAAG,GAAG,IAAI,CAAC,CAAC;IAC3C,CAAC;CACF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { LookupRegistry } from "./registry.js";
|
|
2
|
+
export interface CodegenOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Sections whose wire values are lower case: the term `USER` of `InstanceTypes` is sent
|
|
5
|
+
* as `"user"`. Other sections keep the term as is (`USER_LOGIN`).
|
|
6
|
+
*/
|
|
7
|
+
lowercase?: readonly string[];
|
|
8
|
+
/** Named in the header comment. Default `lookups.yaml`. */
|
|
9
|
+
source?: string;
|
|
10
|
+
}
|
|
11
|
+
/** `EventTypes` → `EVENT_TYPES`, `Statuses.Ticket` → `STATUSES_TICKET`. */
|
|
12
|
+
export declare function constantName(section: string): string;
|
|
13
|
+
/** `EventTypes` → `EventType`, `Statuses.Ticket` → `StatusesTicket`. */
|
|
14
|
+
export declare function typeName(section: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Generates a TypeScript module from a registry: per section a `readonly` tuple of wire
|
|
17
|
+
* values, a string enum and a Zod `z.enum`. Deterministic, so a test can compare the
|
|
18
|
+
* committed file against what the current `lookups.yaml` would produce.
|
|
19
|
+
*/
|
|
20
|
+
export declare function generateLookupsModule(registry: LookupRegistry, options?: CodegenOptions): string;
|
|
21
|
+
//# sourceMappingURL=codegen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../src/codegen.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,2DAA2D;IAC3D,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAiBD,2EAA2E;AAC3E,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAMpD;AAED,wEAAwE;AACxE,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGhD;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,cAAc,EACxB,OAAO,GAAE,cAAmB,GAC3B,MAAM,CAwBR"}
|
package/dist/codegen.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
function singular(word) {
|
|
2
|
+
if (word.endsWith("ies"))
|
|
3
|
+
return `${word.slice(0, -3)}y`;
|
|
4
|
+
if (/(ss|us|x|ch|sh)es$/.test(word))
|
|
5
|
+
return word.slice(0, -2);
|
|
6
|
+
if (word.endsWith("s") && !word.endsWith("ss"))
|
|
7
|
+
return word.slice(0, -1);
|
|
8
|
+
return word;
|
|
9
|
+
}
|
|
10
|
+
function pascal(word) {
|
|
11
|
+
return word
|
|
12
|
+
.split("_")
|
|
13
|
+
.filter(Boolean)
|
|
14
|
+
.map((part) => part[0].toUpperCase() + part.slice(1))
|
|
15
|
+
.join("");
|
|
16
|
+
}
|
|
17
|
+
/** `EventTypes` → `EVENT_TYPES`, `Statuses.Ticket` → `STATUSES_TICKET`. */
|
|
18
|
+
export function constantName(section) {
|
|
19
|
+
return section
|
|
20
|
+
.split(".")
|
|
21
|
+
.map((part) => part.replace(/([a-z0-9])([A-Z])/g, "$1_$2"))
|
|
22
|
+
.join("_")
|
|
23
|
+
.toUpperCase();
|
|
24
|
+
}
|
|
25
|
+
/** `EventTypes` → `EventType`, `Statuses.Ticket` → `StatusesTicket`. */
|
|
26
|
+
export function typeName(section) {
|
|
27
|
+
const parts = section.split(".").map(pascal);
|
|
28
|
+
return parts.length === 1 ? singular(parts[0]) : parts.join("");
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Generates a TypeScript module from a registry: per section a `readonly` tuple of wire
|
|
32
|
+
* values, a string enum and a Zod `z.enum`. Deterministic, so a test can compare the
|
|
33
|
+
* committed file against what the current `lookups.yaml` would produce.
|
|
34
|
+
*/
|
|
35
|
+
export function generateLookupsModule(registry, options = {}) {
|
|
36
|
+
const lowercase = new Set(options.lowercase ?? []);
|
|
37
|
+
const lines = [
|
|
38
|
+
`// Generated from ${options.source ?? "lookups.yaml"} by \`memento lookups codegen\`.`,
|
|
39
|
+
"// Do not edit by hand: change the YAML and regenerate.",
|
|
40
|
+
'import { z } from "zod";',
|
|
41
|
+
"",
|
|
42
|
+
];
|
|
43
|
+
for (const section of registry.sectionNames()) {
|
|
44
|
+
const terms = registry.terms(section);
|
|
45
|
+
const wire = (term) => (lowercase.has(section) ? term.toLowerCase() : term);
|
|
46
|
+
const constant = constantName(section);
|
|
47
|
+
const type = typeName(section);
|
|
48
|
+
lines.push(`/** \`${section}\` from the vocabulary, as sent on the wire. */`, `export const ${constant} = [${terms.map((t) => JSON.stringify(wire(t))).join(", ")}] as const;`, `export enum ${type} {`, ...terms.map((term) => ` ${term} = ${JSON.stringify(wire(term))},`), "}", `export const Known${type}Schema = z.enum(${constant});`, "");
|
|
49
|
+
}
|
|
50
|
+
return lines.join("\n");
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=codegen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codegen.js","sourceRoot":"","sources":["../src/codegen.ts"],"names":[],"mappings":"AAYA,SAAS,QAAQ,CAAC,IAAY;IAC5B,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,GAAG,IAAI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,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** A namespace is a flat list of terms or a mapping of nested namespaces. */
|
|
2
|
+
export type LookupNode = readonly string[] | {
|
|
3
|
+
readonly [key: string]: LookupNode;
|
|
4
|
+
};
|
|
5
|
+
export type LookupTree = {
|
|
6
|
+
readonly [namespace: string]: LookupNode;
|
|
7
|
+
};
|
|
8
|
+
/** Terms are UPPER_SNAKE_CASE, so they are valid enum keys and stable across locales. */
|
|
9
|
+
export declare const TERM_RE: RegExp;
|
|
10
|
+
export declare class LookupCompileError extends Error {
|
|
11
|
+
name: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Compiles the text of a `lookups.yaml` into a validated tree. `source` names the file
|
|
15
|
+
* in error messages.
|
|
16
|
+
*/
|
|
17
|
+
export declare function compileLookups(text: string, source?: string): LookupTree;
|
|
18
|
+
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAEA,6EAA6E;AAC7E,MAAM,MAAM,UAAU,GAAG,SAAS,MAAM,EAAE,GAAG;IAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;CAAE,CAAC;AACpF,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU,CAAA;CAAE,CAAC;AAEtE,yFAAyF;AACzF,eAAO,MAAM,OAAO,QAAsB,CAAC;AAI3C,qBAAa,kBAAmB,SAAQ,KAAK;IAClC,IAAI,SAAwB;CACtC;AA8BD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,SAAiB,GAAG,UAAU,CAsBhF"}
|
package/dist/compile.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { parse, YAMLParseError } from "yaml";
|
|
2
|
+
/** Terms are UPPER_SNAKE_CASE, so they are valid enum keys and stable across locales. */
|
|
3
|
+
export const TERM_RE = /^[A-Z][A-Z0-9_]*$/;
|
|
4
|
+
/** Namespace keys are PascalCase-ish identifiers: `EventTypes`, `InstanceTypes`. */
|
|
5
|
+
const NAMESPACE_RE = /^[A-Za-z][A-Za-z0-9_]*$/;
|
|
6
|
+
export class LookupCompileError extends Error {
|
|
7
|
+
name = "LookupCompileError";
|
|
8
|
+
}
|
|
9
|
+
function normalizeNode(body, path) {
|
|
10
|
+
if (Array.isArray(body)) {
|
|
11
|
+
const seen = new Set();
|
|
12
|
+
for (const term of body) {
|
|
13
|
+
if (typeof term !== "string") {
|
|
14
|
+
throw new LookupCompileError(`${path}: term must be a string, got ${typeof term}`);
|
|
15
|
+
}
|
|
16
|
+
if (!TERM_RE.test(term)) {
|
|
17
|
+
throw new LookupCompileError(`${path}: term "${term}" must be UPPER_SNAKE_CASE`);
|
|
18
|
+
}
|
|
19
|
+
if (seen.has(term))
|
|
20
|
+
throw new LookupCompileError(`${path}: duplicate term "${term}"`);
|
|
21
|
+
seen.add(term);
|
|
22
|
+
}
|
|
23
|
+
return [...body];
|
|
24
|
+
}
|
|
25
|
+
if (body !== null && typeof body === "object") {
|
|
26
|
+
const out = {};
|
|
27
|
+
for (const [key, value] of Object.entries(body)) {
|
|
28
|
+
if (!NAMESPACE_RE.test(key)) {
|
|
29
|
+
throw new LookupCompileError(`${path}: invalid namespace key "${key}"`);
|
|
30
|
+
}
|
|
31
|
+
out[key] = normalizeNode(value, `${path}.${key}`);
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
throw new LookupCompileError(`${path}: expected a list or a mapping`);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Compiles the text of a `lookups.yaml` into a validated tree. `source` names the file
|
|
39
|
+
* in error messages.
|
|
40
|
+
*/
|
|
41
|
+
export function compileLookups(text, source = "lookups.yaml") {
|
|
42
|
+
let raw;
|
|
43
|
+
try {
|
|
44
|
+
raw = parse(text);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (error instanceof YAMLParseError) {
|
|
48
|
+
throw new LookupCompileError(`${source}: YAML parse error: ${error.message}`);
|
|
49
|
+
}
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
if (raw === null || raw === undefined)
|
|
53
|
+
return {};
|
|
54
|
+
if (typeof raw !== "object" || Array.isArray(raw)) {
|
|
55
|
+
throw new LookupCompileError(`${source}: top level must be a mapping of namespaces`);
|
|
56
|
+
}
|
|
57
|
+
const tree = {};
|
|
58
|
+
for (const [namespace, body] of Object.entries(raw)) {
|
|
59
|
+
if (!NAMESPACE_RE.test(namespace)) {
|
|
60
|
+
throw new LookupCompileError(`${source}: invalid namespace "${namespace}"`);
|
|
61
|
+
}
|
|
62
|
+
tree[namespace] = normalizeNode(body, namespace);
|
|
63
|
+
}
|
|
64
|
+
return tree;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=compile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.js","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAM7C,yFAAyF;AACzF,MAAM,CAAC,MAAM,OAAO,GAAG,mBAAmB,CAAC;AAC3C,oFAAoF;AACpF,MAAM,YAAY,GAAG,yBAAyB,CAAC;AAE/C,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAClC,IAAI,GAAG,oBAAoB,CAAC;CACtC;AAED,SAAS,aAAa,CAAC,IAAa,EAAE,IAAY;IAChD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;QAC/B,KAAK,MAAM,IAAI,IAAI,IAAI,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,GAAY,CAAC;IACjB,IAAI,CAAC;QACH,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,cAAc,EAAE,CAAC;YACpC,MAAM,IAAI,kBAAkB,CAAC,GAAG,MAAM,uBAAuB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAChF,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;IACD,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IACjD,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAClD,MAAM,IAAI,kBAAkB,CAAC,GAAG,MAAM,6CAA6C,CAAC,CAAC;IACvF,CAAC;IACD,MAAM,IAAI,GAA+B,EAAE,CAAC;IAC5C,KAAK,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACpD,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YAClC,MAAM,IAAI,kBAAkB,CAAC,GAAG,MAAM,wBAAwB,SAAS,GAAG,CAAC,CAAC;QAC9E,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,GAAG,aAAa,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/csv.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { LookupRegistry, Translations } from "./registry.js";
|
|
2
|
+
export interface CsvRecord {
|
|
3
|
+
/** 1-based line on which the record starts (quoted fields may span lines). */
|
|
4
|
+
line: number;
|
|
5
|
+
cells: string[];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Picks the delimiter of a spreadsheet export from its header line: Excel writes `;`
|
|
9
|
+
* under locales whose decimal separator is a comma (sr, de, …), LibreOffice may write tabs.
|
|
10
|
+
*/
|
|
11
|
+
export declare function detectDelimiter(text: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* RFC 4180 CSV parser, lenient the way spreadsheets need: strips a UTF-8 BOM, accepts
|
|
14
|
+
* CRLF/LF, quoted fields with `""` escapes and embedded newlines, and skips blank lines.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseCsv(text: string, delimiter?: string): CsvRecord[];
|
|
17
|
+
/** One CSV line (no trailing newline), quoting cells that need it. */
|
|
18
|
+
export declare function formatCsvRow(cells: readonly string[], delimiter?: string): string;
|
|
19
|
+
export interface CsvIssue {
|
|
20
|
+
line: number;
|
|
21
|
+
column?: string;
|
|
22
|
+
message: string;
|
|
23
|
+
}
|
|
24
|
+
export interface TranslationsValidation {
|
|
25
|
+
ok: boolean;
|
|
26
|
+
locales: string[];
|
|
27
|
+
translations: Translations;
|
|
28
|
+
errors: CsvIssue[];
|
|
29
|
+
warnings: CsvIssue[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Validates a translations sheet (`section,term,en,sr,…`) against a registry: the header,
|
|
33
|
+
* that every row names a known section and term, duplicates, and missing translations.
|
|
34
|
+
* Errors make the sheet unusable; warnings (an empty cell, a term without a row) do not.
|
|
35
|
+
*/
|
|
36
|
+
export declare function validateTranslationsCsv(text: string, registry: LookupRegistry): TranslationsValidation;
|
|
37
|
+
//# sourceMappingURL=csv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csv.d.ts","sourceRoot":"","sources":["../src/csv.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElE,MAAM,WAAW,SAAS;IACxB,8EAA8E;IAC9E,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAID;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAYpD;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,SAAwB,GAAG,SAAS,EAAE,CA4CrF;AAED,sEAAsE;AACtE,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,SAAS,SAAM,GAAG,MAAM,CAQ9E;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,OAAO,CAAC;IACZ,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,YAAY,EAAE,YAAY,CAAC;IAC3B,MAAM,EAAE,QAAQ,EAAE,CAAC;IACnB,QAAQ,EAAE,QAAQ,EAAE,CAAC;CACtB;AAID;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,cAAc,GACvB,sBAAsB,CAyExB"}
|
package/dist/csv.js
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
const DELIMITERS = [",", ";", "\t"];
|
|
2
|
+
/**
|
|
3
|
+
* Picks the delimiter of a spreadsheet export from its header line: Excel writes `;`
|
|
4
|
+
* under locales whose decimal separator is a comma (sr, de, …), LibreOffice may write tabs.
|
|
5
|
+
*/
|
|
6
|
+
export function detectDelimiter(text) {
|
|
7
|
+
const header = text.split(/\r?\n/, 1)[0] ?? "";
|
|
8
|
+
let best = ",";
|
|
9
|
+
let bestCount = 0;
|
|
10
|
+
for (const delimiter of DELIMITERS) {
|
|
11
|
+
const count = header.split(delimiter).length - 1;
|
|
12
|
+
if (count > bestCount) {
|
|
13
|
+
best = delimiter;
|
|
14
|
+
bestCount = count;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return best;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* RFC 4180 CSV parser, lenient the way spreadsheets need: strips a UTF-8 BOM, accepts
|
|
21
|
+
* CRLF/LF, quoted fields with `""` escapes and embedded newlines, and skips blank lines.
|
|
22
|
+
*/
|
|
23
|
+
export function parseCsv(text, delimiter = detectDelimiter(text)) {
|
|
24
|
+
const input = text.startsWith("") ? text.slice(1) : text;
|
|
25
|
+
const records = [];
|
|
26
|
+
let cells = [];
|
|
27
|
+
let cell = "";
|
|
28
|
+
let quoted = false;
|
|
29
|
+
let line = 1;
|
|
30
|
+
let start = 1;
|
|
31
|
+
const endRecord = () => {
|
|
32
|
+
cells.push(cell);
|
|
33
|
+
if (cells.length > 1 || cells[0] !== "")
|
|
34
|
+
records.push({ line: start, cells });
|
|
35
|
+
cells = [];
|
|
36
|
+
cell = "";
|
|
37
|
+
};
|
|
38
|
+
for (let i = 0; i < input.length; i++) {
|
|
39
|
+
const ch = input[i];
|
|
40
|
+
if (quoted) {
|
|
41
|
+
if (ch === '"') {
|
|
42
|
+
if (input[i + 1] === '"') {
|
|
43
|
+
cell += '"';
|
|
44
|
+
i++;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
quoted = false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
if (ch === "\n")
|
|
52
|
+
line++;
|
|
53
|
+
cell += ch;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else if (ch === '"' && cell === "") {
|
|
57
|
+
quoted = true;
|
|
58
|
+
}
|
|
59
|
+
else if (ch === delimiter) {
|
|
60
|
+
cells.push(cell);
|
|
61
|
+
cell = "";
|
|
62
|
+
}
|
|
63
|
+
else if (ch === "\n" || ch === "\r") {
|
|
64
|
+
if (ch === "\r" && input[i + 1] === "\n")
|
|
65
|
+
i++;
|
|
66
|
+
endRecord();
|
|
67
|
+
line++;
|
|
68
|
+
start = line;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
cell += ch;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (cell !== "" || cells.length > 0)
|
|
75
|
+
endRecord();
|
|
76
|
+
return records;
|
|
77
|
+
}
|
|
78
|
+
/** One CSV line (no trailing newline), quoting cells that need it. */
|
|
79
|
+
export function formatCsvRow(cells, delimiter = ",") {
|
|
80
|
+
return cells
|
|
81
|
+
.map((value) => value.includes(delimiter) || /["\r\n]/.test(value) || value !== value.trim()
|
|
82
|
+
? `"${value.replaceAll('"', '""')}"`
|
|
83
|
+
: value)
|
|
84
|
+
.join(delimiter);
|
|
85
|
+
}
|
|
86
|
+
const LOCALE_RE = /^[a-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/;
|
|
87
|
+
/**
|
|
88
|
+
* Validates a translations sheet (`section,term,en,sr,…`) against a registry: the header,
|
|
89
|
+
* that every row names a known section and term, duplicates, and missing translations.
|
|
90
|
+
* Errors make the sheet unusable; warnings (an empty cell, a term without a row) do not.
|
|
91
|
+
*/
|
|
92
|
+
export function validateTranslationsCsv(text, registry) {
|
|
93
|
+
const errors = [];
|
|
94
|
+
const warnings = [];
|
|
95
|
+
const translations = new Map();
|
|
96
|
+
const [header, ...rows] = parseCsv(text);
|
|
97
|
+
const result = (locales) => ({
|
|
98
|
+
ok: errors.length === 0,
|
|
99
|
+
locales,
|
|
100
|
+
translations,
|
|
101
|
+
errors,
|
|
102
|
+
warnings,
|
|
103
|
+
});
|
|
104
|
+
if (!header) {
|
|
105
|
+
errors.push({ line: 1, message: "empty file: expected a header section,term,<locale>…" });
|
|
106
|
+
return result([]);
|
|
107
|
+
}
|
|
108
|
+
const columns = header.cells.map((cell) => cell.trim());
|
|
109
|
+
if (columns[0]?.toLowerCase() !== "section" || columns[1]?.toLowerCase() !== "term") {
|
|
110
|
+
errors.push({ line: header.line, message: 'header must start with "section,term"' });
|
|
111
|
+
return result([]);
|
|
112
|
+
}
|
|
113
|
+
const locales = columns.slice(2);
|
|
114
|
+
if (locales.length === 0) {
|
|
115
|
+
errors.push({ line: header.line, message: "header has no locale columns (e.g. en,sr)" });
|
|
116
|
+
}
|
|
117
|
+
const seenLocales = new Set();
|
|
118
|
+
for (const locale of locales) {
|
|
119
|
+
if (!LOCALE_RE.test(locale)) {
|
|
120
|
+
errors.push({ line: header.line, column: locale, message: `invalid locale "${locale}"` });
|
|
121
|
+
}
|
|
122
|
+
else if (seenLocales.has(locale)) {
|
|
123
|
+
errors.push({ line: header.line, column: locale, message: `duplicate locale "${locale}"` });
|
|
124
|
+
}
|
|
125
|
+
seenLocales.add(locale);
|
|
126
|
+
}
|
|
127
|
+
const seenRows = new Map();
|
|
128
|
+
for (const { line, cells } of rows) {
|
|
129
|
+
const section = (cells[0] ?? "").trim();
|
|
130
|
+
const term = (cells[1] ?? "").trim();
|
|
131
|
+
if (cells.length > columns.length && cells.slice(columns.length).some((c) => c.trim())) {
|
|
132
|
+
errors.push({ line, message: `${cells.length} cells, header has ${columns.length}` });
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (!registry.hasSection(section)) {
|
|
136
|
+
errors.push({ line, column: "section", message: `unknown section "${section}"` });
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (!registry.terms(section).includes(term)) {
|
|
140
|
+
errors.push({ line, column: "term", message: `unknown term "${term}" in ${section}` });
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const key = `${section}.${term}`;
|
|
144
|
+
const previous = seenRows.get(key);
|
|
145
|
+
if (previous !== undefined) {
|
|
146
|
+
errors.push({ line, message: `duplicate row for ${key} (first on line ${previous})` });
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
seenRows.set(key, line);
|
|
150
|
+
const labels = {};
|
|
151
|
+
locales.forEach((locale, index) => {
|
|
152
|
+
const value = (cells[index + 2] ?? "").trim();
|
|
153
|
+
if (value)
|
|
154
|
+
labels[locale] = value;
|
|
155
|
+
else
|
|
156
|
+
warnings.push({ line, column: locale, message: `${key} has no ${locale} translation` });
|
|
157
|
+
});
|
|
158
|
+
translations.set(key, labels);
|
|
159
|
+
}
|
|
160
|
+
for (const section of registry.sectionNames()) {
|
|
161
|
+
for (const term of registry.terms(section)) {
|
|
162
|
+
if (!seenRows.has(`${section}.${term}`)) {
|
|
163
|
+
warnings.push({ line: 0, message: `${section}.${term} has no translation row` });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return result(locales);
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=csv.js.map
|
package/dist/csv.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csv.js","sourceRoot":"","sources":["../src/csv.ts"],"names":[],"mappings":"AAQA,MAAM,UAAU,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAU,CAAC;AAE7C;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC/C,IAAI,IAAI,GAAG,GAAG,CAAC;IACf,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;QACjD,IAAI,KAAK,GAAG,SAAS,EAAE,CAAC;YACtB,IAAI,GAAG,SAAS,CAAC;YACjB,SAAS,GAAG,KAAK,CAAC;QACpB,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,SAAS,GAAG,eAAe,CAAC,IAAI,CAAC;IACtE,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CA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AC,CAAC;QACH,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAChC,CAAC;IACD,KAAK,MAAM,OAAO,IAAI,QAAQ,CAAC,YAAY,EAAE,EAAE,CAAC;QAC9C,KAAK,MAAM,IAAI,IAAI,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3C,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,OAAO,IAAI,IAAI,EAAE,CAAC,EAAE,CAAC;gBACxC,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,IAAI,IAAI,yBAAyB,EAAE,CAAC,CAAC;YACnF,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC;AACzB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { CANDIDATES_CSV, type Candidate, CandidateRecorder, type CandidateRecorderOptions, } from "./candidates.js";
|
|
2
|
+
export { type CodegenOptions, constantName, generateLookupsModule, typeName, } from "./codegen.js";
|
|
3
|
+
export { compileLookups, LookupCompileError, type LookupNode, type LookupTree, TERM_RE, } from "./compile.js";
|
|
4
|
+
export { type CsvIssue, type CsvRecord, detectDelimiter, formatCsvRow, parseCsv, type TranslationsValidation, validateTranslationsCsv, } from "./csv.js";
|
|
5
|
+
export { type LoadedLookups, type LoadLookupsOptions, loadLookups } from "./load.js";
|
|
6
|
+
export { normalizeTerm } from "./normalize.js";
|
|
7
|
+
export { type PromotedTerm, type PromoteOptions, type PromoteResult, promoteCandidates, type SkippedCandidate, } from "./promote.js";
|
|
8
|
+
export { LookupRegistry, type Translations } from "./registry.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,KAAK,SAAS,EACd,iBAAiB,EACjB,KAAK,wBAAwB,GAC9B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,KAAK,cAAc,EACnB,YAAY,EACZ,qBAAqB,EACrB,QAAQ,GACT,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,OAAO,GACR,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,eAAe,EACf,YAAY,EACZ,QAAQ,EACR,KAAK,sBAAsB,EAC3B,uBAAuB,GACxB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,kBAAkB,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,iBAAiB,EACjB,KAAK,gBAAgB,GACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,cAAc,EAAE,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { CANDIDATES_CSV, CandidateRecorder, } from "./candidates.js";
|
|
2
|
+
export { constantName, generateLookupsModule, typeName, } from "./codegen.js";
|
|
3
|
+
export { compileLookups, LookupCompileError, TERM_RE, } from "./compile.js";
|
|
4
|
+
export { detectDelimiter, formatCsvRow, parseCsv, validateTranslationsCsv, } from "./csv.js";
|
|
5
|
+
export { loadLookups } from "./load.js";
|
|
6
|
+
export { normalizeTerm } from "./normalize.js";
|
|
7
|
+
export { promoteCandidates, } from "./promote.js";
|
|
8
|
+
export { LookupRegistry } from "./registry.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAEd,iBAAiB,GAElB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAEL,YAAY,EACZ,qBAAqB,EACrB,QAAQ,GACT,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,cAAc,EACd,kBAAkB,EAGlB,OAAO,GACR,MAAM,cAAc,CAAC;AACtB,OAAO,EAGL,eAAe,EACf,YAAY,EACZ,QAAQ,EAER,uBAAuB,GACxB,MAAM,UAAU,CAAC;AAClB,OAAO,EAA+C,WAAW,EAAE,MAAM,WAAW,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAIL,iBAAiB,GAElB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,cAAc,EAAqB,MAAM,eAAe,CAAC"}
|
package/dist/load.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type CsvIssue } from "./csv.js";
|
|
2
|
+
import { LookupRegistry } from "./registry.js";
|
|
3
|
+
export interface LoadLookupsOptions {
|
|
4
|
+
/** Path of `lookups.yaml`. */
|
|
5
|
+
path: string;
|
|
6
|
+
/** Optional translations sheet (`i18n/translations.csv`); a missing file is no error. */
|
|
7
|
+
translationsPath?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface LoadedLookups {
|
|
10
|
+
registry: LookupRegistry;
|
|
11
|
+
/** The locale columns of the translations sheet (`[]` without one). */
|
|
12
|
+
locales: string[];
|
|
13
|
+
/** Problems of the translations sheet that did not stop loading. */
|
|
14
|
+
warnings: CsvIssue[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Loads the vocabulary at startup. Throws `LookupCompileError` when the YAML is invalid
|
|
18
|
+
* or the translations sheet has errors (unknown terms, duplicates, a bad header).
|
|
19
|
+
*/
|
|
20
|
+
export declare function loadLookups(options: LoadLookupsOptions): Promise<LoadedLookups>;
|
|
21
|
+
//# sourceMappingURL=load.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,QAAQ,EAA2B,MAAM,UAAU,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,WAAW,kBAAkB;IACjC,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,yFAAyF;IACzF,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,cAAc,CAAC;IACzB,uEAAuE;IACvE,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,oEAAoE;IACpE,QAAQ,EAAE,QAAQ,EAAE,CAAC;CACtB;AAWD;;;GAGG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,aAAa,CAAC,CAoBrF"}
|
package/dist/load.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { compileLookups, LookupCompileError } from "./compile.js";
|
|
3
|
+
import { validateTranslationsCsv } from "./csv.js";
|
|
4
|
+
import { LookupRegistry } from "./registry.js";
|
|
5
|
+
async function readOptional(path) {
|
|
6
|
+
try {
|
|
7
|
+
return await readFile(path, "utf8");
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
if (error.code === "ENOENT")
|
|
11
|
+
return null;
|
|
12
|
+
throw error;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Loads the vocabulary at startup. Throws `LookupCompileError` when the YAML is invalid
|
|
17
|
+
* or the translations sheet has errors (unknown terms, duplicates, a bad header).
|
|
18
|
+
*/
|
|
19
|
+
export async function loadLookups(options) {
|
|
20
|
+
const registry = new LookupRegistry(compileLookups(await readFile(options.path, "utf8"), options.path));
|
|
21
|
+
if (!options.translationsPath)
|
|
22
|
+
return { registry, locales: [], warnings: [] };
|
|
23
|
+
const csv = await readOptional(options.translationsPath);
|
|
24
|
+
if (csv === null)
|
|
25
|
+
return { registry, locales: [], warnings: [] };
|
|
26
|
+
const result = validateTranslationsCsv(csv, registry);
|
|
27
|
+
if (!result.ok) {
|
|
28
|
+
const first = result.errors
|
|
29
|
+
.slice(0, 5)
|
|
30
|
+
.map((issue) => `line ${issue.line}: ${issue.message}`)
|
|
31
|
+
.join("; ");
|
|
32
|
+
throw new LookupCompileError(`${options.translationsPath}: ${first}`);
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
registry: registry.withTranslations(result.translations),
|
|
36
|
+
locales: result.locales,
|
|
37
|
+
warnings: result.warnings,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=load.js.map
|
package/dist/load.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load.js","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAiB,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAiB/C,KAAK,UAAU,YAAY,CAAC,IAAY;IACtC,IAAI,CAAC;QACH,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACtC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC;QACpE,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,OAA2B;IAC3D,MAAM,QAAQ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` → `USER`, `"ticket-closed"` → `TICKET_CLOSED`. Returns `""` when nothing
|
|
4
|
+
* alphanumeric is left. Same pipeline as dc-lookups' `normalize_candidate_value`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function normalizeTerm(raw: string): string;
|
|
7
|
+
//# sourceMappingURL=normalize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../src/normalize.ts"],"names":[],"mappings":"AAeA;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAUjD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Apostrophes vanish without leaving a separator: "O'Brien" → "OBRIEN", not "O_BRIEN".
|
|
2
|
+
const APOSTROPHES = /['’‘ʼ]/g;
|
|
3
|
+
// Letters NFKD does not decompose, transliterated the way their languages do (Đorđe → Djordje).
|
|
4
|
+
const LETTERS = {
|
|
5
|
+
Đ: "Dj",
|
|
6
|
+
đ: "dj",
|
|
7
|
+
Ø: "O",
|
|
8
|
+
ø: "o",
|
|
9
|
+
Ł: "L",
|
|
10
|
+
ł: "l",
|
|
11
|
+
ß: "ss",
|
|
12
|
+
Æ: "AE",
|
|
13
|
+
æ: "ae",
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Maps a free-form value to an UPPER_SNAKE_CASE term: `"São Tomé"` → `SAO_TOME`, `"Đorđe"` → `DJORDJE`,
|
|
17
|
+
* `"user"` → `USER`, `"ticket-closed"` → `TICKET_CLOSED`. Returns `""` when nothing
|
|
18
|
+
* alphanumeric is left. Same pipeline as dc-lookups' `normalize_candidate_value`.
|
|
19
|
+
*/
|
|
20
|
+
export function normalizeTerm(raw) {
|
|
21
|
+
return raw
|
|
22
|
+
.trim()
|
|
23
|
+
.normalize("NFKD")
|
|
24
|
+
.replace(/\p{M}/gu, "")
|
|
25
|
+
.replace(APOSTROPHES, "")
|
|
26
|
+
.replace(/[ĐđØøŁłßÆæ]/g, (ch) => LETTERS[ch])
|
|
27
|
+
.replace(/[^A-Za-z0-9]+/g, "_")
|
|
28
|
+
.replace(/^_+|_+$/g, "")
|
|
29
|
+
.toUpperCase();
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=normalize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../src/normalize.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,MAAM,WAAW,GAAG,SAAS,CAAC;AAC9B,gGAAgG;AAChG,MAAM,OAAO,GAA2B;IACtC,CAAC,EAAE,IAAI;IACP,CAAC,EAAE,IAAI;IACP,CAAC,EAAE,GAAG;IACN,CAAC,EAAE,GAAG;IACN,CAAC,EAAE,GAAG;IACN,CAAC,EAAE,GAAG;IACN,CAAC,EAAE,IAAI;IACP,CAAC,EAAE,IAAI;IACP,CAAC,EAAE,IAAI;CACR,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,OAAO,GAAG;SACP,IAAI,EAAE;SACN,SAAS,CAAC,MAAM,CAAC;SACjB,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;SACtB,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;SACxB,OAAO,CAAC,cAAc,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAW,CAAC;SACtD,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC;SAC9B,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;SACvB,WAAW,EAAE,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export interface PromoteOptions {
|
|
2
|
+
/** `lookups.yaml`. */
|
|
3
|
+
path: string;
|
|
4
|
+
/** Default `<dir of path>/i18n/translations.csv`; created when missing. */
|
|
5
|
+
translationsPath?: string | undefined;
|
|
6
|
+
/** Default `<dir of path>/var/candidates`. */
|
|
7
|
+
candidatesDir?: string | undefined;
|
|
8
|
+
/** Only these candidates, as `Section.TERM`; default: every recorded one. */
|
|
9
|
+
only?: readonly string[] | undefined;
|
|
10
|
+
/** Compute the result and change nothing. */
|
|
11
|
+
dryRun?: boolean | undefined;
|
|
12
|
+
/** Locale columns of a translations sheet created from scratch. Default `["en", "sr"]`. */
|
|
13
|
+
locales?: readonly string[] | undefined;
|
|
14
|
+
}
|
|
15
|
+
export interface PromotedTerm {
|
|
16
|
+
section: string;
|
|
17
|
+
term: string;
|
|
18
|
+
/** The labels written to the sheet, per locale (the term itself where nobody filled one in). */
|
|
19
|
+
labels: Record<string, string>;
|
|
20
|
+
count: number;
|
|
21
|
+
}
|
|
22
|
+
export interface SkippedCandidate {
|
|
23
|
+
section: string;
|
|
24
|
+
term: string;
|
|
25
|
+
reason: string;
|
|
26
|
+
}
|
|
27
|
+
export interface PromoteResult {
|
|
28
|
+
lookupsPath: string;
|
|
29
|
+
translationsPath: string;
|
|
30
|
+
candidatesDir: string;
|
|
31
|
+
dryRun: boolean;
|
|
32
|
+
/** Terms added to `lookups.yaml` and the sheet (and removed from the queue). */
|
|
33
|
+
promoted: PromotedTerm[];
|
|
34
|
+
/** Candidates left alone, and why (a term already in the vocabulary is dropped from the queue). */
|
|
35
|
+
skipped: SkippedCandidate[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Moves recorded candidates into the vocabulary: each term is appended to its section of
|
|
39
|
+
* `lookups.yaml` (comments and layout kept), a row with its labels — the translator's from
|
|
40
|
+
* `translations_candidate.csv`, the term itself otherwise — is appended to the translations
|
|
41
|
+
* sheet, and the candidate leaves the queue. A candidate whose section the vocabulary does
|
|
42
|
+
* not have is skipped and stays; one whose term is already in the vocabulary is dropped from
|
|
43
|
+
* the queue. The new sheet is validated against the new vocabulary before anything is
|
|
44
|
+
* written; `dryRun` only reports.
|
|
45
|
+
*/
|
|
46
|
+
export declare function promoteCandidates(options: PromoteOptions): Promise<PromoteResult>;
|
|
47
|
+
//#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promote.js
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { mkdir, readdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { isSeq, parseDocument, stringify } from "yaml";
|
|
4
|
+
import { CANDIDATES_CSV } from "./candidates.js";
|
|
5
|
+
import { compileLookups, LookupCompileError } from "./compile.js";
|
|
6
|
+
import { formatCsvRow, parseCsv, validateTranslationsCsv } from "./csv.js";
|
|
7
|
+
import { LookupRegistry } from "./registry.js";
|
|
8
|
+
async function readOptional(path) {
|
|
9
|
+
try {
|
|
10
|
+
return await readFile(path, "utf8");
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
if (error.code === "ENOENT")
|
|
14
|
+
return null;
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
async function writeAtomic(path, text) {
|
|
19
|
+
await mkdir(dirname(path), { recursive: true });
|
|
20
|
+
await writeFile(`${path}.tmp`, text);
|
|
21
|
+
await rename(`${path}.tmp`, path);
|
|
22
|
+
}
|
|
23
|
+
/** `var/candidates/<Section>.yaml` files → section name → its candidates. */
|
|
24
|
+
async function readQueue(dir) {
|
|
25
|
+
const queue = new Map();
|
|
26
|
+
let entries;
|
|
27
|
+
try {
|
|
28
|
+
entries = await readdir(dir);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (error.code === "ENOENT")
|
|
32
|
+
return queue;
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
for (const entry of entries.sort()) {
|
|
36
|
+
if (!entry.endsWith(".yaml"))
|
|
37
|
+
continue;
|
|
38
|
+
const section = entry.slice(0, -".yaml".length);
|
|
39
|
+
const data = parseDocument(await readFile(join(dir, entry), "utf8")).toJS();
|
|
40
|
+
if (!Array.isArray(data))
|
|
41
|
+
continue;
|
|
42
|
+
const candidates = data.filter((c) => typeof c === "object" && c !== null && typeof c.value === "string");
|
|
43
|
+
queue.set(section, candidates);
|
|
44
|
+
}
|
|
45
|
+
return queue;
|
|
46
|
+
}
|
|
47
|
+
/** The labels a translator filled into `translations_candidate.csv`, keyed `Section.TERM`. */
|
|
48
|
+
function candidateLabels(text) {
|
|
49
|
+
const labels = new Map();
|
|
50
|
+
if (!text)
|
|
51
|
+
return labels;
|
|
52
|
+
const [header, ...rows] = parseCsv(text);
|
|
53
|
+
if (!header)
|
|
54
|
+
return labels;
|
|
55
|
+
const locales = header.cells.slice(2).map((c) => c.trim());
|
|
56
|
+
for (const { cells } of rows) {
|
|
57
|
+
const key = `${(cells[0] ?? "").trim()}.${(cells[1] ?? "").trim()}`;
|
|
58
|
+
const row = {};
|
|
59
|
+
locales.forEach((locale, i) => {
|
|
60
|
+
const value = (cells[i + 2] ?? "").trim();
|
|
61
|
+
if (value)
|
|
62
|
+
row[locale] = value;
|
|
63
|
+
});
|
|
64
|
+
labels.set(key, row);
|
|
65
|
+
}
|
|
66
|
+
return labels;
|
|
67
|
+
}
|
|
68
|
+
/** The candidate CSV without the rows of `remove` (`Section.TERM`); `null` when only the header is left. */
|
|
69
|
+
function withoutRows(text, remove) {
|
|
70
|
+
if (!text)
|
|
71
|
+
return null;
|
|
72
|
+
const [header, ...rows] = parseCsv(text);
|
|
73
|
+
if (!header)
|
|
74
|
+
return null;
|
|
75
|
+
const kept = rows.filter(({ cells }) => !remove.has(`${cells[0] ?? ""}.${cells[1] ?? ""}`));
|
|
76
|
+
if (kept.length === 0)
|
|
77
|
+
return null;
|
|
78
|
+
return `${[header, ...kept].map(({ cells }) => formatCsvRow(cells)).join("\n")}\n`;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Moves recorded candidates into the vocabulary: each term is appended to its section of
|
|
82
|
+
* `lookups.yaml` (comments and layout kept), a row with its labels — the translator's from
|
|
83
|
+
* `translations_candidate.csv`, the term itself otherwise — is appended to the translations
|
|
84
|
+
* sheet, and the candidate leaves the queue. A candidate whose section the vocabulary does
|
|
85
|
+
* not have is skipped and stays; one whose term is already in the vocabulary is dropped from
|
|
86
|
+
* the queue. The new sheet is validated against the new vocabulary before anything is
|
|
87
|
+
* written; `dryRun` only reports.
|
|
88
|
+
*/
|
|
89
|
+
export async function promoteCandidates(options) {
|
|
90
|
+
const root = dirname(options.path);
|
|
91
|
+
const translationsPath = options.translationsPath ?? join(root, "i18n", "translations.csv");
|
|
92
|
+
const candidatesDir = options.candidatesDir ?? join(root, "var", "candidates");
|
|
93
|
+
const only = options.only ? new Set(options.only) : null;
|
|
94
|
+
const result = {
|
|
95
|
+
lookupsPath: options.path,
|
|
96
|
+
translationsPath,
|
|
97
|
+
candidatesDir,
|
|
98
|
+
dryRun: options.dryRun ?? false,
|
|
99
|
+
promoted: [],
|
|
100
|
+
skipped: [],
|
|
101
|
+
};
|
|
102
|
+
const yamlText = await readFile(options.path, "utf8");
|
|
103
|
+
const registry = new LookupRegistry(compileLookups(yamlText, options.path));
|
|
104
|
+
const doc = parseDocument(yamlText);
|
|
105
|
+
const queue = await readQueue(candidatesDir);
|
|
106
|
+
const candidateCsvPath = join(candidatesDir, CANDIDATES_CSV);
|
|
107
|
+
const candidateCsv = await readOptional(candidateCsvPath);
|
|
108
|
+
const labels = candidateLabels(candidateCsv);
|
|
109
|
+
const sheetText = await readOptional(translationsPath);
|
|
110
|
+
const header = sheetText
|
|
111
|
+
? (parseCsv(sheetText)[0]?.cells.map((c) => c.trim()) ?? [])
|
|
112
|
+
: ["section", "term", ...(options.locales ?? ["en", "sr"])];
|
|
113
|
+
if (header[0]?.toLowerCase() !== "section" || header[1]?.toLowerCase() !== "term") {
|
|
114
|
+
throw new LookupCompileError(`${translationsPath}: header must start with "section,term"`);
|
|
115
|
+
}
|
|
116
|
+
const locales = header.slice(2);
|
|
117
|
+
const newRows = [];
|
|
118
|
+
const dequeue = new Map(); // section → terms to drop from the queue
|
|
119
|
+
const drop = (section, term) => {
|
|
120
|
+
const set = dequeue.get(section) ?? new Set();
|
|
121
|
+
set.add(term);
|
|
122
|
+
dequeue.set(section, set);
|
|
123
|
+
};
|
|
124
|
+
for (const [section, candidates] of queue) {
|
|
125
|
+
for (const candidate of candidates) {
|
|
126
|
+
const term = candidate.value;
|
|
127
|
+
const key = `${section}.${term}`;
|
|
128
|
+
if (only && !only.has(key))
|
|
129
|
+
continue;
|
|
130
|
+
if (!registry.hasSection(section)) {
|
|
131
|
+
result.skipped.push({ section, term, reason: "section not in lookups.yaml" });
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (registry.terms(section).includes(term)) {
|
|
135
|
+
result.skipped.push({ section, term, reason: "already in lookups.yaml" });
|
|
136
|
+
drop(section, term);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const seq = doc.getIn(section.split("."));
|
|
140
|
+
if (!isSeq(seq)) {
|
|
141
|
+
result.skipped.push({ section, term, reason: "section is not a list" });
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
seq.add(term);
|
|
145
|
+
const given = labels.get(key) ?? {};
|
|
146
|
+
const row = {};
|
|
147
|
+
for (const locale of locales)
|
|
148
|
+
row[locale] = given[locale] ?? term;
|
|
149
|
+
newRows.push(formatCsvRow([section, term, ...locales.map((l) => row[l])]));
|
|
150
|
+
result.promoted.push({ section, term, labels: row, count: candidate.count ?? 1 });
|
|
151
|
+
drop(section, term);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (result.promoted.length === 0 && dequeue.size === 0)
|
|
155
|
+
return result;
|
|
156
|
+
const newYaml = doc.toString();
|
|
157
|
+
const newRegistry = new LookupRegistry(compileLookups(newYaml, options.path));
|
|
158
|
+
const base = sheetText ?? `${formatCsvRow(header)}\n`;
|
|
159
|
+
const newSheet = newRows.length === 0
|
|
160
|
+
? base
|
|
161
|
+
: `${base.endsWith("\n") || base === "" ? base : `${base}\n`}${newRows.join("\n")}\n`;
|
|
162
|
+
const check = validateTranslationsCsv(newSheet, newRegistry);
|
|
163
|
+
if (!check.ok) {
|
|
164
|
+
const first = check.errors
|
|
165
|
+
.slice(0, 5)
|
|
166
|
+
.map((issue) => `line ${issue.line}: ${issue.message}`)
|
|
167
|
+
.join("; ");
|
|
168
|
+
throw new LookupCompileError(`${translationsPath} after promotion: ${first}`);
|
|
169
|
+
}
|
|
170
|
+
if (result.dryRun)
|
|
171
|
+
return result;
|
|
172
|
+
if (result.promoted.length > 0) {
|
|
173
|
+
await writeAtomic(options.path, newYaml);
|
|
174
|
+
await writeAtomic(translationsPath, newSheet);
|
|
175
|
+
}
|
|
176
|
+
const removed = new Set();
|
|
177
|
+
for (const [section, terms] of dequeue) {
|
|
178
|
+
for (const term of terms)
|
|
179
|
+
removed.add(`${section}.${term}`);
|
|
180
|
+
const left = (queue.get(section) ?? []).filter((c) => !terms.has(c.value));
|
|
181
|
+
const file = join(candidatesDir, `${section}.yaml`);
|
|
182
|
+
if (left.length === 0)
|
|
183
|
+
await unlink(file).catch(() => { });
|
|
184
|
+
else
|
|
185
|
+
await writeAtomic(file, stringify(left));
|
|
186
|
+
}
|
|
187
|
+
const leftCsv = withoutRows(candidateCsv, removed);
|
|
188
|
+
if (candidateCsv !== null) {
|
|
189
|
+
if (leftCsv === null)
|
|
190
|
+
await unlink(candidateCsvPath).catch(() => { });
|
|
191
|
+
else
|
|
192
|
+
await writeAtomic(candidateCsvPath, leftCsv);
|
|
193
|
+
}
|
|
194
|
+
return result;
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=promote.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promote.js","sourceRoot":"","sources":["../src/promote.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,SAAS,EAA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,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;QAC1B,IAAI,OAAO,KAAK,IAAI;YAAE,MAAM,MAAM,CAAC,gBAAgB,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;;YAChE,MAAM,WAAW,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { LookupTree } from "./compile.js";
|
|
2
|
+
/** `{ "EventTypes.USER_LOGIN": { en: "User login", sr: "Prijava korisnika" } }` */
|
|
3
|
+
export type Translations = ReadonlyMap<string, Readonly<Record<string, string>>>;
|
|
4
|
+
/**
|
|
5
|
+
* The runtime view of a lookup tree: which terms exist in which section (`EventTypes`,
|
|
6
|
+
* `Statuses.Ticket`), and their translated labels.
|
|
7
|
+
*/
|
|
8
|
+
export declare class LookupRegistry {
|
|
9
|
+
readonly tree: LookupTree;
|
|
10
|
+
private readonly sections;
|
|
11
|
+
private readonly members;
|
|
12
|
+
private readonly translations;
|
|
13
|
+
constructor(tree?: LookupTree, translations?: Translations);
|
|
14
|
+
/** Every section that holds terms, e.g. `["ActorTypes", "EventTypes", "InstanceTypes"]`. */
|
|
15
|
+
sectionNames(): string[];
|
|
16
|
+
hasSection(section: string): boolean;
|
|
17
|
+
/** The terms of a section, in declaration order (empty for an unknown section). */
|
|
18
|
+
terms(section: string): readonly string[];
|
|
19
|
+
/** Whether `value` is a term of `section`; the value is normalized first (`user` → USER). */
|
|
20
|
+
has(section: string, value: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The label of a term in the first locale of `locales` that has one, or `undefined`.
|
|
23
|
+
* `sr-Latn` also tries `sr`.
|
|
24
|
+
*/
|
|
25
|
+
label(section: string, value: string, locales: readonly string[]): string | undefined;
|
|
26
|
+
/** A registry with the same terms and these translations. */
|
|
27
|
+
withTranslations(translations: Translations): LookupRegistry;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,UAAU,EAAE,MAAM,cAAc,CAAC;AAG3D,mFAAmF;AACnF,MAAM,MAAM,YAAY,GAAG,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;AAYjF;;;GAGG;AACH,qBAAa,cAAc;IACzB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAiC;IAC1D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmC;IAC3D,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;gBAEhC,IAAI,GAAE,UAAe,EAAE,YAAY,GAAE,YAAwB;IAQzE,4FAA4F;IAC5F,YAAY,IAAI,MAAM,EAAE;IAIxB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAIpC,mFAAmF;IACnF,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE;IAIzC,6FAA6F;IAC7F,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;IAI5C;;;OAGG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS;IAUrF,6DAA6D;IAC7D,gBAAgB,CAAC,YAAY,EAAE,YAAY,GAAG,cAAc;CAG7D"}
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { normalizeTerm } from "./normalize.js";
|
|
2
|
+
function flatten(node, prefix, out) {
|
|
3
|
+
if (Array.isArray(node)) {
|
|
4
|
+
out.set(prefix, node);
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
for (const [key, child] of Object.entries(node)) {
|
|
8
|
+
flatten(child, `${prefix}.${key}`, out);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The runtime view of a lookup tree: which terms exist in which section (`EventTypes`,
|
|
13
|
+
* `Statuses.Ticket`), and their translated labels.
|
|
14
|
+
*/
|
|
15
|
+
export class LookupRegistry {
|
|
16
|
+
tree;
|
|
17
|
+
sections;
|
|
18
|
+
members;
|
|
19
|
+
translations;
|
|
20
|
+
constructor(tree = {}, translations = new Map()) {
|
|
21
|
+
this.tree = tree;
|
|
22
|
+
this.sections = new Map();
|
|
23
|
+
for (const [namespace, node] of Object.entries(tree))
|
|
24
|
+
flatten(node, namespace, this.sections);
|
|
25
|
+
this.members = new Map([...this.sections].map(([key, terms]) => [key, new Set(terms)]));
|
|
26
|
+
this.translations = translations;
|
|
27
|
+
}
|
|
28
|
+
/** Every section that holds terms, e.g. `["ActorTypes", "EventTypes", "InstanceTypes"]`. */
|
|
29
|
+
sectionNames() {
|
|
30
|
+
return [...this.sections.keys()];
|
|
31
|
+
}
|
|
32
|
+
hasSection(section) {
|
|
33
|
+
return this.sections.has(section);
|
|
34
|
+
}
|
|
35
|
+
/** The terms of a section, in declaration order (empty for an unknown section). */
|
|
36
|
+
terms(section) {
|
|
37
|
+
return this.sections.get(section) ?? [];
|
|
38
|
+
}
|
|
39
|
+
/** Whether `value` is a term of `section`; the value is normalized first (`user` → USER). */
|
|
40
|
+
has(section, value) {
|
|
41
|
+
return this.members.get(section)?.has(normalizeTerm(value)) ?? false;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The label of a term in the first locale of `locales` that has one, or `undefined`.
|
|
45
|
+
* `sr-Latn` also tries `sr`.
|
|
46
|
+
*/
|
|
47
|
+
label(section, value, locales) {
|
|
48
|
+
const row = this.translations.get(`${section}.${normalizeTerm(value)}`);
|
|
49
|
+
if (!row)
|
|
50
|
+
return undefined;
|
|
51
|
+
for (const locale of locales) {
|
|
52
|
+
const text = row[locale] ?? row[locale.split("-")[0]];
|
|
53
|
+
if (text)
|
|
54
|
+
return text;
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
/** A registry with the same terms and these translations. */
|
|
59
|
+
withTranslations(translations) {
|
|
60
|
+
return new LookupRegistry(this.tree, translations);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAK/C,SAAS,OAAO,CAAC,IAAgB,EAAE,MAAc,EAAE,GAAmC;IACpF,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,IAAyB,CAAC,CAAC;QAC3C,OAAO;IACT,CAAC;IACD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAkC,CAAC,EAAE,CAAC;QAC9E,OAAO,CAAC,KAAK,EAAE,GAAG,MAAM,IAAI,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC;IAC1C,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,cAAc;IAChB,IAAI,CAAa;IACT,QAAQ,CAAiC;IACzC,OAAO,CAAmC;IAC1C,YAAY,CAAe;IAE5C,YAAY,OAAmB,EAAE,EAAE,eAA6B,IAAI,GAAG,EAAE;QACvE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,EAAE,CAAC;QAC1B,KAAK,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CA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AC,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAW,CAAC,CAAC;YAChE,IAAI,IAAI;gBAAE,OAAO,IAAI,CAAC;QACxB,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,6DAA6D;IAC7D,gBAAgB,CAAC,YAA0B;QACzC,OAAO,IAAI,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IACrD,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vol-a/lookups",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "JSVola lookups: controlled vocabularies from YAML (file kinds, processing statuses and kinds, share scopes, OCR languages, encryption modes), CSV translations, candidate recording and TypeScript/Zod codegen.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/digital-cube/jsvola.git",
|
|
9
|
+
"directory": "packages/lookups"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/digital-cube/jsvola#readme",
|
|
12
|
+
"bugs": "https://github.com/digital-cube/jsvola/issues",
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=24"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"@vol-a/source": "./src/index.ts",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"yaml": "^2.9.1"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"vola",
|
|
35
|
+
"jsvola",
|
|
36
|
+
"lookups",
|
|
37
|
+
"vocabulary",
|
|
38
|
+
"i18n"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsc -p tsconfig.build.json",
|
|
42
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
43
|
+
"test": "vitest run",
|
|
44
|
+
"test:cov": "vitest run --coverage"
|
|
45
|
+
}
|
|
6
46
|
}
|