@mailwoman/registry 11.0.0 → 11.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/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/performance.md +1 -1
- 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/artifacts/country-airport-collision.ts +7 -5
- package/lib/artifacts/iata-airport/membership.ts +7 -5
- package/lib/artifacts/iata-airport/records.ts +7 -5
- package/lib/artifacts/iso3166-1/alpha2-membership.ts +7 -5
- package/lib/artifacts/iso3166-1/alpha3-membership.ts +7 -5
- package/lib/artifacts/iso3166-1/records.ts +7 -5
- package/lib/bcp47/subtag-index.ts +65 -0
- package/lib/bcp47/tag.ts +301 -0
- package/lib/errors.ts +22 -9
- package/lib/iata/airports/records.ts +3 -4
- package/lib/iata/airports/validate.ts +6 -5
- package/lib/index.ts +18 -8
- package/lib/inspect.ts +5 -5
- package/lib/iso15924/codes.ts +169 -0
- package/lib/iso15924/unicode-script.ts +124 -0
- package/lib/iso3166/alpha2.ts +5 -5
- package/lib/iso3166/alpha3.ts +6 -6
- package/lib/iso3166/records.ts +9 -8
- package/lib/iso3166/relations.ts +5 -5
- package/lib/iso639/languages.ts +88 -0
- package/lib/key.ts +9 -7
- package/lib/normalize.ts +12 -8
- package/lib/overlap/country-airport.ts +14 -12
- package/lib/rgy1/base64.ts +3 -4
- package/lib/rgy1/reader.ts +8 -7
- package/lib/rgy1/sections.generated.ts +6 -5
- package/lib/rgy1/views.ts +5 -6
- package/lib/types.ts +66 -7
- package/lib/wasm.ts +11 -9
- 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/artifacts/country-airport-collision.d.ts +0 -8
- package/out/artifacts/country-airport-collision.d.ts.map +1 -1
- package/out/artifacts/country-airport-collision.js +6 -5
- package/out/artifacts/country-airport-collision.js.map +1 -1
- package/out/artifacts/iata-airport/membership.d.ts +0 -8
- package/out/artifacts/iata-airport/membership.d.ts.map +1 -1
- package/out/artifacts/iata-airport/membership.js +6 -5
- package/out/artifacts/iata-airport/membership.js.map +1 -1
- package/out/artifacts/iata-airport/records.d.ts +0 -8
- package/out/artifacts/iata-airport/records.d.ts.map +1 -1
- package/out/artifacts/iata-airport/records.js +6 -5
- package/out/artifacts/iata-airport/records.js.map +1 -1
- package/out/artifacts/iso3166-1/alpha2-membership.d.ts +0 -8
- package/out/artifacts/iso3166-1/alpha2-membership.d.ts.map +1 -1
- package/out/artifacts/iso3166-1/alpha2-membership.js +6 -5
- package/out/artifacts/iso3166-1/alpha2-membership.js.map +1 -1
- package/out/artifacts/iso3166-1/alpha3-membership.d.ts +0 -8
- package/out/artifacts/iso3166-1/alpha3-membership.d.ts.map +1 -1
- package/out/artifacts/iso3166-1/alpha3-membership.js +6 -5
- package/out/artifacts/iso3166-1/alpha3-membership.js.map +1 -1
- package/out/artifacts/iso3166-1/records.d.ts +0 -8
- package/out/artifacts/iso3166-1/records.d.ts.map +1 -1
- package/out/artifacts/iso3166-1/records.js +6 -5
- package/out/artifacts/iso3166-1/records.js.map +1 -1
- 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 +12 -8
- package/out/errors.d.ts.map +1 -1
- package/out/errors.js +10 -8
- package/out/errors.js.map +1 -1
- package/out/iata/airports/records.d.ts +0 -7
- package/out/iata/airports/records.d.ts.map +1 -1
- package/out/iata/airports/records.js +2 -4
- package/out/iata/airports/records.js.map +1 -1
- package/out/iata/airports/validate.d.ts +0 -8
- package/out/iata/airports/validate.d.ts.map +1 -1
- package/out/iata/airports/validate.js +5 -5
- package/out/iata/airports/validate.js.map +1 -1
- package/out/index.d.ts +13 -8
- package/out/index.d.ts.map +1 -1
- package/out/index.js +6 -12
- package/out/index.js.map +1 -1
- package/out/inspect.d.ts +2 -5
- package/out/inspect.d.ts.map +1 -1
- package/out/inspect.js +4 -5
- package/out/inspect.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/iso3166/alpha2.d.ts +0 -8
- package/out/iso3166/alpha2.d.ts.map +1 -1
- package/out/iso3166/alpha2.js +4 -5
- package/out/iso3166/alpha2.js.map +1 -1
- package/out/iso3166/alpha3.d.ts +1 -9
- package/out/iso3166/alpha3.d.ts.map +1 -1
- package/out/iso3166/alpha3.js +5 -6
- package/out/iso3166/alpha3.js.map +1 -1
- package/out/iso3166/records.d.ts +0 -11
- package/out/iso3166/records.d.ts.map +1 -1
- package/out/iso3166/records.js +8 -8
- package/out/iso3166/records.js.map +1 -1
- package/out/iso3166/relations.d.ts +0 -7
- package/out/iso3166/relations.d.ts.map +1 -1
- package/out/iso3166/relations.js +4 -5
- package/out/iso3166/relations.js.map +1 -1
- 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/key.d.ts +6 -7
- package/out/key.d.ts.map +1 -1
- package/out/key.js +8 -7
- package/out/key.js.map +1 -1
- package/out/normalize.d.ts +9 -8
- package/out/normalize.d.ts.map +1 -1
- package/out/normalize.js +2 -12
- package/out/normalize.js.map +1 -1
- package/out/overlap/country-airport.d.ts +2 -16
- package/out/overlap/country-airport.d.ts.map +1 -1
- package/out/overlap/country-airport.js +13 -12
- package/out/overlap/country-airport.js.map +1 -1
- package/out/rgy1/base64.d.ts +0 -4
- package/out/rgy1/base64.d.ts.map +1 -1
- package/out/rgy1/base64.js +2 -4
- package/out/rgy1/base64.js.map +1 -1
- package/out/rgy1/reader.d.ts +0 -11
- package/out/rgy1/reader.d.ts.map +1 -1
- package/out/rgy1/reader.js +7 -7
- package/out/rgy1/reader.js.map +1 -1
- package/out/rgy1/sections.generated.d.ts +3 -5
- package/out/rgy1/sections.generated.d.ts.map +1 -1
- package/out/rgy1/sections.generated.js +5 -5
- package/out/rgy1/sections.generated.js.map +1 -1
- package/out/rgy1/views.d.ts +2 -9
- package/out/rgy1/views.d.ts.map +1 -1
- package/out/rgy1/views.js +4 -6
- package/out/rgy1/views.js.map +1 -1
- package/out/sdk/fetch.d.ts +6 -6
- package/out/sdk/fetch.d.ts.map +1 -1
- package/out/sdk/fetch.js +23 -11
- package/out/sdk/fetch.js.map +1 -1
- package/out/sdk/fetch.run.d.ts +0 -12
- package/out/sdk/fetch.run.d.ts.map +1 -1
- package/out/sdk/fetch.run.js +22 -9
- package/out/sdk/fetch.run.js.map +1 -1
- package/out/sdk/sources.d.ts +7 -16
- package/out/sdk/sources.d.ts.map +1 -1
- package/out/sdk/sources.js +34 -14
- package/out/sdk/sources.js.map +1 -1
- package/out/tools/artifact-path.d.ts +0 -5
- package/out/tools/artifact-path.d.ts.map +1 -1
- package/out/tools/artifact-path.js +2 -5
- package/out/tools/artifact-path.js.map +1 -1
- package/out/tools/bench.run.d.ts +0 -17
- package/out/tools/bench.run.d.ts.map +1 -1
- package/out/tools/bench.run.js +13 -10
- package/out/tools/bench.run.js.map +1 -1
- package/out/tools/build-wasm.run.d.ts +0 -16
- package/out/tools/build-wasm.run.d.ts.map +1 -1
- package/out/tools/build-wasm.run.js +8 -10
- package/out/tools/build-wasm.run.js.map +1 -1
- package/out/tools/generate-sections.run.d.ts +0 -11
- package/out/tools/generate-sections.run.d.ts.map +1 -1
- package/out/tools/generate-sections.run.js +5 -14
- package/out/tools/generate-sections.run.js.map +1 -1
- package/out/tools/generate.run.d.ts +0 -16
- package/out/tools/generate.run.d.ts.map +1 -1
- package/out/tools/generate.run.js +61 -17
- 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 +4 -14
- package/out/tools/normalize.d.ts.map +1 -1
- package/out/tools/normalize.js +14 -14
- package/out/tools/normalize.js.map +1 -1
- package/out/tools/normalize.run.d.ts +0 -12
- package/out/tools/normalize.run.d.ts.map +1 -1
- package/out/tools/normalize.run.js +24 -7
- package/out/tools/normalize.run.js.map +1 -1
- package/out/types.d.ts +62 -7
- package/out/types.d.ts.map +1 -1
- package/out/types.js +12 -9
- package/out/types.js.map +1 -1
- package/out/wasm.d.ts +0 -13
- package/out/wasm.d.ts.map +1 -1
- package/out/wasm.js +10 -9
- package/out/wasm.js.map +1 -1
- package/package.json +12 -4
- package/sdk/fetch.run.ts +25 -9
- package/sdk/fetch.ts +32 -12
- package/sdk/sources.ts +36 -14
- package/tools/artifact-path.ts +2 -5
- package/tools/bench.run.ts +19 -10
- package/tools/build-wasm.run.ts +9 -10
- package/tools/generate-sections.run.ts +6 -14
- package/tools/generate.run.ts +68 -17
- package/tools/language-subtags.ts +195 -0
- package/tools/normalize.run.ts +28 -7
- package/tools/normalize.ts +16 -15
package/tools/generate.run.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* Compiles the normalized data into RGY1 artifacts with `crates/registry-build`, writes each artifact as a
|
|
7
|
-
* TypeScript module under `lib/artifacts/`, and records every artifact's SHA-256 in `data/manifests/artifacts.json`.
|
|
5
|
+
* Compiles the normalized data into RGY1 artifacts with `crates/registry-build`,
|
|
6
|
+
* writes each artifact as a TypeScript module under `lib/artifacts/`, and records
|
|
7
|
+
* every artifact's SHA-256 in `data/manifests/artifacts.json`.
|
|
8
8
|
*
|
|
9
|
-
* Each artifact is its own module exporting one lazily decoded getter, so a bundle that
|
|
10
|
-
* predicate holds the collision bitset and no airport record.
|
|
11
|
-
* too, into `test/fixtures/artifacts/*.rgy1`,
|
|
9
|
+
* Each artifact is its own module exporting one lazily decoded getter, so a bundle that
|
|
10
|
+
* imports the collision predicate holds the collision bitset and no airport record.
|
|
11
|
+
* The fixture profile under `test/fixtures/` is compiled too, into `test/fixtures/artifacts/*.rgy1`,
|
|
12
|
+
* so the committed fixtures stay equal to the compiler's output.
|
|
12
13
|
*
|
|
13
14
|
* Usage: `node packages/registry/tools/generate.run.ts [--check]`
|
|
14
15
|
*
|
|
@@ -18,13 +19,15 @@
|
|
|
18
19
|
import { readLocalBuffer, readLocalJSONFile } from "@mailwoman/core/fs/readers"
|
|
19
20
|
import { temporaryDirectory } from "@mailwoman/core/fs/temporary"
|
|
20
21
|
import { writeLocalFile } from "@mailwoman/core/fs/writers"
|
|
21
|
-
import { sha256File } from "@mailwoman/core/hash"
|
|
22
|
-
import { prettyJSON } from "@mailwoman/core/json"
|
|
22
|
+
import { sha256File, sha256Hex } from "@mailwoman/core/hash"
|
|
23
|
+
import { prettyJSON, stringifyJSON } from "@mailwoman/core/json"
|
|
23
24
|
import { repoRootPath, workspacePath } from "@mailwoman/core/paths"
|
|
24
25
|
import { runFile } from "@mailwoman/core/process"
|
|
25
26
|
import { parseArguments } from "@mailwoman/core/scripting/arguments"
|
|
27
|
+
import { SourceHeaderSyntax, spdxHeaderText } from "@mailwoman/core/spdx-header"
|
|
26
28
|
|
|
27
29
|
import { artifactModulePath } from "#tools/artifact-path"
|
|
30
|
+
import { type NormalizedSubtags, SUBTAG_TABLES, type SubtagTable, subtagTableRows } from "#tools/language-subtags"
|
|
28
31
|
|
|
29
32
|
const { values } = parseArguments({ options: { check: { type: "boolean", default: false } } })
|
|
30
33
|
const registry = (...segments: string[]): string => workspacePath("registry", ...segments)
|
|
@@ -82,13 +85,12 @@ for (const name of ARTIFACTS) {
|
|
|
82
85
|
|
|
83
86
|
manifest[name] = { sha256, bytes: bytes.byteLength, profile: profile.profile }
|
|
84
87
|
|
|
85
|
-
const module =
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* @author Teffen Ellis, et al.
|
|
88
|
+
const module = `${spdxHeaderText(SourceHeaderSyntax.Slash)}/**
|
|
89
|
+
* The \`${name}\` artifact of the \`${profile.profile}\` profile, ${bytes.byteLength} bytes,
|
|
90
|
+
* SHA-256 ${sha256}.
|
|
89
91
|
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
+
* Generated by tools/generate.run.ts from data/normalized.
|
|
93
|
+
* Edit the data or the compiler rather than this file.
|
|
92
94
|
*/
|
|
93
95
|
|
|
94
96
|
import { decodeBase64 } from "#rgy1/base64"
|
|
@@ -113,6 +115,55 @@ export function ${getter}(): Uint8Array {
|
|
|
113
115
|
await emit(registry("lib", "artifacts", `${artifactModulePath(name)}.ts`), module)
|
|
114
116
|
}
|
|
115
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
|
+
|
|
116
167
|
await emit(registry("data", "manifests", "artifacts.json"), prettyJSON(manifest))
|
|
117
168
|
|
|
118
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/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
|
@@ -1,21 +1,23 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* Writes `data/normalized/iso3166-1.json`, `data/normalized/iata-airports.json` and
|
|
7
|
-
* `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.
|
|
8
7
|
*
|
|
9
8
|
* Usage: `node packages/registry/tools/normalize.run.ts`
|
|
10
9
|
*
|
|
11
10
|
* The run refuses a source file whose digest differs from `data/manifests/sources.lock.json`.
|
|
12
11
|
*/
|
|
13
12
|
|
|
13
|
+
import { readLocalTextFile } from "@mailwoman/core/fs/readers"
|
|
14
14
|
import { writeLocalFile, writeLocalJSONFile } from "@mailwoman/core/fs/writers"
|
|
15
15
|
import { stringifyJSON } from "@mailwoman/core/json"
|
|
16
16
|
import { workspacePathBuilder } from "@mailwoman/core/paths"
|
|
17
17
|
|
|
18
18
|
import { readSourceLock } from "#sdk/fetch"
|
|
19
|
+
import { pinnedSourceFile, SOURCES } from "#sdk/sources"
|
|
20
|
+
import { normalizeSubtags, SUBTAG_TYPES } from "#tools/language-subtags"
|
|
19
21
|
import { formatNormalized, normalizeFromLock } from "#tools/normalize"
|
|
20
22
|
|
|
21
23
|
const lock = await readSourceLock()
|
|
@@ -24,13 +26,32 @@ if (!lock) throw new Error("no sources.lock.json; run packages/registry/sdk/fetc
|
|
|
24
26
|
|
|
25
27
|
const { countries, airports, coverage } = await normalizeFromLock(lock)
|
|
26
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
|
+
}
|
|
27
46
|
|
|
28
47
|
await writeLocalFile(formatNormalized(countries), data("normalized", "iso3166-1.json"))
|
|
29
48
|
await writeLocalFile(formatNormalized(airports), data("normalized", "iata-airports.json"))
|
|
49
|
+
await writeLocalFile(formatNormalized(subtags), data("normalized", "language-subtags.json"))
|
|
30
50
|
await writeLocalJSONFile(coverage, data("manifests", "coverage.json"))
|
|
31
51
|
|
|
32
52
|
console.log(
|
|
33
53
|
`countries: ${countries.records.length} (${stringifyJSON(coverage.namespaces["iso3166-1-alpha2"]!.statuses)})`
|
|
34
54
|
)
|
|
35
55
|
console.log(`airports: ${airports.records.length} (${stringifyJSON(coverage.namespaces["iata-location"]!.statuses)})`)
|
|
36
|
-
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
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
5
|
* Turns the pinned sources into the reviewable normalized JSON the compiler reads.
|
|
7
6
|
*
|
|
8
|
-
* Every record keeps the source's own identity (`entityID`), the code as the
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
7
|
+
* Every record keeps the source's own identity (`entityID`), the code as the
|
|
8
|
+
* source spells it, and the source's status words.
|
|
9
|
+
* Each record comes from one source: a country record from Wikidata, an airport record from OurAirports.
|
|
10
|
+
*
|
|
11
|
+
* An airport's `country` is the alpha-2 string OurAirports states, with a status that records
|
|
12
|
+
* whether that string is an officially assigned ISO code, a source extension such as `XK`, or absent.
|
|
12
13
|
*/
|
|
13
14
|
|
|
14
15
|
import { readLocalJSONFile, readLocalTextFile } from "@mailwoman/core/fs/readers"
|
|
@@ -16,7 +17,7 @@ import { sha256File } from "@mailwoman/core/hash"
|
|
|
16
17
|
import { stringifyJSON } from "@mailwoman/core/json"
|
|
17
18
|
import { TextSpliterator } from "spliterator"
|
|
18
19
|
|
|
19
|
-
import { type SourceDefinition, type SourceLock,
|
|
20
|
+
import { pinnedSourceFile, type SourceDefinition, type SourceLock, SOURCES } from "#sdk/sources"
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* One ISO 3166-1 entry.
|
|
@@ -425,7 +426,7 @@ export function declareCoverage(
|
|
|
425
426
|
*
|
|
426
427
|
* The envelope keys come first, then `records`, each on its own line.
|
|
427
428
|
*/
|
|
428
|
-
export function formatNormalized(collection:
|
|
429
|
+
export function formatNormalized(collection: { records: readonly unknown[] }): string {
|
|
429
430
|
const { records, ...envelope } = collection
|
|
430
431
|
const head = stringifyJSON(envelope).slice(1, -1)
|
|
431
432
|
const body = records.map((record) => `\t\t${stringifyJSON(record)}`).join(",\n")
|
|
@@ -434,7 +435,7 @@ export function formatNormalized(collection: NormalizedCountries | NormalizedAir
|
|
|
434
435
|
}
|
|
435
436
|
|
|
436
437
|
/**
|
|
437
|
-
* Reads the three pinned sources and normalizes them, refusing bytes the lock
|
|
438
|
+
* Reads the three pinned sources and normalizes them, refusing bytes the lock doesn't describe.
|
|
438
439
|
*/
|
|
439
440
|
export async function normalizeFromLock(lock: SourceLock): Promise<{
|
|
440
441
|
countries: NormalizedCountries
|
|
@@ -443,7 +444,7 @@ export async function normalizeFromLock(lock: SourceLock): Promise<{
|
|
|
443
444
|
}> {
|
|
444
445
|
for (const definition of SOURCES.filter((candidate) => candidate.terms.elected)) {
|
|
445
446
|
const locked = lock.sources[definition.id]
|
|
446
|
-
const digest = await sha256File(
|
|
447
|
+
const digest = await sha256File(pinnedSourceFile(definition))
|
|
447
448
|
|
|
448
449
|
if (!locked) throw new Error(`${definition.id} is outside the lock`)
|
|
449
450
|
|
|
@@ -452,7 +453,7 @@ export async function normalizeFromLock(lock: SourceLock): Promise<{
|
|
|
452
453
|
}
|
|
453
454
|
}
|
|
454
455
|
|
|
455
|
-
const results = await readLocalJSONFile<SPARQLResults>(
|
|
456
|
+
const results = await readLocalJSONFile<SPARQLResults>(pinnedSourceFile(sourceDefinition("wikidata-iso3166-1")))
|
|
456
457
|
const countries = normalizeCountries(results, lock.profile)
|
|
457
458
|
|
|
458
459
|
const current = new Set(
|
|
@@ -460,14 +461,14 @@ export async function normalizeFromLock(lock: SourceLock): Promise<{
|
|
|
460
461
|
)
|
|
461
462
|
|
|
462
463
|
const airports = normalizeAirports(
|
|
463
|
-
await readLocalTextFile(
|
|
464
|
+
await readLocalTextFile(pinnedSourceFile(sourceDefinition("ourairports-airports"))),
|
|
464
465
|
current,
|
|
465
466
|
lock.profile
|
|
466
467
|
)
|
|
467
468
|
|
|
468
469
|
const comparison = compareCountryLists(
|
|
469
470
|
countries.records,
|
|
470
|
-
await readLocalTextFile(
|
|
471
|
+
await readLocalTextFile(pinnedSourceFile(sourceDefinition("ourairports-countries")))
|
|
471
472
|
)
|
|
472
473
|
|
|
473
474
|
return { countries, airports, coverage: declareCoverage(countries, airports, comparison) }
|