@pubid/pubid 0.1.59 → 0.1.60
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 +3 -3
- package/artifact/corpus.json.gz +0 -0
- package/dist/flavors/eu/index.js +37 -5
- package/dist/flavors/eu/model.d.ts +10 -1
- package/dist/flavors/eu/model.js +8 -4
- package/dist/flavors/itu/grammar.js +12 -3
- package/dist/flavors/itu/index.js +5 -1
- package/dist/flavors/itu/model.d.ts +6 -0
- package/dist/flavors/itu/model.js +23 -0
- package/dist/pubid-urn/schemas/eu.js +1 -0
- package/dist/pubid-urn/schemas/itu.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ consumed here at a **pinned ref** and are never edited from this repo.
|
|
|
25
25
|
|
|
26
26
|
## Status
|
|
27
27
|
|
|
28
|
-
**All
|
|
28
|
+
**All 46 flavors supported in corpus mode.** The pubid-testsuite corpus is
|
|
29
29
|
a **closed universe**: every canonical spelling, canonical hash and URN,
|
|
30
30
|
plus every attested non-normalized alias. pubid-ts resolves and normalizes
|
|
31
31
|
any identifier IN that universe, and nothing outside it:
|
|
@@ -84,12 +84,12 @@ package — though it still uses Node's `fs`/`zlib` to read it, so
|
|
|
84
84
|
browser runtimes remain out of scope.
|
|
85
85
|
|
|
86
86
|
The conformance gate enforces corpus mode over the whole testsuite on
|
|
87
|
-
every CI run:
|
|
87
|
+
every CI run: 46/46 flavors, canonical hash, human form, URN, alias
|
|
88
88
|
normalization, negative rejection and deserialize idempotency.
|
|
89
89
|
|
|
90
90
|
## Grammar mode: open-universe runtime parsing
|
|
91
91
|
|
|
92
|
-
All
|
|
92
|
+
All 46 flavors are grammar-backed and ship the wave plan end to end
|
|
93
93
|
(core model → parser engine → builder → normalizer → renderer → urn →
|
|
94
94
|
per-flavor grammars). Grammar implementations parse real-world
|
|
95
95
|
identifiers far beyond the published corpus — novel spellings, unseen
|
package/artifact/corpus.json.gz
CHANGED
|
Binary file
|
package/dist/flavors/eu/index.js
CHANGED
|
@@ -10,7 +10,9 @@ export * from "./model.js";
|
|
|
10
10
|
* Pubid::Eu::Builder: CELEX and ELI fix year/number by position, the
|
|
11
11
|
* canonical and Official-Journal forms carry two numbers whose ORDER is
|
|
12
12
|
* not in the grammar (number_first_for), and the renderer's "No"
|
|
13
|
-
* disambiguation lives on the model (EuIdentifier#numbers).
|
|
13
|
+
* disambiguation lives on the model (EuIdentifier#numbers). The ELI
|
|
14
|
+
* subtype ("reg_impl") is stripped before the grammar and carried as an
|
|
15
|
+
* equality-ignored facet, as Identifier.bound_without_subtype does.
|
|
14
16
|
*/
|
|
15
17
|
// --- Builder (lib/pubid/eu/builder.rb) ---------------------------------------
|
|
16
18
|
const TYPES_BY_WORD = {
|
|
@@ -34,6 +36,27 @@ const s = (v) => {
|
|
|
34
36
|
const text = String(v);
|
|
35
37
|
return text.length > 0 ? text : undefined;
|
|
36
38
|
};
|
|
39
|
+
// The subtypes CELLAR gives each ELI type: implementing and delegated
|
|
40
|
+
// acts of every type, and the financial regulation (Identifier::
|
|
41
|
+
// ELI_SUBTYPES).
|
|
42
|
+
const ELI_SUBTYPES = {
|
|
43
|
+
reg: ["impl", "del", "financ"],
|
|
44
|
+
dir: ["impl", "del"],
|
|
45
|
+
dec: ["impl", "del"],
|
|
46
|
+
};
|
|
47
|
+
// The subtype of an ELI input, removed before the baked grammar (which
|
|
48
|
+
// knows only reg/dir/dec), as BSI and IETF strip their prefixes
|
|
49
|
+
// (Identifier::ELI_SUBTYPE).
|
|
50
|
+
const ELI_SUBTYPE = /^(https?:\/\/data\.europa\.eu\/eli\/(reg|dir|dec))_([a-z]+)\//;
|
|
51
|
+
/** A known subtype of a known ELI type, or undefined. An unknown one
|
|
52
|
+
* stays in the input, so the grammar rejects it. */
|
|
53
|
+
function eliSubtype(identifier) {
|
|
54
|
+
const match = ELI_SUBTYPE.exec(identifier);
|
|
55
|
+
if (match === null)
|
|
56
|
+
return undefined;
|
|
57
|
+
const subtype = match[3];
|
|
58
|
+
return (ELI_SUBTYPES[match[2]] ?? []).includes(subtype) ? subtype : undefined;
|
|
59
|
+
}
|
|
37
60
|
function positional(data) {
|
|
38
61
|
const letter = s(data["celex_letter"]);
|
|
39
62
|
const eli = s(data["eli_type"]);
|
|
@@ -77,7 +100,7 @@ function family(data) {
|
|
|
77
100
|
}
|
|
78
101
|
return bracket ?? suffix;
|
|
79
102
|
}
|
|
80
|
-
function buildEu(data) {
|
|
103
|
+
function buildEu(data, subtype) {
|
|
81
104
|
const act = positional(data) ?? fromPair(data);
|
|
82
105
|
if (!isPlausibleYear(act.year)) {
|
|
83
106
|
throw new Error(`EU legal act: ${act.year} is not a year`);
|
|
@@ -86,10 +109,12 @@ function buildEu(data) {
|
|
|
86
109
|
if (number === "0") {
|
|
87
110
|
throw new Error("EU legal act: number 0");
|
|
88
111
|
}
|
|
112
|
+
const fam = family(data);
|
|
89
113
|
const id = new act.klass({
|
|
90
114
|
number,
|
|
91
115
|
date: { year: act.year },
|
|
92
|
-
...(
|
|
116
|
+
...(fam !== undefined ? { family: fam } : {}),
|
|
117
|
+
...(subtype !== undefined ? { subtype } : {}),
|
|
93
118
|
});
|
|
94
119
|
// Keep the order only when it is not what the render rule prints.
|
|
95
120
|
if (act.numberFirst !== undefined && act.numberFirst !== id.defaultNumberFirst()) {
|
|
@@ -103,11 +128,18 @@ export function euGrammarImplementation() {
|
|
|
103
128
|
return {
|
|
104
129
|
parse(input) {
|
|
105
130
|
cachedRuntime ??= PubidRuntime.load("eu");
|
|
106
|
-
|
|
131
|
+
// An ELI subtype ("reg_impl") is stripped before the grammar, as
|
|
132
|
+
// the reference's bound_without_subtype does; the subtype rides
|
|
133
|
+
// the build as an equality-ignored facet.
|
|
134
|
+
const subtype = eliSubtype(input);
|
|
135
|
+
const stripped = subtype !== undefined
|
|
136
|
+
? input.replace(ELI_SUBTYPE, "$1/")
|
|
137
|
+
: input;
|
|
138
|
+
const bound = cachedRuntime.parseAndBind(stripped);
|
|
107
139
|
if (bound === null || typeof bound !== "object") {
|
|
108
140
|
throw new ParseFailed("eu: the artifact rejected the input", 0);
|
|
109
141
|
}
|
|
110
|
-
return buildEu(bound);
|
|
142
|
+
return buildEu(bound, subtype);
|
|
111
143
|
},
|
|
112
144
|
};
|
|
113
145
|
}
|
|
@@ -14,6 +14,13 @@ import type { PubidDate } from "../../model/component.js";
|
|
|
14
14
|
* `number_first` is the print ORDER of the two numbers — spelling, not
|
|
15
15
|
* identity: it serializes but `==` skips it (equality_ignored), so
|
|
16
16
|
* "EU Decision 1082/2013" equals the CELEX number 32013D1082.
|
|
17
|
+
* `subtype` is the ELI type subtype ("impl" implementing act, "del"
|
|
18
|
+
* delegated act, "financ" financial regulation) from an ELI such as
|
|
19
|
+
* http://data.europa.eu/eli/reg_impl/2016/1356/oj. Such an act shares
|
|
20
|
+
* the numbering of its type (the Official Journal cites it as
|
|
21
|
+
* "Commission Implementing Regulation (EU) 2016/1356"), so the subtype
|
|
22
|
+
* is not identity either: "EU Regulation 2016/1356" is the same act.
|
|
23
|
+
* Only #toEli reads it, to give the ELI back.
|
|
17
24
|
*/
|
|
18
25
|
/** The act-type metadata each leaf class carries (Ruby self.type). */
|
|
19
26
|
export interface EuType {
|
|
@@ -38,6 +45,7 @@ export declare class EuIdentifier extends BaseIdentifier {
|
|
|
38
45
|
readonly date: PubidDate | undefined;
|
|
39
46
|
readonly family: string | undefined;
|
|
40
47
|
readonly number_first: boolean | undefined;
|
|
48
|
+
readonly subtype: string | undefined;
|
|
41
49
|
/** The year, read off the date component (Ruby #year). */
|
|
42
50
|
get year(): string | undefined;
|
|
43
51
|
/** A regulation with a year before 2015 prints <number>/<year>;
|
|
@@ -65,7 +73,8 @@ export declare class EuIdentifier extends BaseIdentifier {
|
|
|
65
73
|
/** The CELEX number: sector 3, year, type letter, number padded to 4.
|
|
66
74
|
* (The base class carries no type letter — the segments join empty.) */
|
|
67
75
|
toCelex(): string;
|
|
68
|
-
/** The ELI of the act as published in the Official Journal
|
|
76
|
+
/** The ELI of the act as published in the Official Journal — the
|
|
77
|
+
* subtype rides the type segment ("reg_impl") when the input had one. */
|
|
69
78
|
toEli(): string;
|
|
70
79
|
/** The EU has no registered URN namespace (the ELI is its official
|
|
71
80
|
* identifier). This pubid-invented form keeps the act type, so a
|
package/dist/flavors/eu/model.js
CHANGED
|
@@ -12,10 +12,11 @@ export class EuIdentifier extends BaseIdentifier {
|
|
|
12
12
|
static attributes = extendAttributes(BaseIdentifier, {
|
|
13
13
|
family: { type: "string" },
|
|
14
14
|
number_first: { type: "boolean", equalityIgnored: true },
|
|
15
|
+
subtype: { type: "string", equalityIgnored: true },
|
|
15
16
|
});
|
|
16
|
-
// The gem's key_value whitelist: only the
|
|
17
|
+
// The gem's key_value whitelist: only the five slots hit the wire; the
|
|
17
18
|
// base's part/edition/publisher/... slots stay off it.
|
|
18
|
-
static mappings = keyValue({ wire: "number", to: "number" }, { wire: "date", to: "date" }, { wire: "family", to: "family" }, { wire: "number_first", to: "number_first" });
|
|
19
|
+
static mappings = keyValue({ wire: "number", to: "number" }, { wire: "date", to: "date" }, { wire: "family", to: "family" }, { wire: "number_first", to: "number_first" }, { wire: "subtype", to: "subtype" });
|
|
19
20
|
static euType = { key: "identifier", title: "", celex: null, eli: null };
|
|
20
21
|
/** The year, read off the date component (Ruby #year). */
|
|
21
22
|
get year() {
|
|
@@ -66,9 +67,12 @@ export class EuIdentifier extends BaseIdentifier {
|
|
|
66
67
|
toCelex() {
|
|
67
68
|
return `3${this.year ?? ""}${this.euCelexLetter() ?? ""}${(this.number ?? "").padStart(4, "0")}`;
|
|
68
69
|
}
|
|
69
|
-
/** The ELI of the act as published in the Official Journal
|
|
70
|
+
/** The ELI of the act as published in the Official Journal — the
|
|
71
|
+
* subtype rides the type segment ("reg_impl") when the input had one. */
|
|
70
72
|
toEli() {
|
|
71
|
-
|
|
73
|
+
const eli = this.euEliSegment() ?? "";
|
|
74
|
+
const typed = this.subtype !== undefined ? `${eli}_${this.subtype}` : eli;
|
|
75
|
+
return `http://data.europa.eu/eli/${typed}/${this.year ?? ""}/${this.number ?? ""}/oj`;
|
|
72
76
|
}
|
|
73
77
|
/** The EU has no registered URN namespace (the ELI is its official
|
|
74
78
|
* identifier). This pubid-invented form keeps the act type, so a
|
|
@@ -5,8 +5,8 @@ import { match, str } from "../../grammar/engine.js";
|
|
|
5
5
|
* succeeded alternative, so neighbour order in `identifier` is pinned
|
|
6
6
|
* by the Ruby comments):
|
|
7
7
|
* annex_to | special_publication | supplement | annex | appendix |
|
|
8
|
-
* report | handbook | numeric_question | letter_question |
|
|
9
|
-
* contribution | series_code | without_series
|
|
8
|
+
* report | resolution | handbook | numeric_question | letter_question |
|
|
9
|
+
* with_series | contribution | series_code | without_series
|
|
10
10
|
* and supplement chains precede supplement_with_base (which would
|
|
11
11
|
* otherwise strand "/Technical Cor. 1" trailing input).
|
|
12
12
|
*/
|
|
@@ -154,6 +154,15 @@ function buildRules() {
|
|
|
154
154
|
.then(space, rules["itu_prefix"], rules["sector"], space, rules["report_body"])
|
|
155
155
|
.or(rules["itu_prefix"].then(rules["sector"], space, rules["report_word"], space, rules["report_body"])));
|
|
156
156
|
rule("report_identifier", () => rules["base_report"].then(rules["language"].maybe()));
|
|
157
|
+
// ITU-R Resolution ("Resolution ITU-R 1-9 (2023)"): a number and its
|
|
158
|
+
// revision, never a series. Like the Report marker, the word is
|
|
159
|
+
// captured, and both the leading and the infix spelling are accepted.
|
|
160
|
+
rule("resolution_word", () => str("Resolution").or(str("Res.")).as("resolution_marker"));
|
|
161
|
+
rule("resolution_body", () => rules["code"].then(rules["document_date"].maybe()));
|
|
162
|
+
rule("base_resolution", () => rules["resolution_word"]
|
|
163
|
+
.then(space, rules["itu_prefix"], rules["sector"], space, rules["resolution_body"])
|
|
164
|
+
.or(rules["itu_prefix"].then(rules["sector"], space, rules["resolution_word"], space, rules["resolution_body"])));
|
|
165
|
+
rule("resolution_identifier", () => rules["base_resolution"].then(rules["language"].maybe()));
|
|
157
166
|
rule("base", () => rules["base_report"].or(rules["base_with_series"], rules["base_without_series"], rules["base_series_code"]));
|
|
158
167
|
// Annex label: one letter, optional number and/or "+" ("F3", "C+").
|
|
159
168
|
rule("annex_label", () => letter.then(digits.maybe(), str("+").maybe()));
|
|
@@ -254,7 +263,7 @@ function buildRules() {
|
|
|
254
263
|
rule("radio_regulations", () => rules["itu_prefix"]
|
|
255
264
|
.then(str("R").as("sector"), space, str("RR").as("radio_regulations"), rules["date_part"].or(dash.then(digit.repeat(4, 4).as("year"))).maybe(), rules["language"].maybe(), match(".").absent()));
|
|
256
265
|
rule("identifier", () => rules["annex_to_identifier"]
|
|
257
|
-
.or(rules["special_publication"], rules["supplement_identifier"], rules["annex_identifier"], rules["appendix_identifier"], rules["report_identifier"], rules["handbook"], rules["numeric_question"], rules["letter_question"], rules["radio_regulations"], rules["with_series"], rules["contribution"], rules["series_code_identifier"], rules["without_series"], rules["publication_id"]));
|
|
266
|
+
.or(rules["special_publication"], rules["supplement_identifier"], rules["annex_identifier"], rules["appendix_identifier"], rules["report_identifier"], rules["resolution_identifier"], rules["handbook"], rules["numeric_question"], rules["letter_question"], rules["radio_regulations"], rules["with_series"], rules["contribution"], rules["series_code_identifier"], rules["without_series"], rules["publication_id"]));
|
|
258
267
|
rule("root", () => rules["identifier"]
|
|
259
268
|
.then(rules["common_text_twin"])
|
|
260
269
|
.or(rules["identifier"]));
|
|
@@ -79,7 +79,11 @@ class ItuBuilder {
|
|
|
79
79
|
combined: this.buildDesignations(tree["combined"]),
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
|
-
const klass = tree["report_marker"] !== undefined
|
|
82
|
+
const klass = tree["report_marker"] !== undefined
|
|
83
|
+
? ITU_CLASSES["report"]
|
|
84
|
+
: tree["resolution_marker"] !== undefined
|
|
85
|
+
? ITU_CLASSES["resolution"]
|
|
86
|
+
: ITU_CLASSES["recommendation"];
|
|
83
87
|
return new klass({ ...common });
|
|
84
88
|
}
|
|
85
89
|
withTwin(identifier, twin) {
|
|
@@ -72,6 +72,11 @@ export declare class ItuReport extends ItuIdentifier {
|
|
|
72
72
|
static mappings: FieldMapping[];
|
|
73
73
|
renderBase(): string;
|
|
74
74
|
}
|
|
75
|
+
export declare class ItuResolution extends ItuIdentifier {
|
|
76
|
+
static polymorphicName: string;
|
|
77
|
+
static mappings: FieldMapping[];
|
|
78
|
+
renderBase(): string;
|
|
79
|
+
}
|
|
75
80
|
export declare class ItuHandbook extends ItuIdentifier {
|
|
76
81
|
static polymorphicName: string;
|
|
77
82
|
static mappings: FieldMapping[];
|
|
@@ -174,6 +179,7 @@ export declare class ItuAnnex extends ItuIdentifier {
|
|
|
174
179
|
export declare const ITU_CLASSES: {
|
|
175
180
|
readonly recommendation: typeof ItuRecommendation;
|
|
176
181
|
readonly report: typeof ItuReport;
|
|
182
|
+
readonly resolution: typeof ItuResolution;
|
|
177
183
|
readonly handbook: typeof ItuHandbook;
|
|
178
184
|
readonly special_publication: typeof ItuSpecialPublication;
|
|
179
185
|
readonly radio_regulations: typeof ItuRadioRegulations;
|
|
@@ -271,6 +271,10 @@ export class ItuUrnGenerator extends BaseUrnGenerator {
|
|
|
271
271
|
// reach the URN or the two same-numbered documents collide.
|
|
272
272
|
if (id instanceof ItuReport)
|
|
273
273
|
parts.push("report");
|
|
274
|
+
// A Resolution numbers independently too ("1-9" is also a
|
|
275
|
+
// Recommendation number), so it gets its own segment.
|
|
276
|
+
if (id instanceof ItuResolution)
|
|
277
|
+
parts.push("resolution");
|
|
274
278
|
if (id.series !== undefined) {
|
|
275
279
|
if (id.code !== undefined) {
|
|
276
280
|
const join = id.series_dash === true ? "-" : ".";
|
|
@@ -347,6 +351,24 @@ export class ItuReport extends ItuIdentifier {
|
|
|
347
351
|
}
|
|
348
352
|
registerType(ItuReport);
|
|
349
353
|
attachUrn(ItuReport);
|
|
354
|
+
// The ITU-R Resolution, adopted by the Radiocommunication Assembly
|
|
355
|
+
// ("Resolution ITU-R 1-9 (2023)"). A Resolution has a number and a
|
|
356
|
+
// revision (code.parts, as for a Recommendation edition), never a
|
|
357
|
+
// series. Resolutions number independently of Recommendations, so the
|
|
358
|
+
// leading word is part of the identity: it reaches to_s and the URN,
|
|
359
|
+
// and the class-strict == keeps "Resolution ITU-R 1-9" unequal to
|
|
360
|
+
// "ITU-R 1-9" in both directions. The grammar also reads "ITU-R Res.
|
|
361
|
+
// 1-9", "ITU-R Resolution 1-9" and "Res. ITU-R 1-9"; all render ITU's
|
|
362
|
+
// leading form.
|
|
363
|
+
export class ItuResolution extends ItuIdentifier {
|
|
364
|
+
static polymorphicName = "pubid:itu:resolution";
|
|
365
|
+
static mappings = STANDARD_MAPPINGS;
|
|
366
|
+
renderBase() {
|
|
367
|
+
return `Resolution ${super.renderBase()}`;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
registerType(ItuResolution);
|
|
371
|
+
attachUrn(ItuResolution);
|
|
350
372
|
export class ItuHandbook extends ItuIdentifier {
|
|
351
373
|
static polymorphicName = "pubid:itu:handbook";
|
|
352
374
|
static mappings = STANDARD_MAPPINGS;
|
|
@@ -629,6 +651,7 @@ attachUrn(ItuAnnex);
|
|
|
629
651
|
export const ITU_CLASSES = {
|
|
630
652
|
recommendation: ItuRecommendation,
|
|
631
653
|
report: ItuReport,
|
|
654
|
+
resolution: ItuResolution,
|
|
632
655
|
handbook: ItuHandbook,
|
|
633
656
|
special_publication: ItuSpecialPublication,
|
|
634
657
|
radio_regulations: ItuRadioRegulations,
|
|
@@ -9,6 +9,7 @@ import { define } from "../index.js";
|
|
|
9
9
|
export const euSchema = define("eu", (s) => {
|
|
10
10
|
s.atom("family", "family");
|
|
11
11
|
s.facet("number_first", "numberfirst", "bool");
|
|
12
|
+
s.facet("subtype", "subtype");
|
|
12
13
|
s.type("pubid:eu:regulation", "reg", { core: ["year", "number"] });
|
|
13
14
|
s.type("pubid:eu:directive", "dir", { core: ["year", "number"] });
|
|
14
15
|
s.type("pubid:eu:decision", "dec", { core: ["year", "number"] });
|
|
@@ -43,6 +43,7 @@ export const ituSchema = define("itu", (s) => {
|
|
|
43
43
|
s.facet("slash_joined", "slashjoined", "bool");
|
|
44
44
|
s.type("pubid:itu:recommendation", "rec");
|
|
45
45
|
s.type("pubid:itu:report", "rpt");
|
|
46
|
+
s.type("pubid:itu:resolution", "res");
|
|
46
47
|
s.type("pubid:itu:combined-identifier", "comb");
|
|
47
48
|
s.type("pubid:itu:question", "q");
|
|
48
49
|
s.type("pubid:itu:handbook", "hb");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pubid/pubid",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.60",
|
|
4
4
|
"description": "TypeScript PubID identifiers: resolution, normalization and canonical hashes for every identifier in the pubid-testsuite corpus (41 standards bodies), with a conformance runner mirroring the Ruby reference",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|