@pubid/pubid 0.1.3 → 0.1.4

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.
Files changed (183) hide show
  1. package/artifact/corpus.json.gz +0 -0
  2. package/dist/conformance/cli.js +5 -1
  3. package/dist/flavors/amca/grammar.d.ts +4 -0
  4. package/dist/flavors/amca/grammar.js +87 -0
  5. package/dist/flavors/amca/index.d.ts +4 -0
  6. package/dist/flavors/amca/index.js +76 -0
  7. package/dist/flavors/amca/model.d.ts +29 -0
  8. package/dist/flavors/amca/model.js +146 -0
  9. package/dist/flavors/ansi/index.d.ts +24 -0
  10. package/dist/flavors/ansi/index.js +147 -0
  11. package/dist/flavors/api/grammar.d.ts +4 -0
  12. package/dist/flavors/api/grammar.js +79 -0
  13. package/dist/flavors/api/index.d.ts +4 -0
  14. package/dist/flavors/api/index.js +71 -0
  15. package/dist/flavors/api/model.d.ts +27 -0
  16. package/dist/flavors/api/model.js +114 -0
  17. package/dist/flavors/ashrae/grammar.d.ts +2 -0
  18. package/dist/flavors/ashrae/grammar.js +667 -0
  19. package/dist/flavors/ashrae/index.d.ts +4 -0
  20. package/dist/flavors/ashrae/index.js +306 -0
  21. package/dist/flavors/ashrae/model.d.ts +87 -0
  22. package/dist/flavors/ashrae/model.js +335 -0
  23. package/dist/flavors/ashrae/preprocessor.d.ts +7 -0
  24. package/dist/flavors/ashrae/preprocessor.js +44 -0
  25. package/dist/flavors/asme/grammar.d.ts +2 -0
  26. package/dist/flavors/asme/grammar.js +200 -0
  27. package/dist/flavors/asme/index.d.ts +4 -0
  28. package/dist/flavors/asme/index.js +138 -0
  29. package/dist/flavors/asme/model.d.ts +34 -0
  30. package/dist/flavors/asme/model.js +123 -0
  31. package/dist/flavors/astm/grammar.d.ts +2 -0
  32. package/dist/flavors/astm/grammar.js +110 -0
  33. package/dist/flavors/astm/index.d.ts +2 -0
  34. package/dist/flavors/astm/index.js +127 -0
  35. package/dist/flavors/astm/model.d.ts +42 -0
  36. package/dist/flavors/astm/model.js +263 -0
  37. package/dist/flavors/bipm/index.d.ts +30 -0
  38. package/dist/flavors/bipm/index.js +434 -0
  39. package/dist/flavors/bsi/grammar.d.ts +4 -0
  40. package/dist/flavors/bsi/grammar.js +535 -0
  41. package/dist/flavors/bsi/index.d.ts +4 -0
  42. package/dist/flavors/bsi/index.js +941 -0
  43. package/dist/flavors/bsi/model.d.ts +127 -0
  44. package/dist/flavors/bsi/model.js +863 -0
  45. package/dist/flavors/calconnect/index.d.ts +21 -0
  46. package/dist/flavors/calconnect/index.js +113 -0
  47. package/dist/flavors/cen_cenelec/grammar.d.ts +4 -0
  48. package/dist/flavors/cen_cenelec/grammar.js +107 -0
  49. package/dist/flavors/cen_cenelec/index.d.ts +5 -0
  50. package/dist/flavors/cen_cenelec/index.js +263 -0
  51. package/dist/flavors/cen_cenelec/model.d.ts +45 -0
  52. package/dist/flavors/cen_cenelec/model.js +490 -0
  53. package/dist/flavors/cie/grammar.d.ts +5 -0
  54. package/dist/flavors/cie/grammar.js +127 -0
  55. package/dist/flavors/cie/index.d.ts +2 -0
  56. package/dist/flavors/cie/index.js +311 -0
  57. package/dist/flavors/cie/model.d.ts +122 -0
  58. package/dist/flavors/cie/model.js +464 -0
  59. package/dist/flavors/csa/grammar.d.ts +6 -0
  60. package/dist/flavors/csa/grammar.js +239 -0
  61. package/dist/flavors/csa/index.d.ts +2 -0
  62. package/dist/flavors/csa/index.js +634 -0
  63. package/dist/flavors/csa/model.d.ts +33 -0
  64. package/dist/flavors/csa/model.js +505 -0
  65. package/dist/flavors/doi/index.d.ts +13 -0
  66. package/dist/flavors/doi/index.js +65 -0
  67. package/dist/flavors/easc/index.d.ts +4 -0
  68. package/dist/flavors/easc/index.js +107 -0
  69. package/dist/flavors/ecma/index.d.ts +4 -0
  70. package/dist/flavors/ecma/index.js +117 -0
  71. package/dist/flavors/etsi/index.d.ts +14 -0
  72. package/dist/flavors/etsi/index.js +307 -0
  73. package/dist/flavors/evs/grammar.d.ts +2 -0
  74. package/dist/flavors/evs/grammar.js +22 -0
  75. package/dist/flavors/evs/index.d.ts +2 -0
  76. package/dist/flavors/evs/index.js +24 -0
  77. package/dist/flavors/evs/model.d.ts +19 -0
  78. package/dist/flavors/evs/model.js +36 -0
  79. package/dist/flavors/gb/index.d.ts +24 -0
  80. package/dist/flavors/gb/index.js +111 -0
  81. package/dist/flavors/gost/grammar.d.ts +2 -0
  82. package/dist/flavors/gost/grammar.js +46 -0
  83. package/dist/flavors/gost/index.d.ts +2 -0
  84. package/dist/flavors/gost/index.js +165 -0
  85. package/dist/flavors/gost/model.d.ts +61 -0
  86. package/dist/flavors/gost/model.js +147 -0
  87. package/dist/flavors/gost/prefix_routes.d.ts +15 -0
  88. package/dist/flavors/gost/prefix_routes.js +192 -0
  89. package/dist/flavors/iala/index.d.ts +32 -0
  90. package/dist/flavors/iala/index.js +300 -0
  91. package/dist/flavors/iana/index.d.ts +19 -0
  92. package/dist/flavors/iana/index.js +71 -0
  93. package/dist/flavors/idf/grammar.d.ts +2 -0
  94. package/dist/flavors/idf/grammar.js +71 -0
  95. package/dist/flavors/idf/index.d.ts +2 -0
  96. package/dist/flavors/idf/index.js +100 -0
  97. package/dist/flavors/idf/model.d.ts +54 -0
  98. package/dist/flavors/idf/model.js +359 -0
  99. package/dist/flavors/iec/grammar.d.ts +3 -0
  100. package/dist/flavors/iec/grammar.js +187 -0
  101. package/dist/flavors/iec/index.d.ts +4 -0
  102. package/dist/flavors/iec/index.js +507 -0
  103. package/dist/flavors/iec/model.d.ts +54 -0
  104. package/dist/flavors/iec/model.js +437 -0
  105. package/dist/flavors/ieee/grammar.d.ts +2 -0
  106. package/dist/flavors/ieee/grammar.js +626 -0
  107. package/dist/flavors/ieee/index.d.ts +3 -0
  108. package/dist/flavors/ieee/index.js +1186 -0
  109. package/dist/flavors/ieee/model.d.ts +142 -0
  110. package/dist/flavors/ieee/model.js +1148 -0
  111. package/dist/flavors/ieee/preprocessor.d.ts +8 -0
  112. package/dist/flavors/ieee/preprocessor.js +410 -0
  113. package/dist/flavors/ieee/update_codes.d.ts +8 -0
  114. package/dist/flavors/ieee/update_codes.js +191 -0
  115. package/dist/flavors/ietf/index.d.ts +30 -0
  116. package/dist/flavors/ietf/index.js +151 -0
  117. package/dist/flavors/iho/index.d.ts +4 -0
  118. package/dist/flavors/iho/index.js +126 -0
  119. package/dist/flavors/index.d.ts +9 -0
  120. package/dist/flavors/index.js +136 -0
  121. package/dist/flavors/isbn/index.d.ts +13 -0
  122. package/dist/flavors/isbn/index.js +97 -0
  123. package/dist/flavors/iso/grammar.d.ts +2 -0
  124. package/dist/flavors/iso/grammar.js +207 -0
  125. package/dist/flavors/iso/index.d.ts +2 -0
  126. package/dist/flavors/iso/index.js +343 -0
  127. package/dist/flavors/iso/model.d.ts +159 -0
  128. package/dist/flavors/iso/model.js +802 -0
  129. package/dist/flavors/iso/stages.generated.d.ts +13 -0
  130. package/dist/flavors/iso/stages.generated.js +391 -0
  131. package/dist/flavors/itu/grammar.d.ts +4 -0
  132. package/dist/flavors/itu/grammar.js +205 -0
  133. package/dist/flavors/itu/index.d.ts +2 -0
  134. package/dist/flavors/itu/index.js +224 -0
  135. package/dist/flavors/itu/model.d.ts +184 -0
  136. package/dist/flavors/itu/model.js +599 -0
  137. package/dist/flavors/jcgm/index.d.ts +7 -0
  138. package/dist/flavors/jcgm/index.js +300 -0
  139. package/dist/flavors/jis/index.d.ts +4 -0
  140. package/dist/flavors/jis/index.js +267 -0
  141. package/dist/flavors/nist/grammar.d.ts +2 -0
  142. package/dist/flavors/nist/grammar.js +287 -0
  143. package/dist/flavors/nist/index.d.ts +2 -0
  144. package/dist/flavors/nist/index.js +1244 -0
  145. package/dist/flavors/nist/model.d.ts +155 -0
  146. package/dist/flavors/nist/model.js +823 -0
  147. package/dist/flavors/nist/preprocessor.d.ts +11 -0
  148. package/dist/flavors/nist/preprocessor.js +281 -0
  149. package/dist/flavors/oasis/index.d.ts +23 -0
  150. package/dist/flavors/oasis/index.js +110 -0
  151. package/dist/flavors/ogc/index.d.ts +20 -0
  152. package/dist/flavors/ogc/index.js +75 -0
  153. package/dist/flavors/oiml/grammar.d.ts +2 -0
  154. package/dist/flavors/oiml/grammar.js +180 -0
  155. package/dist/flavors/oiml/implementation.d.ts +9 -0
  156. package/dist/flavors/oiml/implementation.js +16 -0
  157. package/dist/flavors/oiml/model.d.ts +4 -0
  158. package/dist/flavors/oiml/model.js +462 -0
  159. package/dist/flavors/omg/index.d.ts +14 -0
  160. package/dist/flavors/omg/index.js +73 -0
  161. package/dist/flavors/plateau/index.d.ts +4 -0
  162. package/dist/flavors/plateau/index.js +97 -0
  163. package/dist/flavors/tgpp/index.d.ts +4 -0
  164. package/dist/flavors/tgpp/index.js +122 -0
  165. package/dist/flavors/un/index.d.ts +13 -0
  166. package/dist/flavors/un/index.js +90 -0
  167. package/dist/flavors/w3c/index.d.ts +14 -0
  168. package/dist/flavors/w3c/index.js +148 -0
  169. package/dist/flavors/xsf/index.d.ts +18 -0
  170. package/dist/flavors/xsf/index.js +65 -0
  171. package/dist/grammar/engine.d.ts +78 -0
  172. package/dist/grammar/engine.js +351 -0
  173. package/dist/model/attribute.d.ts +54 -0
  174. package/dist/model/attribute.js +53 -0
  175. package/dist/model/builder.d.ts +39 -0
  176. package/dist/model/builder.js +124 -0
  177. package/dist/model/component.d.ts +70 -0
  178. package/dist/model/component.js +170 -0
  179. package/dist/model/identifier.d.ts +83 -0
  180. package/dist/model/identifier.js +270 -0
  181. package/dist/model/urn-generator.d.ts +27 -0
  182. package/dist/model/urn-generator.js +91 -0
  183. package/package.json +1 -1
@@ -0,0 +1,599 @@
1
+ import { BaseIdentifier, registerType } from "../../model/identifier.js";
2
+ import { extendAttributes, keyValue } from "../../model/attribute.js";
3
+ import { PubidDate } from "../../model/component.js";
4
+ import { BaseUrnGenerator } from "../../model/urn-generator.js";
5
+ import { Component } from "../../model/component.js";
6
+ /**
7
+ * Port of lib/pubid/itu/identifiers/* + components/{code,designation}.rb.
8
+ * The wire hash is FLAT (StandardSerialization / the Supplement block):
9
+ * sector/series/number/parts/… are bare top-level scalars read through
10
+ * the ItuCode component; publisher ("ITU") is never serialized
11
+ * (reconstructed on render).
12
+ */
13
+ /** Long-form ↔ single-letter language map (Identifiers::Base::LANGUAGES). */
14
+ export const ITU_LANGUAGES = {
15
+ fr: "F", es: "S", ru: "R", ar: "A", zh: "C", en: "E",
16
+ F: "F", S: "S", R: "R", A: "A", C: "C", E: "E",
17
+ };
18
+ /** The ITU Code component (Components::Code): [Imp]NUMBER[suffix][.subseries][-parts][qualifier]. */
19
+ export class ItuCode extends Component {
20
+ imp_marker;
21
+ number;
22
+ series_suffix;
23
+ series_suffix_spaced;
24
+ subseries;
25
+ parts;
26
+ qualifier;
27
+ qualifier_glued;
28
+ constructor(attrs) {
29
+ super();
30
+ this.imp_marker = attrs["imp_marker"];
31
+ this.number = attrs["number"];
32
+ this.series_suffix = attrs["series_suffix"];
33
+ this.series_suffix_spaced = attrs["series_suffix_spaced"] === true;
34
+ this.subseries = attrs["subseries"];
35
+ this.parts = Array.isArray(attrs["parts"]) ? attrs["parts"] : [];
36
+ this.qualifier = attrs["qualifier"];
37
+ this.qualifier_glued = attrs["qualifier_glued"] === true;
38
+ }
39
+ render() {
40
+ let result = `${this.imp_marker ?? ""}${this.number ?? ""}`;
41
+ if (this.series_suffix !== undefined && !this.series_suffix_spaced)
42
+ result += this.series_suffix;
43
+ if (this.subseries !== undefined)
44
+ result += `.${this.subseries}`;
45
+ if (this.parts.length > 0)
46
+ result += this.parts.map((p) => `-${p}`).join("");
47
+ if (this.qualifier !== undefined && this.qualifier_glued)
48
+ result += this.qualifier;
49
+ if (this.series_suffix !== undefined && this.series_suffix_spaced)
50
+ result += ` ${this.series_suffix}`;
51
+ if (this.qualifier !== undefined && !this.qualifier_glued)
52
+ result += ` ${this.qualifier}`;
53
+ return result;
54
+ }
55
+ /** Space-free form for URN/MR — keeps "D.200" and "D.200 R" distinct. */
56
+ compactS() {
57
+ return this.render().replaceAll(" ", "");
58
+ }
59
+ toWire() {
60
+ return {
61
+ ...(this.imp_marker !== undefined ? { imp_marker: this.imp_marker } : {}),
62
+ ...(this.number !== undefined ? { number: this.number } : {}),
63
+ ...(this.series_suffix !== undefined ? { series_suffix: this.series_suffix } : {}),
64
+ ...(this.series_suffix_spaced ? { series_suffix_spaced: true } : {}),
65
+ ...(this.subseries !== undefined ? { subseries: this.subseries } : {}),
66
+ ...(this.parts.length > 0 ? { parts: this.parts } : {}),
67
+ ...(this.qualifier !== undefined ? { qualifier: this.qualifier } : {}),
68
+ ...(this.qualifier_glued ? { qualifier_glued: true } : {}),
69
+ };
70
+ }
71
+ }
72
+ /** One "/SERIES.CODE" joint designation (Components::Designation). */
73
+ export class ItuDesignation extends Component {
74
+ series;
75
+ code;
76
+ constructor(attrs) {
77
+ super();
78
+ this.series = attrs["series"];
79
+ this.code =
80
+ attrs["code"] instanceof ItuCode
81
+ ? attrs["code"]
82
+ : new ItuCode(attrs["code"] ?? {});
83
+ }
84
+ render() {
85
+ return `${this.series ?? ""}.${this.code.render()}`;
86
+ }
87
+ toWire() {
88
+ return { series: this.series, code: this.code.toWire() };
89
+ }
90
+ }
91
+ export class ItuIdentifier extends BaseIdentifier {
92
+ static attributes = extendAttributes(BaseIdentifier, {
93
+ sector: { type: "string" },
94
+ series: { type: "string" },
95
+ code: { type: ItuCode },
96
+ date: { type: PubidDate },
97
+ language: { type: "string" },
98
+ version: { type: "string" },
99
+ series_word: { type: "boolean", default: false },
100
+ series_dash: { type: "boolean", default: false },
101
+ attachment: { type: "boolean", default: false },
102
+ range_end: { type: "string" },
103
+ common_text_twin: { type: "string" },
104
+ });
105
+ /** Walks `base` to the origin document (Pubid::Identifier#root). */
106
+ root() {
107
+ const base = this["base"];
108
+ return base instanceof ItuIdentifier ? base.root() : this;
109
+ }
110
+ /** " (M/YYYY)" / " (YYYY)" / "" — shared by every dated ITU type. */
111
+ dateSuffix() {
112
+ if (!(this.date instanceof PubidDate))
113
+ return "";
114
+ return this.date.month !== undefined
115
+ ? ` (${this.date.month}/${this.date.year})`
116
+ : ` (${this.date.year})`;
117
+ }
118
+ languageSuffix() {
119
+ if (this.language === undefined)
120
+ return "";
121
+ return ITU_LANGUAGES[this.language] === undefined ? "" : `-${this.language}`;
122
+ }
123
+ twinSuffix() {
124
+ return this.common_text_twin === undefined ? "" : ` | ${this.common_text_twin}`;
125
+ }
126
+ renderBase() {
127
+ let result = `ITU-${this.sector}`;
128
+ if (this.series !== undefined && this.code !== undefined) {
129
+ result += ` ${this.series}${this.series_dash === true ? "-" : "."}${this.code.render()}`;
130
+ }
131
+ else if (this.series !== undefined) {
132
+ result += ` ${this.series}`;
133
+ }
134
+ else {
135
+ result += ` ${this.code?.render() ?? ""}`;
136
+ }
137
+ if (this.range_end !== undefined)
138
+ result += `-${this.range_end}`;
139
+ if (this.series_word === true)
140
+ result += " series";
141
+ if (this.attachment === true)
142
+ result += " attachment";
143
+ if (this.version !== undefined)
144
+ result += ` (V${this.version})`;
145
+ return result + this.dateSuffix();
146
+ }
147
+ render() {
148
+ return this.renderBase() + this.languageSuffix() + this.twinSuffix();
149
+ }
150
+ }
151
+ // ---------------------------------------------------------------------------
152
+ // Flat converters (Identifiers::Base's shared *_to_kv/*_from_kv helpers).
153
+ // ---------------------------------------------------------------------------
154
+ const codeOf = (m) => m["code"];
155
+ /** One converter constructs the whole ItuCode from its sibling wire keys. */
156
+ function ituCodeFromHash(h) {
157
+ if (h["number"] === undefined || h["number"] === null)
158
+ return undefined;
159
+ return new ItuCode({
160
+ imp_marker: h["imp_marker"],
161
+ number: h["number"],
162
+ series_suffix: h["series_suffix"],
163
+ series_suffix_spaced: h["series_suffix_spaced"] === true,
164
+ subseries: h["subseries"],
165
+ parts: h["parts"],
166
+ qualifier: h["qualifier"],
167
+ qualifier_glued: h["qualifier_glued"] === true,
168
+ });
169
+ }
170
+ const codeKey = (wire, read) => ({
171
+ wire,
172
+ to: "code",
173
+ toWire: (m) => {
174
+ const code = codeOf(m);
175
+ return code === undefined ? undefined : read(code);
176
+ },
177
+ fromWire: () => undefined,
178
+ });
179
+ const yearMapping = () => ({
180
+ wire: "year",
181
+ to: "date",
182
+ toWire: (m) => m["date"]?.year,
183
+ fromWire: (h) => h["year"] === undefined || h["year"] === null
184
+ ? undefined
185
+ : new PubidDate({
186
+ year: String(h["year"]),
187
+ month: h["month"] === undefined || h["month"] === null ? undefined : String(h["month"]),
188
+ }),
189
+ });
190
+ const monthMapping = () => ({
191
+ wire: "month",
192
+ to: "date",
193
+ toWire: (m) => m["date"]?.month,
194
+ fromWire: () => undefined,
195
+ });
196
+ /** StandardSerialization — the single-document whitelist. */
197
+ const STANDARD_MAPPINGS = keyValue({ wire: "sector", to: "sector" }, { wire: "series", to: "series" }, codeKey("imp_marker", (c) => c.imp_marker), {
198
+ wire: "number",
199
+ to: "code",
200
+ toWire: (m) => codeOf(m)?.number,
201
+ fromWire: (h) => ituCodeFromHash(h),
202
+ }, codeKey("series_suffix", (c) => c.series_suffix), codeKey("series_suffix_spaced", (c) => (c.series_suffix_spaced ? true : undefined)), codeKey("subseries", (c) => c.subseries), codeKey("parts", (c) => (c.parts.length > 0 ? c.parts : undefined)), codeKey("qualifier", (c) => c.qualifier), codeKey("qualifier_glued", (c) => (c.qualifier_glued ? true : undefined)), { wire: "series_word", to: "series_word" }, { wire: "series_dash", to: "series_dash" }, { wire: "attachment", to: "attachment" }, { wire: "range_end", to: "range_end" }, { wire: "version", to: "version" }, yearMapping(), monthMapping(), { wire: "language", to: "language" }, { wire: "common_text_twin", to: "common_text_twin" });
203
+ /**
204
+ * The Supplement block: sector/series/series_word are emitted ONLY for
205
+ * the base-less series-only form; with a base they are redundant
206
+ * copies of the base's (supplement_sector_to_kv's base-nil guard).
207
+ */
208
+ const SUPPLEMENT_MAPPINGS = keyValue({ wire: "sector", to: "sector", toWire: (m) => (m["base"] === undefined ? m["sector"] : undefined) }, { wire: "series", to: "series", toWire: (m) => (m["base"] === undefined ? m["series"] : undefined) }, {
209
+ wire: "series_word",
210
+ to: "series_word",
211
+ toWire: (m) => (m["base"] === undefined && m["series_word"] === true ? true : undefined),
212
+ }, { wire: "number", to: "number" }, { wire: "number_glued", to: "number_glued" }, { wire: "slash_joined", to: "slash_joined" }, yearMapping(), monthMapping(), { wire: "base", to: "base" }, { wire: "common_text_twin", to: "common_text_twin" });
213
+ // ---------------------------------------------------------------------------
214
+ // URN generation (lib/pubid/itu/urn_generator.rb) — declared before the
215
+ // concrete classes so the attachUrn statements below it are initialized;
216
+ // its bodies reference the classes only at call time.
217
+ // ---------------------------------------------------------------------------
218
+ function urnDateSegment(id) {
219
+ if (!(id.date instanceof PubidDate))
220
+ return undefined;
221
+ return id.date.month !== undefined ? `${id.date.month}/${id.date.year}` : id.date.year;
222
+ }
223
+ export class ItuUrnGenerator extends BaseUrnGenerator {
224
+ generate() {
225
+ const id = this.identifier;
226
+ if (id instanceof ItuAnnex) {
227
+ const baseUrn = id.base?.toUrn();
228
+ return baseUrn === undefined ? "urn:itu:annex" : `${baseUrn}:annex`;
229
+ }
230
+ if (id instanceof ItuAnnexOfRecommendation || id instanceof ItuAppendixOfRecommendation) {
231
+ const segments = [
232
+ id.base?.toUrn() ?? "urn:itu",
233
+ id instanceof ItuAnnexOfRecommendation ? "annex" : "appendix",
234
+ id.number?.toLowerCase(),
235
+ ];
236
+ if (id instanceof ItuAppendixOfRecommendation && id.material !== undefined) {
237
+ segments.push(id.material.toLowerCase().replace(/[^a-z0-9]/g, ""));
238
+ }
239
+ segments.push(urnDateSegment(id));
240
+ return segments.filter((s) => s !== undefined).join(":");
241
+ }
242
+ if (id instanceof ItuSupplement)
243
+ return this.generateSupplementUrn(id);
244
+ return this.generateBaseUrn(id);
245
+ }
246
+ generateBaseUrn(id) {
247
+ const parts = ["urn", "itu"];
248
+ parts.push(id.sector !== undefined ? id.sector.toLowerCase() : "itu");
249
+ // Reports number independently of Recommendations — the marker must
250
+ // reach the URN or the two same-numbered documents collide.
251
+ if (id instanceof ItuReport)
252
+ parts.push("report");
253
+ if (id.series !== undefined) {
254
+ if (id.code !== undefined) {
255
+ const join = id.series_dash === true ? "-" : ".";
256
+ parts.push(`${id.series}${join}${id.code.compactS()}`);
257
+ }
258
+ else {
259
+ parts.push(id.series);
260
+ }
261
+ }
262
+ else if (id.code !== undefined) {
263
+ parts.push(id.code.compactS());
264
+ }
265
+ if (id.series_word === true)
266
+ parts.push("series");
267
+ if (id.attachment === true)
268
+ parts.push("attachment");
269
+ if (id.range_end !== undefined)
270
+ parts.push(`to-${id.range_end}`);
271
+ const segment = urnDateSegment(id);
272
+ if (segment !== undefined)
273
+ parts.push(segment);
274
+ if (id.language !== undefined)
275
+ parts.push(id.language.toLowerCase());
276
+ return parts.join(":");
277
+ }
278
+ generateSupplementUrn(id) {
279
+ const parts = ["urn", "itu"];
280
+ if (id.base !== undefined) {
281
+ // An annex/appendix base holds its identity in ITS own base —
282
+ // go through its to_urn instead (the nested_wrapper branch).
283
+ const nestedWrapper = id.base instanceof ItuAnnexOfRecommendation || id.base instanceof ItuAppendixOfRecommendation;
284
+ const baseUrn = nestedWrapper ? id.base.toUrn() : this.generateBaseUrn(id.base);
285
+ parts.push(...baseUrn.replace(/^urn:itu:/, "").split(":"));
286
+ }
287
+ else {
288
+ if (id.sector !== undefined)
289
+ parts.push(id.sector.toLowerCase());
290
+ if (id.series !== undefined) {
291
+ if (id.code !== undefined)
292
+ parts.push(`${id.series}.${id.code.compactS()}`);
293
+ else
294
+ parts.push(id.series);
295
+ }
296
+ // The base-less supplement's whole identity is sector + series.
297
+ if (id.series_word === true)
298
+ parts.push("series");
299
+ }
300
+ if (id.number !== undefined)
301
+ parts.push(id.number);
302
+ const segment = urnDateSegment(id);
303
+ if (segment !== undefined)
304
+ parts.push(segment);
305
+ return parts.join(":");
306
+ }
307
+ }
308
+ function attachUrn(klass) {
309
+ klass["urnGenerator"] = ItuUrnGenerator;
310
+ }
311
+ // ---------------------------------------------------------------------------
312
+ // The concrete classes.
313
+ // ---------------------------------------------------------------------------
314
+ export class ItuRecommendation extends ItuIdentifier {
315
+ static polymorphicName = "pubid:itu:recommendation";
316
+ static mappings = STANDARD_MAPPINGS;
317
+ }
318
+ registerType(ItuRecommendation);
319
+ attachUrn(ItuRecommendation);
320
+ export class ItuReport extends ItuIdentifier {
321
+ static polymorphicName = "pubid:itu:report";
322
+ static mappings = STANDARD_MAPPINGS;
323
+ renderBase() {
324
+ return `Report ${super.renderBase()}`;
325
+ }
326
+ }
327
+ registerType(ItuReport);
328
+ attachUrn(ItuReport);
329
+ export class ItuHandbook extends ItuIdentifier {
330
+ static polymorphicName = "pubid:itu:handbook";
331
+ static mappings = STANDARD_MAPPINGS;
332
+ renderBase() {
333
+ return `ITU-${this.sector} ${this.code?.number ?? ""}.HDB${this.dateSuffix()}`;
334
+ }
335
+ }
336
+ registerType(ItuHandbook);
337
+ attachUrn(ItuHandbook);
338
+ export class ItuSpecialPublication extends ItuIdentifier {
339
+ static polymorphicName = "pubid:itu:special-publication";
340
+ static mappings = STANDARD_MAPPINGS;
341
+ renderBase() {
342
+ let result = `ITU ${this.series} No. ${this.code?.number ?? ""}`;
343
+ if (this.date instanceof PubidDate) {
344
+ result += this.date.month !== undefined
345
+ ? ` (${this.date.month.padStart(2, "0")}/${this.date.year})`
346
+ : ` (${this.date.year})`;
347
+ }
348
+ return result;
349
+ }
350
+ }
351
+ registerType(ItuSpecialPublication);
352
+ attachUrn(ItuSpecialPublication);
353
+ export class ItuContribution extends ItuIdentifier {
354
+ static polymorphicName = "pubid:itu:contribution";
355
+ static mappings = STANDARD_MAPPINGS;
356
+ renderBase() {
357
+ return `ITU-${this.sector} ${this.series}-C${this.code?.number ?? ""}`;
358
+ }
359
+ }
360
+ registerType(ItuContribution);
361
+ attachUrn(ItuContribution);
362
+ export class ItuQuestion extends ItuIdentifier {
363
+ static polymorphicName = "pubid:itu:question";
364
+ static attributes = extendAttributes(ItuIdentifier, {
365
+ study_group: { type: "string" },
366
+ has_bl: { type: "boolean", default: false },
367
+ bracketed: { type: "boolean", default: false },
368
+ has_colon: { type: "boolean", default: false },
369
+ });
370
+ static mappings = keyValue(...STANDARD_MAPPINGS, { wire: "study_group", to: "study_group" }, { wire: "has_bl", to: "has_bl" }, { wire: "bracketed", to: "bracketed" }, { wire: "has_colon", to: "has_colon" });
371
+ renderBase() {
372
+ let result = `ITU-${this.sector}`;
373
+ result += this.series !== undefined ? ` ${this.series}.` : " ";
374
+ if (this.bracketed === true)
375
+ result += "[";
376
+ result += this.code?.render() ?? "";
377
+ if (this.has_bl === true)
378
+ result += "/BL";
379
+ result += `/${this.study_group}`;
380
+ if (this.bracketed === true)
381
+ result += "]";
382
+ if (this.has_colon === true)
383
+ result += ":";
384
+ return result;
385
+ }
386
+ }
387
+ registerType(ItuQuestion);
388
+ attachUrn(ItuQuestion);
389
+ export class ItuCombinedIdentifier extends ItuIdentifier {
390
+ static polymorphicName = "pubid:itu:combined-identifier";
391
+ static attributes = extendAttributes(ItuIdentifier, {
392
+ combined: { type: ItuDesignation, collection: true, initializeEmpty: true },
393
+ });
394
+ static mappings = keyValue(...STANDARD_MAPPINGS, {
395
+ wire: "combined",
396
+ to: "combined",
397
+ toWire: (m) => {
398
+ const list = m["combined"];
399
+ if (list === undefined || list.length === 0)
400
+ return undefined;
401
+ return list.map((d) => {
402
+ const row = {
403
+ series: d.series,
404
+ number: d.code.number,
405
+ };
406
+ if (d.code.subseries !== undefined)
407
+ row["subseries"] = d.code.subseries;
408
+ if (d.code.parts.length > 0)
409
+ row["parts"] = d.code.parts;
410
+ if (d.code.series_suffix !== undefined) {
411
+ row["series_suffix"] = d.code.series_suffix;
412
+ if (d.code.series_suffix_spaced)
413
+ row["series_suffix_spaced"] = true;
414
+ }
415
+ if (d.code.qualifier !== undefined) {
416
+ row["qualifier"] = d.code.qualifier;
417
+ if (d.code.qualifier_glued)
418
+ row["qualifier_glued"] = true;
419
+ }
420
+ return row;
421
+ });
422
+ },
423
+ fromWire: (h) => {
424
+ const rows = h["combined"];
425
+ if (!Array.isArray(rows))
426
+ return undefined;
427
+ return rows.map((row) => {
428
+ const r = row;
429
+ return new ItuDesignation({
430
+ series: r["series"],
431
+ code: new ItuCode({
432
+ number: r["number"],
433
+ series_suffix: r["series_suffix"],
434
+ series_suffix_spaced: r["series_suffix_spaced"] === true,
435
+ subseries: r["subseries"],
436
+ parts: r["parts"],
437
+ qualifier: r["qualifier"],
438
+ qualifier_glued: r["qualifier_glued"] === true,
439
+ }),
440
+ });
441
+ });
442
+ },
443
+ });
444
+ renderBase() {
445
+ let result = `ITU-${this.sector}`;
446
+ result +=
447
+ this.series !== undefined
448
+ ? ` ${this.series}${this.series_dash === true ? "-" : "."}${this.code?.render() ?? ""}`
449
+ : ` ${this.code?.render() ?? ""}`;
450
+ if (this.range_end !== undefined)
451
+ result += `-${this.range_end}`;
452
+ if (this.combined.length > 0) {
453
+ result += `/${this.combined.map((d) => d.render()).join("/")}`;
454
+ }
455
+ if (this.series_word === true)
456
+ result += " series";
457
+ if (this.attachment === true)
458
+ result += " attachment";
459
+ if (this.version !== undefined)
460
+ result += ` (V${this.version})`;
461
+ return result + this.dateSuffix();
462
+ }
463
+ }
464
+ registerType(ItuCombinedIdentifier);
465
+ attachUrn(ItuCombinedIdentifier);
466
+ // --- Supplements -----------------------------------------------------------
467
+ export class ItuSupplement extends ItuIdentifier {
468
+ static attributes = extendAttributes(ItuIdentifier, {
469
+ base: { type: ItuIdentifier },
470
+ number: { type: "string" },
471
+ number_glued: { type: "boolean", default: false },
472
+ slash_joined: { type: "boolean", default: false },
473
+ });
474
+ renderSupplement(label) {
475
+ let result = this.base !== undefined ? this.base.toHuman() : `ITU-${this.sector}`;
476
+ if (this.base === undefined && this.series !== undefined) {
477
+ result += ` ${this.series}`;
478
+ if (this.series_word === true)
479
+ result += " series";
480
+ }
481
+ result += this.slash_joined === true ? "/" : " ";
482
+ result += label;
483
+ if (this.number_glued !== true)
484
+ result += " ";
485
+ result += `${this.number ?? ""}`;
486
+ return result + this.dateSuffix();
487
+ }
488
+ }
489
+ export class ItuSupplementSuppl extends ItuSupplement {
490
+ static polymorphicName = "pubid:itu:supplement";
491
+ static mappings = SUPPLEMENT_MAPPINGS;
492
+ render() {
493
+ return this.renderSupplement("Suppl.");
494
+ }
495
+ }
496
+ registerType(ItuSupplementSuppl);
497
+ attachUrn(ItuSupplementSuppl);
498
+ export class ItuAmendment extends ItuSupplement {
499
+ static polymorphicName = "pubid:itu:amendment";
500
+ static mappings = SUPPLEMENT_MAPPINGS;
501
+ render() {
502
+ return this.renderSupplement("Amd.");
503
+ }
504
+ }
505
+ registerType(ItuAmendment);
506
+ attachUrn(ItuAmendment);
507
+ export class ItuAddendum extends ItuSupplement {
508
+ static polymorphicName = "pubid:itu:addendum";
509
+ static mappings = SUPPLEMENT_MAPPINGS;
510
+ render() {
511
+ return this.renderSupplement("Add.");
512
+ }
513
+ }
514
+ registerType(ItuAddendum);
515
+ attachUrn(ItuAddendum);
516
+ export class ItuErrata extends ItuSupplement {
517
+ static polymorphicName = "pubid:itu:errata";
518
+ static mappings = SUPPLEMENT_MAPPINGS;
519
+ render() {
520
+ return this.renderSupplement("Err.");
521
+ }
522
+ }
523
+ registerType(ItuErrata);
524
+ attachUrn(ItuErrata);
525
+ export class ItuCorrigendum extends ItuSupplement {
526
+ static polymorphicName = "pubid:itu:corrigendum";
527
+ static attributes = extendAttributes(ItuSupplement, {
528
+ technical: { type: "boolean", default: false },
529
+ });
530
+ static mappings = keyValue(...SUPPLEMENT_MAPPINGS, { wire: "technical", to: "technical" });
531
+ render() {
532
+ return this.renderSupplement(this.technical === true ? "Technical Cor." : "Cor.");
533
+ }
534
+ }
535
+ registerType(ItuCorrigendum);
536
+ attachUrn(ItuCorrigendum);
537
+ // --- Wrappers (annex / appendix of a Recommendation, Annex to OB) ----------
538
+ export class ItuAnnexOfRecommendation extends ItuIdentifier {
539
+ static polymorphicName = "pubid:itu:annex-of-recommendation";
540
+ static attributes = extendAttributes(ItuIdentifier, {
541
+ base: { type: ItuIdentifier },
542
+ number: { type: "string" },
543
+ });
544
+ static mappings = keyValue({ wire: "number", to: "number" }, yearMapping(), monthMapping(), { wire: "base", to: "base" }, { wire: "language", to: "language" }, { wire: "common_text_twin", to: "common_text_twin" });
545
+ renderBase() {
546
+ const head = this.base !== undefined ? this.base.renderBase() : `ITU-${this.sector}`;
547
+ return `${head} Annex ${this.number}${this.dateSuffix()}`;
548
+ }
549
+ }
550
+ registerType(ItuAnnexOfRecommendation);
551
+ attachUrn(ItuAnnexOfRecommendation);
552
+ export class ItuAppendixOfRecommendation extends ItuIdentifier {
553
+ static polymorphicName = "pubid:itu:appendix-of-recommendation";
554
+ static attributes = extendAttributes(ItuIdentifier, {
555
+ base: { type: ItuIdentifier },
556
+ number: { type: "string" },
557
+ material: { type: "string" },
558
+ });
559
+ static mappings = keyValue({ wire: "number", to: "number" }, { wire: "material", to: "material" }, yearMapping(), monthMapping(), { wire: "base", to: "base" }, { wire: "language", to: "language" }, { wire: "common_text_twin", to: "common_text_twin" });
560
+ renderBase() {
561
+ const head = this.base !== undefined ? this.base.renderBase() : `ITU-${this.sector}`;
562
+ let result = `${head} App. ${this.number}`;
563
+ if (this.material !== undefined)
564
+ result += ` ${this.material}`;
565
+ return result + this.dateSuffix();
566
+ }
567
+ }
568
+ registerType(ItuAppendixOfRecommendation);
569
+ attachUrn(ItuAppendixOfRecommendation);
570
+ export class ItuAnnex extends ItuIdentifier {
571
+ static polymorphicName = "pubid:itu:annex";
572
+ static attributes = extendAttributes(ItuIdentifier, {
573
+ base: { type: ItuIdentifier },
574
+ });
575
+ static mappings = keyValue({ wire: "base", to: "base" }, { wire: "language", to: "language" }, { wire: "common_text_twin", to: "common_text_twin" });
576
+ renderBase() {
577
+ return `Annex to ${this.base?.renderBase() ?? ""}`;
578
+ }
579
+ }
580
+ registerType(ItuAnnex);
581
+ attachUrn(ItuAnnex);
582
+ /** The builder's class table (kind token → class). */
583
+ export const ITU_CLASSES = {
584
+ recommendation: ItuRecommendation,
585
+ report: ItuReport,
586
+ handbook: ItuHandbook,
587
+ special_publication: ItuSpecialPublication,
588
+ contribution: ItuContribution,
589
+ question: ItuQuestion,
590
+ combined: ItuCombinedIdentifier,
591
+ supplement: ItuSupplementSuppl,
592
+ amendment: ItuAmendment,
593
+ addendum: ItuAddendum,
594
+ errata: ItuErrata,
595
+ corrigendum: ItuCorrigendum,
596
+ annex_of: ItuAnnexOfRecommendation,
597
+ appendix_of: ItuAppendixOfRecommendation,
598
+ annex_to: ItuAnnex,
599
+ };
@@ -0,0 +1,7 @@
1
+ import { Grammar } from "../../grammar/engine.js";
2
+ import type { Tree, TreeObject } from "../../grammar/engine.js";
3
+ import type { FlavorImplementation } from "../../conformance/implementation.js";
4
+ export declare const jcgmGrammar: Grammar;
5
+ declare function isObj(v: Tree): v is TreeObject;
6
+ export declare function jcgmGrammarImplementation(): FlavorImplementation;
7
+ export { isObj };