@mailwoman/registry 11.3.0 → 11.4.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/data/manifests/artifacts.json +5 -0
- package/data/manifests/coverage.json +571 -0
- package/data/manifests/sources.lock.json +48 -0
- package/data/normalized/groupings.json +10902 -0
- package/definitions/groupings.json +222 -0
- package/docs/data-policy.md +10 -0
- package/lib/artifacts/groupings/groupings.fixture.json +1222 -0
- package/lib/artifacts/groupings/groupings.ts +77 -0
- package/lib/groupings.ts +127 -0
- package/lib/index.ts +19 -2
- package/lib/types.ts +90 -0
- package/out/artifacts/groupings/groupings.d.ts +28 -0
- package/out/artifacts/groupings/groupings.d.ts.map +1 -0
- package/out/artifacts/groupings/groupings.fixture.json +1222 -0
- package/out/artifacts/groupings/groupings.js +59 -0
- package/out/artifacts/groupings/groupings.js.map +1 -0
- package/out/groupings.d.ts +59 -0
- package/out/groupings.d.ts.map +1 -0
- package/out/groupings.js +92 -0
- package/out/groupings.js.map +1 -0
- package/out/index.d.ts +6 -2
- package/out/index.d.ts.map +1 -1
- package/out/index.js +3 -1
- package/out/index.js.map +1 -1
- package/out/sdk/sources.d.ts +55 -1
- package/out/sdk/sources.d.ts.map +1 -1
- package/out/sdk/sources.js +83 -0
- package/out/sdk/sources.js.map +1 -1
- package/out/tools/generate.run.js +58 -0
- package/out/tools/generate.run.js.map +1 -1
- package/out/tools/groupings.d.ts +101 -0
- package/out/tools/groupings.d.ts.map +1 -0
- package/out/tools/groupings.js +295 -0
- package/out/tools/groupings.js.map +1 -0
- package/out/tools/normalize.d.ts +17 -3
- package/out/tools/normalize.d.ts.map +1 -1
- package/out/tools/normalize.js +6 -1
- package/out/tools/normalize.js.map +1 -1
- package/out/tools/normalize.run.js +50 -3
- package/out/tools/normalize.run.js.map +1 -1
- package/out/types.d.ts +81 -0
- package/out/types.d.ts.map +1 -1
- package/out/types.js +29 -0
- package/out/types.js.map +1 -1
- package/package.json +4 -2
- package/sdk/sources.ts +119 -0
- package/tools/generate.run.ts +65 -0
- package/tools/groupings.ts +428 -0
- package/tools/normalize.run.ts +64 -4
- package/tools/normalize.ts +16 -2
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The `country-groupings` table of the `open-2026-11` profile: 32 groupings and 1182 membership rows.
|
|
6
|
+
*
|
|
7
|
+
* The rows live in `./groupings.fixture.json`,
|
|
8
|
+
* SHA-256 500525cacad4ab47c52e35aa07028b72a8fa998e47e7b3043bc459776a5448c2.
|
|
9
|
+
* Generated by tools/generate.run.ts from data/normalized.
|
|
10
|
+
*
|
|
11
|
+
* Edit the definitions, the data or the generator rather than this file.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { GroupingRecord, MembershipRow } from "#types"
|
|
15
|
+
|
|
16
|
+
import fixture from "./groupings.fixture.json" with { type: "json" }
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Every grouping ID the table declares.
|
|
20
|
+
*/
|
|
21
|
+
export const GROUPING_IDS = [
|
|
22
|
+
"g7",
|
|
23
|
+
"g20",
|
|
24
|
+
"eu",
|
|
25
|
+
"eurozone",
|
|
26
|
+
"schengen",
|
|
27
|
+
"eea",
|
|
28
|
+
"efta",
|
|
29
|
+
"council-of-europe",
|
|
30
|
+
"oecd",
|
|
31
|
+
"nato",
|
|
32
|
+
"un",
|
|
33
|
+
"wto",
|
|
34
|
+
"commonwealth",
|
|
35
|
+
"brics",
|
|
36
|
+
"apec",
|
|
37
|
+
"asean",
|
|
38
|
+
"mercosur",
|
|
39
|
+
"andean-community",
|
|
40
|
+
"caricom",
|
|
41
|
+
"oas",
|
|
42
|
+
"african-union",
|
|
43
|
+
"ecowas",
|
|
44
|
+
"sadc",
|
|
45
|
+
"arab-league",
|
|
46
|
+
"gcc",
|
|
47
|
+
"opec",
|
|
48
|
+
"cis",
|
|
49
|
+
"imf-advanced",
|
|
50
|
+
"wb-high-income",
|
|
51
|
+
"wb-upper-middle-income",
|
|
52
|
+
"wb-lower-middle-income",
|
|
53
|
+
"wb-low-income",
|
|
54
|
+
] as const
|
|
55
|
+
|
|
56
|
+
export type GroupingID = (typeof GROUPING_IDS)[number]
|
|
57
|
+
|
|
58
|
+
const groupings = Object.freeze(fixture.groupings as GroupingRecord[])
|
|
59
|
+
const records = Object.freeze(fixture.records as MembershipRow[])
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Returns the groupings table.
|
|
63
|
+
*
|
|
64
|
+
* Callers read the rows and never write them.
|
|
65
|
+
*/
|
|
66
|
+
export function groupingRows(): readonly GroupingRecord[] {
|
|
67
|
+
return groupings
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Returns the membership rows.
|
|
72
|
+
*
|
|
73
|
+
* Callers read the rows and never write them.
|
|
74
|
+
*/
|
|
75
|
+
export function membershipRows(): readonly MembershipRow[] {
|
|
76
|
+
return records
|
|
77
|
+
}
|
package/lib/groupings.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Country groupings: organizations such as the G20 and the EU, and classifications such
|
|
6
|
+
* as the IMF advanced economies, with each country's membership between stated dates.
|
|
7
|
+
*
|
|
8
|
+
* Every question takes a date, because a grouping's members change:
|
|
9
|
+
* the United Kingdom left the EU on 2020-01-31.
|
|
10
|
+
* A grouping the normalizer couldn't classify throws with its reasons
|
|
11
|
+
* rather than answering with no members.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { GROUPING_IDS, type GroupingID, groupingRows, membershipRows } from "#artifacts/groupings/groupings"
|
|
15
|
+
import type { GroupingRecord, MembershipRow } from "#types"
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A member of a grouping on one date.
|
|
19
|
+
*/
|
|
20
|
+
export interface GroupingMember {
|
|
21
|
+
/**
|
|
22
|
+
* The ISO 3166-1 alpha-2 code, or the publisher's own code when `codeStatus` is `source-extension`.
|
|
23
|
+
*/
|
|
24
|
+
code: string
|
|
25
|
+
codeStatus: MembershipRow["codeStatus"]
|
|
26
|
+
/**
|
|
27
|
+
* True when the source states no start for the membership interval that covers the date.
|
|
28
|
+
* The member is then assumed to have joined before the date.
|
|
29
|
+
*/
|
|
30
|
+
startUnknown: boolean
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Raised for a question about a grouping whose source statements the normalizer couldn't classify.
|
|
35
|
+
*/
|
|
36
|
+
export class BlockedGroupingError extends Error {
|
|
37
|
+
readonly grouping: GroupingID
|
|
38
|
+
readonly reasons: readonly string[]
|
|
39
|
+
|
|
40
|
+
constructor(grouping: GroupingID, reasons: readonly string[]) {
|
|
41
|
+
super(`grouping ${grouping} is blocked: ${reasons.join("; ")}`)
|
|
42
|
+
this.name = "BlockedGroupingError"
|
|
43
|
+
this.grouping = grouping
|
|
44
|
+
this.reasons = reasons
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Returns whether `value` is a declared grouping ID.
|
|
50
|
+
*/
|
|
51
|
+
export function isGroupingID(value: string): value is GroupingID {
|
|
52
|
+
return (GROUPING_IDS as readonly string[]).includes(value)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Returns the grouping's record: its name, kind, source and the reasons it is blocked, if any.
|
|
57
|
+
*/
|
|
58
|
+
export function getGrouping(id: GroupingID): GroupingRecord {
|
|
59
|
+
return groupingRows().find((grouping) => grouping.id === id)!
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const ISO_DATE = /^\d{4}-\d{2}-\d{2}$/
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Whether a membership interval covers `at`.
|
|
66
|
+
*
|
|
67
|
+
* A start or end stated at year or month precision is read as the first day of its year or month.
|
|
68
|
+
* The end date is the first day outside the interval.
|
|
69
|
+
*/
|
|
70
|
+
function covers(row: MembershipRow, at: string): boolean {
|
|
71
|
+
return (!row.start || row.start.date <= at) && (!row.end || at < row.end.date)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Returns the members of `id` on the date `at` (`YYYY-MM-DD`), one entry per code, sorted by code.
|
|
76
|
+
*
|
|
77
|
+
* Associates, observers and suspended members are excluded.
|
|
78
|
+
*
|
|
79
|
+
* @throws {@linkcode BlockedGroupingError} When the grouping is blocked.
|
|
80
|
+
*/
|
|
81
|
+
export function groupingMembers(id: GroupingID, options: { at: string }): GroupingMember[] {
|
|
82
|
+
if (!ISO_DATE.test(options.at)) throw new RangeError(`at must be YYYY-MM-DD, got ${options.at}`)
|
|
83
|
+
|
|
84
|
+
const grouping = getGrouping(id)
|
|
85
|
+
|
|
86
|
+
if (grouping.blockedBy.length) throw new BlockedGroupingError(id, grouping.blockedBy)
|
|
87
|
+
|
|
88
|
+
const members = new Map<string, GroupingMember>()
|
|
89
|
+
|
|
90
|
+
for (const row of membershipRows()) {
|
|
91
|
+
if (row.grouping !== id || row.role !== "member" || !covers(row, options.at)) continue
|
|
92
|
+
|
|
93
|
+
const earlier = members.get(row.code)
|
|
94
|
+
const startUnknown = !row.start
|
|
95
|
+
|
|
96
|
+
members.set(row.code, {
|
|
97
|
+
code: row.code,
|
|
98
|
+
codeStatus: row.codeStatus,
|
|
99
|
+
startUnknown: earlier ? earlier.startUnknown && startUnknown : startUnknown,
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return [...members.values()].toSorted((a, b) => a.code.localeCompare(b.code))
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Returns the IDs of the groupings `code` belonged to on the date `at`, leaving out blocked groupings.
|
|
108
|
+
*/
|
|
109
|
+
export function groupingsOf(code: string, options: { at: string }): GroupingID[] {
|
|
110
|
+
if (!ISO_DATE.test(options.at)) throw new RangeError(`at must be YYYY-MM-DD, got ${options.at}`)
|
|
111
|
+
|
|
112
|
+
const blocked = new Set(
|
|
113
|
+
groupingRows()
|
|
114
|
+
.filter((grouping) => grouping.blockedBy.length)
|
|
115
|
+
.map((grouping) => grouping.id)
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
const ids = new Set<GroupingID>()
|
|
119
|
+
|
|
120
|
+
for (const row of membershipRows()) {
|
|
121
|
+
if (row.code === code && row.role === "member" && !blocked.has(row.grouping) && covers(row, options.at)) {
|
|
122
|
+
ids.add(row.grouping as GroupingID)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return GROUPING_IDS.filter((id) => ids.has(id))
|
|
127
|
+
}
|
package/lib/index.ts
CHANGED
|
@@ -32,6 +32,10 @@ export {
|
|
|
32
32
|
getCountryByNumeric,
|
|
33
33
|
} from "#iso3166/records"
|
|
34
34
|
|
|
35
|
+
export type { GroupingID } from "#artifacts/groupings/groupings"
|
|
36
|
+
export { GROUPING_IDS } from "#artifacts/groupings/groupings"
|
|
37
|
+
export type { GroupingMember } from "#groupings"
|
|
38
|
+
export { BlockedGroupingError, getGrouping, groupingMembers, groupingsOf, isGroupingID } from "#groupings"
|
|
35
39
|
export { alpha2ForAlpha3, alpha2ForNumeric, alpha3ForAlpha2 } from "#iso3166/relations"
|
|
36
40
|
export type { LanguageRecord } from "#iso639/languages"
|
|
37
41
|
export { getLanguage, isLanguageSubtag, parseLanguageSubtag } from "#iso639/languages"
|
|
@@ -39,5 +43,18 @@ export type { Normalization } from "#normalize"
|
|
|
39
43
|
export { canonicalSpelling } from "#normalize"
|
|
40
44
|
export type { CodeMatch } from "#overlap/country-airport"
|
|
41
45
|
export { interpretCountryOrAirportCode, isCountryAirportCollision } from "#overlap/country-airport"
|
|
42
|
-
|
|
43
|
-
export {
|
|
46
|
+
|
|
47
|
+
export type {
|
|
48
|
+
AirportRecord,
|
|
49
|
+
BCP47,
|
|
50
|
+
CountryRecord,
|
|
51
|
+
GroupingRecord,
|
|
52
|
+
IATA,
|
|
53
|
+
ICAO,
|
|
54
|
+
ISO,
|
|
55
|
+
MembershipRow,
|
|
56
|
+
StatedDate,
|
|
57
|
+
SubtagRow,
|
|
58
|
+
} from "#types"
|
|
59
|
+
|
|
60
|
+
export { AirportCountryStatus, CountryStatus, GroupingKind, MemberCodeStatus, MembershipRole, SubtagType } from "#types"
|
package/lib/types.ts
CHANGED
|
@@ -181,3 +181,93 @@ export interface AirportRecord {
|
|
|
181
181
|
municipality: string | null
|
|
182
182
|
isoRegion: string | null
|
|
183
183
|
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Whether a grouping admits members or a publisher assigns countries to it.
|
|
187
|
+
*/
|
|
188
|
+
export const GroupingKind = {
|
|
189
|
+
Organization: "organization",
|
|
190
|
+
Classification: "classification",
|
|
191
|
+
} as const
|
|
192
|
+
|
|
193
|
+
export type GroupingKind = (typeof GroupingKind)[keyof typeof GroupingKind]
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* The role a membership statement gives its country.
|
|
197
|
+
* Only `member` counts as membership.
|
|
198
|
+
*/
|
|
199
|
+
export const MembershipRole = {
|
|
200
|
+
Member: "member",
|
|
201
|
+
Associate: "associate",
|
|
202
|
+
Observer: "observer",
|
|
203
|
+
Suspended: "suspended",
|
|
204
|
+
Other: "other",
|
|
205
|
+
} as const
|
|
206
|
+
|
|
207
|
+
export type MembershipRole = (typeof MembershipRole)[keyof typeof MembershipRole]
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* How a member's code relates to ISO 3166-1.
|
|
211
|
+
*
|
|
212
|
+
* `source-extension` is a code the publisher assigns outside ISO 3166-1, kept as the publisher
|
|
213
|
+
* spells it, such as the World Bank's `XK` for Kosovo and `JG` for the Channel Islands.
|
|
214
|
+
*/
|
|
215
|
+
export const MemberCodeStatus = {
|
|
216
|
+
OfficiallyAssigned: "officially-assigned",
|
|
217
|
+
FormerlyUsed: "formerly-used",
|
|
218
|
+
SourceExtension: "source-extension",
|
|
219
|
+
} as const
|
|
220
|
+
|
|
221
|
+
export type MemberCodeStatus = (typeof MemberCodeStatus)[keyof typeof MemberCodeStatus]
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* A date a source states, with the precision it states it at.
|
|
225
|
+
*
|
|
226
|
+
* `date` is `YYYY-MM-DD`, with the month and day set to `01` when the precision leaves them unstated.
|
|
227
|
+
*/
|
|
228
|
+
export interface StatedDate {
|
|
229
|
+
date: string
|
|
230
|
+
precision: "year" | "month" | "day"
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* One grouping as the groupings table holds it.
|
|
235
|
+
*/
|
|
236
|
+
export interface GroupingRecord {
|
|
237
|
+
id: string
|
|
238
|
+
name: string
|
|
239
|
+
kind: GroupingKind
|
|
240
|
+
/**
|
|
241
|
+
* The source and the selector the members were read through, such as `wikidata:Q458 P463`.
|
|
242
|
+
*/
|
|
243
|
+
source: string
|
|
244
|
+
/**
|
|
245
|
+
* The publication date of a classification's source, or null for an organization.
|
|
246
|
+
*/
|
|
247
|
+
asOf: string | null
|
|
248
|
+
/**
|
|
249
|
+
* The reasons the normalizer couldn't classify the grouping's statements.
|
|
250
|
+
* A blocked grouping answers no membership question.
|
|
251
|
+
*/
|
|
252
|
+
blockedBy: string[]
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* One membership interval: a country's place in a grouping between two stated dates.
|
|
257
|
+
*/
|
|
258
|
+
export interface MembershipRow {
|
|
259
|
+
grouping: string
|
|
260
|
+
code: string
|
|
261
|
+
codeStatus: MemberCodeStatus
|
|
262
|
+
role: MembershipRole
|
|
263
|
+
/**
|
|
264
|
+
* The start, or null when the source states none.
|
|
265
|
+
* A null start is unknown rather than the epoch.
|
|
266
|
+
*/
|
|
267
|
+
start: StatedDate | null
|
|
268
|
+
end: StatedDate | null
|
|
269
|
+
/**
|
|
270
|
+
* The statement or source row the interval was read from, such as `wikidata:Q145-…`.
|
|
271
|
+
*/
|
|
272
|
+
evidence: string
|
|
273
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `country-groupings` table of the `open-2026-11` profile: 32 groupings and 1182 membership rows.
|
|
3
|
+
*
|
|
4
|
+
* The rows live in `./groupings.fixture.json`,
|
|
5
|
+
* SHA-256 500525cacad4ab47c52e35aa07028b72a8fa998e47e7b3043bc459776a5448c2.
|
|
6
|
+
* Generated by tools/generate.run.ts from data/normalized.
|
|
7
|
+
*
|
|
8
|
+
* Edit the definitions, the data or the generator rather than this file.
|
|
9
|
+
*/
|
|
10
|
+
import type { GroupingRecord, MembershipRow } from "#types";
|
|
11
|
+
/**
|
|
12
|
+
* Every grouping ID the table declares.
|
|
13
|
+
*/
|
|
14
|
+
export declare const GROUPING_IDS: readonly ["g7", "g20", "eu", "eurozone", "schengen", "eea", "efta", "council-of-europe", "oecd", "nato", "un", "wto", "commonwealth", "brics", "apec", "asean", "mercosur", "andean-community", "caricom", "oas", "african-union", "ecowas", "sadc", "arab-league", "gcc", "opec", "cis", "imf-advanced", "wb-high-income", "wb-upper-middle-income", "wb-lower-middle-income", "wb-low-income"];
|
|
15
|
+
export type GroupingID = (typeof GROUPING_IDS)[number];
|
|
16
|
+
/**
|
|
17
|
+
* Returns the groupings table.
|
|
18
|
+
*
|
|
19
|
+
* Callers read the rows and never write them.
|
|
20
|
+
*/
|
|
21
|
+
export declare function groupingRows(): readonly GroupingRecord[];
|
|
22
|
+
/**
|
|
23
|
+
* Returns the membership rows.
|
|
24
|
+
*
|
|
25
|
+
* Callers read the rows and never write them.
|
|
26
|
+
*/
|
|
27
|
+
export declare function membershipRows(): readonly MembershipRow[];
|
|
28
|
+
//# sourceMappingURL=groupings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"groupings.d.ts","sourceRoot":"","sources":["../../../lib/artifacts/groupings/groupings.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAI3D;;GAEG;AACH,eAAO,MAAM,YAAY,YACxB,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,UAAU,EACV,UAAU,EACV,KAAK,EACL,MAAM,EACN,mBAAmB,EACnB,MAAM,EACN,MAAM,EACN,IAAI,EACJ,KAAK,EACL,cAAc,EACd,OAAO,EACP,MAAM,EACN,OAAO,EACP,UAAU,EACV,kBAAkB,EAClB,SAAS,EACT,KAAK,EACL,eAAe,EACf,QAAQ,EACR,MAAM,EACN,aAAa,EACb,KAAK,EACL,MAAM,EACN,KAAK,EACL,cAAc,EACd,gBAAgB,EAChB,wBAAwB,EACxB,wBAAwB,EACxB,eAAe,CACN,CAAA;AAEV,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAA;AAKtD;;;;GAIG;AACH,wBAAgB,YAAY,IAAI,SAAS,cAAc,EAAE,CAExD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,SAAS,aAAa,EAAE,CAEzD"}
|