@mailwoman/registry 11.1.0 → 11.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -6
- package/data/manifests/artifacts.json +35 -0
- package/data/manifests/coverage.json +63 -0
- package/data/manifests/sources.lock.json +12 -0
- package/data/normalized/language-subtags.json +18518 -0
- package/docs/data-policy.md +5 -5
- package/docs/rgy1.md +5 -5
- package/lib/artifacts/bcp47/extlang.fixture.json +260 -0
- package/lib/artifacts/bcp47/extlang.ts +32 -0
- package/lib/artifacts/bcp47/grandfathered.fixture.json +28 -0
- package/lib/artifacts/bcp47/grandfathered.ts +32 -0
- package/lib/artifacts/bcp47/language.fixture.json +8278 -0
- package/lib/artifacts/bcp47/language.ts +32 -0
- package/lib/artifacts/bcp47/redundant.fixture.json +69 -0
- package/lib/artifacts/bcp47/redundant.ts +32 -0
- package/lib/artifacts/bcp47/region.fixture.json +307 -0
- package/lib/artifacts/bcp47/region.ts +32 -0
- package/lib/artifacts/bcp47/script.fixture.json +227 -0
- package/lib/artifacts/bcp47/script.ts +32 -0
- package/lib/artifacts/bcp47/variant.fixture.json +141 -0
- package/lib/artifacts/bcp47/variant.ts +32 -0
- package/lib/bcp47/subtag-index.ts +65 -0
- package/lib/bcp47/tag.ts +301 -0
- package/lib/errors.ts +11 -1
- package/lib/index.ts +8 -2
- package/lib/iso15924/codes.ts +169 -0
- package/lib/iso15924/unicode-script.ts +124 -0
- package/lib/iso639/languages.ts +88 -0
- package/lib/types.ts +58 -0
- package/out/artifacts/bcp47/extlang.d.ts +21 -0
- package/out/artifacts/bcp47/extlang.d.ts.map +1 -0
- package/out/artifacts/bcp47/extlang.fixture.json +260 -0
- package/out/artifacts/bcp47/extlang.js +17 -0
- package/out/artifacts/bcp47/extlang.js.map +1 -0
- package/out/artifacts/bcp47/grandfathered.d.ts +21 -0
- package/out/artifacts/bcp47/grandfathered.d.ts.map +1 -0
- package/out/artifacts/bcp47/grandfathered.fixture.json +28 -0
- package/out/artifacts/bcp47/grandfathered.js +17 -0
- package/out/artifacts/bcp47/grandfathered.js.map +1 -0
- package/out/artifacts/bcp47/language.d.ts +21 -0
- package/out/artifacts/bcp47/language.d.ts.map +1 -0
- package/out/artifacts/bcp47/language.fixture.json +8278 -0
- package/out/artifacts/bcp47/language.js +17 -0
- package/out/artifacts/bcp47/language.js.map +1 -0
- package/out/artifacts/bcp47/redundant.d.ts +21 -0
- package/out/artifacts/bcp47/redundant.d.ts.map +1 -0
- package/out/artifacts/bcp47/redundant.fixture.json +69 -0
- package/out/artifacts/bcp47/redundant.js +17 -0
- package/out/artifacts/bcp47/redundant.js.map +1 -0
- package/out/artifacts/bcp47/region.d.ts +21 -0
- package/out/artifacts/bcp47/region.d.ts.map +1 -0
- package/out/artifacts/bcp47/region.fixture.json +307 -0
- package/out/artifacts/bcp47/region.js +17 -0
- package/out/artifacts/bcp47/region.js.map +1 -0
- package/out/artifacts/bcp47/script.d.ts +21 -0
- package/out/artifacts/bcp47/script.d.ts.map +1 -0
- package/out/artifacts/bcp47/script.fixture.json +227 -0
- package/out/artifacts/bcp47/script.js +17 -0
- package/out/artifacts/bcp47/script.js.map +1 -0
- package/out/artifacts/bcp47/variant.d.ts +21 -0
- package/out/artifacts/bcp47/variant.d.ts.map +1 -0
- package/out/artifacts/bcp47/variant.fixture.json +141 -0
- package/out/artifacts/bcp47/variant.js +17 -0
- package/out/artifacts/bcp47/variant.js.map +1 -0
- package/out/bcp47/subtag-index.d.ts +22 -0
- package/out/bcp47/subtag-index.d.ts.map +1 -0
- package/out/bcp47/subtag-index.js +43 -0
- package/out/bcp47/subtag-index.js.map +1 -0
- package/out/bcp47/tag.d.ts +47 -0
- package/out/bcp47/tag.d.ts.map +1 -0
- package/out/bcp47/tag.js +218 -0
- package/out/bcp47/tag.js.map +1 -0
- package/out/errors.d.ts +4 -0
- package/out/errors.d.ts.map +1 -1
- package/out/errors.js.map +1 -1
- package/out/index.d.ts +8 -2
- package/out/index.d.ts.map +1 -1
- package/out/index.js +4 -1
- package/out/index.js.map +1 -1
- package/out/iso15924/codes.d.ts +57 -0
- package/out/iso15924/codes.d.ts.map +1 -0
- package/out/iso15924/codes.js +133 -0
- package/out/iso15924/codes.js.map +1 -0
- package/out/iso15924/unicode-script.d.ts +10 -0
- package/out/iso15924/unicode-script.d.ts.map +1 -0
- package/out/iso15924/unicode-script.js +103 -0
- package/out/iso15924/unicode-script.js.map +1 -0
- package/out/iso639/languages.d.ts +40 -0
- package/out/iso639/languages.d.ts.map +1 -0
- package/out/iso639/languages.js +54 -0
- package/out/iso639/languages.js.map +1 -0
- package/out/sdk/fetch.d.ts +5 -1
- package/out/sdk/fetch.d.ts.map +1 -1
- package/out/sdk/fetch.js +20 -6
- package/out/sdk/fetch.js.map +1 -1
- package/out/sdk/fetch.run.js +17 -3
- package/out/sdk/fetch.run.js.map +1 -1
- package/out/sdk/sources.d.ts +1 -1
- package/out/sdk/sources.d.ts.map +1 -1
- package/out/sdk/sources.js +18 -1
- package/out/sdk/sources.js.map +1 -1
- package/out/tools/bench.run.js +2 -2
- package/out/tools/bench.run.js.map +1 -1
- package/out/tools/build-wasm.run.js +2 -2
- package/out/tools/build-wasm.run.js.map +1 -1
- package/out/tools/generate-sections.run.js +2 -2
- package/out/tools/generate-sections.run.js.map +1 -1
- package/out/tools/generate.run.js +53 -6
- package/out/tools/generate.run.js.map +1 -1
- package/out/tools/language-subtags.d.ts +59 -0
- package/out/tools/language-subtags.d.ts.map +1 -0
- package/out/tools/language-subtags.js +145 -0
- package/out/tools/language-subtags.js.map +1 -0
- package/out/tools/normalize.d.ts +3 -1
- package/out/tools/normalize.d.ts.map +1 -1
- package/out/tools/normalize.js +3 -3
- package/out/tools/normalize.js.map +1 -1
- package/out/tools/normalize.run.js +23 -4
- package/out/tools/normalize.run.js.map +1 -1
- package/out/types.d.ts +57 -0
- package/out/types.d.ts.map +1 -1
- package/out/types.js +12 -0
- package/out/types.js.map +1 -1
- package/package.json +6 -3
- package/sdk/fetch.run.ts +19 -3
- package/sdk/fetch.ts +28 -7
- package/sdk/sources.ts +19 -1
- package/tools/bench.run.ts +2 -2
- package/tools/build-wasm.run.ts +2 -2
- package/tools/generate-sections.run.ts +2 -2
- package/tools/generate.run.ts +59 -6
- package/tools/language-subtags.ts +195 -0
- package/tools/normalize.run.ts +26 -4
- package/tools/normalize.ts +4 -4
package/tools/build-wasm.run.ts
CHANGED
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
* Usage: `node packages/registry/tools/build-wasm.run.ts [--check]`
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
+
import { sha256File } from "@mailwoman/core/crypto/hash"
|
|
17
18
|
import { statPath } from "@mailwoman/core/fs/readers/stat"
|
|
18
19
|
import { replaceFileAtomically } from "@mailwoman/core/fs/writers"
|
|
19
|
-
import { sha256File } from "@mailwoman/core/hash"
|
|
20
20
|
import { repoRootPath, workspacePath } from "@mailwoman/core/paths"
|
|
21
|
-
import { runFile } from "@mailwoman/core/process"
|
|
22
21
|
import { parseArguments } from "@mailwoman/core/scripting/arguments"
|
|
22
|
+
import { runFile } from "@mailwoman/core/scripting/process"
|
|
23
23
|
|
|
24
24
|
const { values } = parseArguments({ options: { check: { type: "boolean", default: false } } })
|
|
25
25
|
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
|
|
12
12
|
import { readLocalJSONFile, readLocalTextFile } from "@mailwoman/core/fs/readers"
|
|
13
13
|
import { writeLocalFile } from "@mailwoman/core/fs/writers"
|
|
14
|
-
import { stringifyJSON } from "@mailwoman/core/json"
|
|
15
14
|
import { workspacePath } from "@mailwoman/core/paths"
|
|
15
|
+
import { SourceHeaderSyntax, spdxHeaderText } from "@mailwoman/core/repo/spdx-header"
|
|
16
16
|
import { parseArguments } from "@mailwoman/core/scripting/arguments"
|
|
17
|
-
import {
|
|
17
|
+
import { stringifyJSON } from "@mailwoman/core/values/json"
|
|
18
18
|
|
|
19
19
|
interface SectionDefinitions {
|
|
20
20
|
envelope: { magic: string; version: number; headerOffset: number; directoryEntryBytes: number; alignment: number }
|
package/tools/generate.run.ts
CHANGED
|
@@ -16,17 +16,18 @@
|
|
|
16
16
|
* `--check` compiles without writing and exits non-zero when a generated module or manifest differs.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
+
import { sha256File, sha256Hex } from "@mailwoman/core/crypto/hash"
|
|
19
20
|
import { readLocalBuffer, readLocalJSONFile } from "@mailwoman/core/fs/readers"
|
|
20
21
|
import { temporaryDirectory } from "@mailwoman/core/fs/temporary"
|
|
21
22
|
import { writeLocalFile } from "@mailwoman/core/fs/writers"
|
|
22
|
-
import { sha256File } from "@mailwoman/core/hash"
|
|
23
|
-
import { prettyJSON } from "@mailwoman/core/json"
|
|
24
23
|
import { repoRootPath, workspacePath } from "@mailwoman/core/paths"
|
|
25
|
-
import {
|
|
24
|
+
import { SourceHeaderSyntax, spdxHeaderText } from "@mailwoman/core/repo/spdx-header"
|
|
26
25
|
import { parseArguments } from "@mailwoman/core/scripting/arguments"
|
|
27
|
-
import {
|
|
26
|
+
import { runFile } from "@mailwoman/core/scripting/process"
|
|
27
|
+
import { prettyJSON, stringifyJSON } from "@mailwoman/core/values/json"
|
|
28
28
|
|
|
29
29
|
import { artifactModulePath } from "#tools/artifact-path"
|
|
30
|
+
import { type NormalizedSubtags, SUBTAG_TABLES, type SubtagTable, subtagTableRows } from "#tools/language-subtags"
|
|
30
31
|
|
|
31
32
|
const { values } = parseArguments({ options: { check: { type: "boolean", default: false } } })
|
|
32
33
|
const registry = (...segments: string[]): string => workspacePath("registry", ...segments)
|
|
@@ -85,8 +86,11 @@ for (const name of ARTIFACTS) {
|
|
|
85
86
|
manifest[name] = { sha256, bytes: bytes.byteLength, profile: profile.profile }
|
|
86
87
|
|
|
87
88
|
const module = `${spdxHeaderText(SourceHeaderSyntax.Slash)}/**
|
|
88
|
-
* The \`${name}\` artifact of the \`${profile.profile}\` profile, ${bytes.byteLength} bytes,
|
|
89
|
-
*
|
|
89
|
+
* The \`${name}\` artifact of the \`${profile.profile}\` profile, ${bytes.byteLength} bytes,
|
|
90
|
+
* SHA-256 ${sha256}.
|
|
91
|
+
*
|
|
92
|
+
* Generated by tools/generate.run.ts from data/normalized.
|
|
93
|
+
* Edit the data or the compiler rather than this file.
|
|
90
94
|
*/
|
|
91
95
|
|
|
92
96
|
import { decodeBase64 } from "#rgy1/base64"
|
|
@@ -111,6 +115,55 @@ export function ${getter}(): Uint8Array {
|
|
|
111
115
|
await emit(registry("lib", "artifacts", `${artifactModulePath(name)}.ts`), module)
|
|
112
116
|
}
|
|
113
117
|
|
|
118
|
+
// The BCP 47 subtag tables are JSON fixtures beside a TypeScript module that imports them, rather than RGY1
|
|
119
|
+
// artifacts. The largest holds 8,276 language rows, and no consumer has measured a need for the batch kernel on them.
|
|
120
|
+
// Each fixture holds one row per line, so a registry update diffs by row, and `.prettierignore` keeps the formatter off the fixtures.
|
|
121
|
+
const subtags = await readLocalJSONFile<NormalizedSubtags>(registry("data", "normalized", "language-subtags.json"))
|
|
122
|
+
|
|
123
|
+
for (const table of Object.keys(SUBTAG_TABLES) as SubtagTable[]) {
|
|
124
|
+
const rows = subtagTableRows(subtags, table)
|
|
125
|
+
const fixture = `[\n${rows.map((row) => `\t${stringifyJSON(row)}`).join(",\n")}\n]\n`
|
|
126
|
+
const sha256 = sha256Hex(fixture)
|
|
127
|
+
const name = `bcp47-${table}-subtags`
|
|
128
|
+
const getter = `${table}SubtagRows`
|
|
129
|
+
|
|
130
|
+
manifest[name] = { sha256, bytes: Buffer.byteLength(fixture), profile: profile.profile }
|
|
131
|
+
|
|
132
|
+
await emit(registry("lib", "artifacts", "bcp47", `${table}.fixture.json`), fixture)
|
|
133
|
+
|
|
134
|
+
const module = `${spdxHeaderText(SourceHeaderSyntax.Slash)}/**
|
|
135
|
+
* The \`${name}\` table of the \`${profile.profile}\` profile, ${rows.length} rows,
|
|
136
|
+
* read from the IANA Language Subtag Registry of File-Date ${subtags.fileDate}.
|
|
137
|
+
*
|
|
138
|
+
* The rows live in \`./${table}.fixture.json\`, SHA-256 ${sha256}.
|
|
139
|
+
* Generated by tools/generate.run.ts from data/normalized.
|
|
140
|
+
* Edit the data or the generator rather than this file.
|
|
141
|
+
*/
|
|
142
|
+
|
|
143
|
+
import type { SubtagRow } from "#types"
|
|
144
|
+
|
|
145
|
+
import fixture from "./${table}.fixture.json" with { type: "json" }
|
|
146
|
+
|
|
147
|
+
const rows: readonly SubtagRow[] = Object.freeze(fixture)
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Returns the table's rows.
|
|
151
|
+
*
|
|
152
|
+
* Callers read the rows and never write them.
|
|
153
|
+
*/
|
|
154
|
+
export function ${getter}(): readonly SubtagRow[] {
|
|
155
|
+
return rows
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* The registry edition the table was read from.
|
|
160
|
+
*/
|
|
161
|
+
export const ${table.toUpperCase()}_SUBTAGS_FILE_DATE = ${stringifyJSON(subtags.fileDate)}
|
|
162
|
+
`
|
|
163
|
+
|
|
164
|
+
await emit(registry("lib", "artifacts", "bcp47", `${table}.ts`), module)
|
|
165
|
+
}
|
|
166
|
+
|
|
114
167
|
await emit(registry("data", "manifests", "artifacts.json"), prettyJSON(manifest))
|
|
115
168
|
|
|
116
169
|
// The fixture profile, committed as bytes so the layout test and the Rust tests read the same artifacts.
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Reads the IANA Language Subtag Registry into normalized subtag records.
|
|
6
|
+
*
|
|
7
|
+
* The registry is a record-jar file (RFC 5646, section 3.1): records separated by `%%` lines, one
|
|
8
|
+
* `Field-Name: body` per line, and a line that starts with whitespace continuing the field before it.
|
|
9
|
+
* A field such as `Description` or `Prefix` may repeat.
|
|
10
|
+
*
|
|
11
|
+
* The registry covers every BCP 47 subtag type, so this one source feeds ISO 639
|
|
12
|
+
* language subtags, ISO 15924 scripts, ISO 3166-1 and UN M49 region subtags,
|
|
13
|
+
* variants, and the grandfathered and redundant whole tags.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { stringifyJSON } from "@mailwoman/core/values/json"
|
|
17
|
+
|
|
18
|
+
import { type SubtagRow, SubtagType } from "#types"
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The subtag types in the order the normalized file sorts them.
|
|
22
|
+
*/
|
|
23
|
+
export const SUBTAG_TYPES: readonly SubtagType[] = Object.values(SubtagType)
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* One registry record: a table row plus the date the registry added it.
|
|
27
|
+
*/
|
|
28
|
+
export interface SubtagRecord extends SubtagRow {
|
|
29
|
+
type: SubtagType
|
|
30
|
+
added: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface NormalizedSubtags {
|
|
34
|
+
profile: string
|
|
35
|
+
source: string
|
|
36
|
+
normalizationVersion: number
|
|
37
|
+
/**
|
|
38
|
+
* The registry's own `File-Date`.
|
|
39
|
+
*/
|
|
40
|
+
fileDate: string
|
|
41
|
+
records: SubtagRecord[]
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The version of the rules below.
|
|
46
|
+
* A change that moves a record's bytes moves this number.
|
|
47
|
+
*/
|
|
48
|
+
export const SUBTAG_NORMALIZATION_VERSION = 1
|
|
49
|
+
|
|
50
|
+
function isSubtagType(value: string): value is SubtagType {
|
|
51
|
+
return (SUBTAG_TYPES as readonly string[]).includes(value)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Splits the registry text into records of field lists, joining continuation lines.
|
|
56
|
+
*/
|
|
57
|
+
export function readRecordJar(text: string): Array<Array<[string, string]>> {
|
|
58
|
+
const records: Array<Array<[string, string]>> = []
|
|
59
|
+
let current: Array<[string, string]> = []
|
|
60
|
+
|
|
61
|
+
// oxlint-disable-next-line mailwoman/prefer-spliterator -- one 732 KB registry file, read whole and bounded
|
|
62
|
+
for (const line of text.split("\n")) {
|
|
63
|
+
if (line === "%%") {
|
|
64
|
+
records.push(current)
|
|
65
|
+
current = []
|
|
66
|
+
|
|
67
|
+
continue
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (/^\s/.test(line)) {
|
|
71
|
+
const last = current.at(-1)
|
|
72
|
+
|
|
73
|
+
if (!last) throw new Error(`continuation line before any field: ${stringifyJSON(line)}`)
|
|
74
|
+
|
|
75
|
+
last[1] = `${last[1]} ${line.trim()}`
|
|
76
|
+
|
|
77
|
+
continue
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (line.trim() === "") continue
|
|
81
|
+
|
|
82
|
+
const colon = line.indexOf(":")
|
|
83
|
+
|
|
84
|
+
if (colon < 1) throw new Error(`registry line without a field name: ${stringifyJSON(line)}`)
|
|
85
|
+
|
|
86
|
+
current.push([line.slice(0, colon), line.slice(colon + 1).trim()])
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
records.push(current)
|
|
90
|
+
|
|
91
|
+
return records
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Normalizes the registry into records sorted by type, then subtag.
|
|
96
|
+
*
|
|
97
|
+
* A field this reader doesn't know is an error naming the record, because a dropped
|
|
98
|
+
* field would change what the registry answers without anyone deciding it.
|
|
99
|
+
*/
|
|
100
|
+
export function normalizeSubtags(text: string, profile: string, source: string): NormalizedSubtags {
|
|
101
|
+
const [header, ...entries] = readRecordJar(text)
|
|
102
|
+
const fileDate = header?.find(([name]) => name === "File-Date")?.[1]
|
|
103
|
+
|
|
104
|
+
if (!fileDate) throw new Error("the registry's first record holds no File-Date")
|
|
105
|
+
|
|
106
|
+
const records = entries.map((fields): SubtagRecord => {
|
|
107
|
+
const one = (name: string): string | undefined => fields.find(([field]) => field === name)?.[1]
|
|
108
|
+
const many = (name: string): string[] => fields.filter(([field]) => field === name).map(([, body]) => body)
|
|
109
|
+
const type = one("Type")
|
|
110
|
+
const subtag = one("Subtag") ?? one("Tag")
|
|
111
|
+
|
|
112
|
+
if (!type || !isSubtagType(type) || !subtag) {
|
|
113
|
+
throw new Error(`registry record without a known Type and Subtag or Tag: ${stringifyJSON(fields)}`)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
for (const [name] of fields) {
|
|
117
|
+
if (!KNOWN_FIELDS.has(name)) throw new Error(`${subtag}: unknown registry field ${name}`)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const prefixes = many("Prefix")
|
|
121
|
+
|
|
122
|
+
// An absent optional field stays absent rather than holding an empty value, so each row's JSON stays short.
|
|
123
|
+
return {
|
|
124
|
+
type,
|
|
125
|
+
subtag,
|
|
126
|
+
descriptions: many("Description"),
|
|
127
|
+
added: one("Added") ?? "",
|
|
128
|
+
...optional("deprecated", one("Deprecated")),
|
|
129
|
+
...optional("preferredValue", one("Preferred-Value")),
|
|
130
|
+
...optional("suppressScript", one("Suppress-Script")),
|
|
131
|
+
...optional("macrolanguage", one("Macrolanguage")),
|
|
132
|
+
...optional("scope", one("Scope")),
|
|
133
|
+
...(prefixes.length ? { prefixes } : {}),
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
const order = (type: SubtagType): number => SUBTAG_TYPES.indexOf(type)
|
|
138
|
+
|
|
139
|
+
records.sort((left, right) => order(left.type) - order(right.type) || compareCodeUnits(left.subtag, right.subtag))
|
|
140
|
+
|
|
141
|
+
return { profile, source, normalizationVersion: SUBTAG_NORMALIZATION_VERSION, fileDate, records }
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const KNOWN_FIELDS = new Set([
|
|
145
|
+
"Type",
|
|
146
|
+
"Subtag",
|
|
147
|
+
"Tag",
|
|
148
|
+
"Description",
|
|
149
|
+
"Added",
|
|
150
|
+
"Deprecated",
|
|
151
|
+
"Preferred-Value",
|
|
152
|
+
"Suppress-Script",
|
|
153
|
+
"Macrolanguage",
|
|
154
|
+
"Scope",
|
|
155
|
+
"Prefix",
|
|
156
|
+
// Comments are the registry's prose for human readers, and no lookup answers from them.
|
|
157
|
+
"Comments",
|
|
158
|
+
])
|
|
159
|
+
|
|
160
|
+
function optional<K extends string>(key: K, value: string | undefined): Partial<Record<K, string>> {
|
|
161
|
+
return value ? ({ [key]: value } as Partial<Record<K, string>>) : {}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function compareCodeUnits(left: string, right: string): number {
|
|
165
|
+
return left < right ? -1 : left > right ? 1 : 0
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The table modules the generator writes under `lib/artifacts/bcp47/`, each holding the subtag types listed.
|
|
170
|
+
*
|
|
171
|
+
* Each subtag type gets its own module, so a bundle that validates scripts holds
|
|
172
|
+
* the 225 script rows and none of the 8,276 language rows.
|
|
173
|
+
*/
|
|
174
|
+
export const SUBTAG_TABLES = {
|
|
175
|
+
language: ["language"],
|
|
176
|
+
extlang: ["extlang"],
|
|
177
|
+
script: ["script"],
|
|
178
|
+
region: ["region"],
|
|
179
|
+
variant: ["variant"],
|
|
180
|
+
grandfathered: ["grandfathered"],
|
|
181
|
+
redundant: ["redundant"],
|
|
182
|
+
} as const satisfies Record<string, readonly SubtagType[]>
|
|
183
|
+
|
|
184
|
+
export type SubtagTable = keyof typeof SUBTAG_TABLES
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* The rows of one table, in the normalized order.
|
|
188
|
+
*/
|
|
189
|
+
export function subtagTableRows(collection: NormalizedSubtags, table: SubtagTable): SubtagRow[] {
|
|
190
|
+
const types = new Set<SubtagType>(SUBTAG_TABLES[table])
|
|
191
|
+
|
|
192
|
+
return collection.records
|
|
193
|
+
.filter((record) => types.has(record.type))
|
|
194
|
+
.map(({ added: _added, type: _type, ...row }) => row)
|
|
195
|
+
}
|
package/tools/normalize.run.ts
CHANGED
|
@@ -2,19 +2,22 @@
|
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Writes `data/normalized/iso3166-1.json`, `data/normalized/iata-airports.json
|
|
6
|
-
* and `data/manifests/coverage.json` from the pinned sources.
|
|
5
|
+
* Writes `data/normalized/iso3166-1.json`, `data/normalized/iata-airports.json`,
|
|
6
|
+
* `data/normalized/language-subtags.json` and `data/manifests/coverage.json` from the pinned sources.
|
|
7
7
|
*
|
|
8
8
|
* Usage: `node packages/registry/tools/normalize.run.ts`
|
|
9
9
|
*
|
|
10
10
|
* The run refuses a source file whose digest differs from `data/manifests/sources.lock.json`.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
import { readLocalTextFile } from "@mailwoman/core/fs/readers"
|
|
13
14
|
import { writeLocalFile, writeLocalJSONFile } from "@mailwoman/core/fs/writers"
|
|
14
|
-
import { stringifyJSON } from "@mailwoman/core/json"
|
|
15
15
|
import { workspacePathBuilder } from "@mailwoman/core/paths"
|
|
16
|
+
import { stringifyJSON } from "@mailwoman/core/values/json"
|
|
16
17
|
|
|
17
18
|
import { readSourceLock } from "#sdk/fetch"
|
|
19
|
+
import { pinnedSourceFile, SOURCES } from "#sdk/sources"
|
|
20
|
+
import { normalizeSubtags, SUBTAG_TYPES } from "#tools/language-subtags"
|
|
18
21
|
import { formatNormalized, normalizeFromLock } from "#tools/normalize"
|
|
19
22
|
|
|
20
23
|
const lock = await readSourceLock()
|
|
@@ -23,13 +26,32 @@ if (!lock) throw new Error("no sources.lock.json; run packages/registry/sdk/fetc
|
|
|
23
26
|
|
|
24
27
|
const { countries, airports, coverage } = await normalizeFromLock(lock)
|
|
25
28
|
const data = workspacePathBuilder("registry", "data")
|
|
29
|
+
const subtagSource = SOURCES.find((source) => source.id === "iana-language-subtags")!
|
|
30
|
+
|
|
31
|
+
const subtags = normalizeSubtags(await readLocalTextFile(pinnedSourceFile(subtagSource)), lock.profile, subtagSource.id)
|
|
32
|
+
|
|
33
|
+
for (const type of SUBTAG_TYPES) {
|
|
34
|
+
const records = subtags.records.filter((record) => record.type === type)
|
|
35
|
+
|
|
36
|
+
coverage.namespaces[`bcp47-${type}`] = {
|
|
37
|
+
source: subtagSource.id,
|
|
38
|
+
count: records.length,
|
|
39
|
+
statuses: {
|
|
40
|
+
current: records.filter((record) => !record.deprecated).length,
|
|
41
|
+
deprecated: records.filter((record) => record.deprecated).length,
|
|
42
|
+
},
|
|
43
|
+
missMeans: `not-found-in-snapshot: the registry's File-Date ${subtags.fileDate} edition holds no such subtag`,
|
|
44
|
+
}
|
|
45
|
+
}
|
|
26
46
|
|
|
27
47
|
await writeLocalFile(formatNormalized(countries), data("normalized", "iso3166-1.json"))
|
|
28
48
|
await writeLocalFile(formatNormalized(airports), data("normalized", "iata-airports.json"))
|
|
49
|
+
await writeLocalFile(formatNormalized(subtags), data("normalized", "language-subtags.json"))
|
|
29
50
|
await writeLocalJSONFile(coverage, data("manifests", "coverage.json"))
|
|
30
51
|
|
|
31
52
|
console.log(
|
|
32
53
|
`countries: ${countries.records.length} (${stringifyJSON(coverage.namespaces["iso3166-1-alpha2"]!.statuses)})`
|
|
33
54
|
)
|
|
34
55
|
console.log(`airports: ${airports.records.length} (${stringifyJSON(coverage.namespaces["iata-location"]!.statuses)})`)
|
|
35
|
-
console.log(`
|
|
56
|
+
console.log(`subtags: ${subtags.records.length} (File-Date ${subtags.fileDate})`)
|
|
57
|
+
console.log(`country lists:${coverage.namespaces["$countryListComparison"]!.kinds!.join("; ")}`)
|
package/tools/normalize.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Turns the pinned sources into the
|
|
5
|
+
* Turns the pinned sources into the normalized JSON that the compiler reads and reviewers can inspect.
|
|
6
6
|
*
|
|
7
7
|
* Every record keeps the source's own identity (`entityID`), the code as the
|
|
8
8
|
* source spells it, and the source's status words.
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
* whether that string is an officially assigned ISO code, a source extension such as `XK`, or absent.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
+
import { sha256File } from "@mailwoman/core/crypto/hash"
|
|
15
16
|
import { readLocalJSONFile, readLocalTextFile } from "@mailwoman/core/fs/readers"
|
|
16
|
-
import {
|
|
17
|
-
import { stringifyJSON } from "@mailwoman/core/json"
|
|
17
|
+
import { stringifyJSON } from "@mailwoman/core/values/json"
|
|
18
18
|
import { TextSpliterator } from "spliterator"
|
|
19
19
|
|
|
20
20
|
import { pinnedSourceFile, type SourceDefinition, type SourceLock, SOURCES } from "#sdk/sources"
|
|
@@ -426,7 +426,7 @@ export function declareCoverage(
|
|
|
426
426
|
*
|
|
427
427
|
* The envelope keys come first, then `records`, each on its own line.
|
|
428
428
|
*/
|
|
429
|
-
export function formatNormalized(collection:
|
|
429
|
+
export function formatNormalized(collection: { records: readonly unknown[] }): string {
|
|
430
430
|
const { records, ...envelope } = collection
|
|
431
431
|
const head = stringifyJSON(envelope).slice(1, -1)
|
|
432
432
|
const body = records.map((record) => `\t\t${stringifyJSON(record)}`).join(",\n")
|