@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,823 @@
1
+ import { BaseIdentifier, registerType } from "../../model/identifier.js";
2
+ import { extendAttributes, keyValue } from "../../model/attribute.js";
3
+ import { Component } from "../../model/component.js";
4
+ import { BaseUrnGenerator } from "../../model/urn-generator.js";
5
+ /**
6
+ * Port of lib/pubid/nist/identifiers/base.rb + components/*. The wire
7
+ * hash mirrors the Ruby compact shape: series/subseries/volume are bare
8
+ * scalars, first/second_number are dropped (build artifacts), and the
9
+ * components serialize as their plain field hashes.
10
+ */
11
+ // --- Components ---------------------------------------------------------------
12
+ export class NistCode extends Component {
13
+ value;
14
+ constructor(attrs) {
15
+ super();
16
+ this.value = String(attrs["value"] ?? "");
17
+ }
18
+ render() {
19
+ return this.value;
20
+ }
21
+ toWire() {
22
+ return { value: this.value };
23
+ }
24
+ }
25
+ export class NistPart {
26
+ type;
27
+ value;
28
+ constructor(attrs) {
29
+ this.type = String(attrs["type"] ?? "");
30
+ this.value = String(attrs["value"] ?? "");
31
+ }
32
+ toWire() {
33
+ return this.type === "" ? { value: this.value } : { type: this.type, value: this.value };
34
+ }
35
+ render(notation) {
36
+ if (notation !== undefined)
37
+ return notation === "" ? this.value : `${notation}${this.value}`;
38
+ if (this.type === "pt")
39
+ return `pt${this.value}`;
40
+ if (this.type === "n")
41
+ return `n${this.value}`;
42
+ if (this.type === "")
43
+ return this.value;
44
+ return `n${this.value}`;
45
+ }
46
+ }
47
+ export class NistVolume {
48
+ value;
49
+ constructor(attrs) {
50
+ this.value = String(attrs["value"] ?? "");
51
+ }
52
+ toWire() {
53
+ return { value: this.value };
54
+ }
55
+ render() {
56
+ return `v${this.value}`;
57
+ }
58
+ }
59
+ export class NistIssueNumber {
60
+ number;
61
+ constructor(attrs) {
62
+ this.number = String(attrs["number"] ?? "");
63
+ }
64
+ toWire() {
65
+ return { number: this.number };
66
+ }
67
+ render() {
68
+ return `n${this.number}`;
69
+ }
70
+ }
71
+ export class NistEdition {
72
+ type;
73
+ id;
74
+ additional_text;
75
+ original_prefix;
76
+ constructor(attrs) {
77
+ this.type = attrs["type"];
78
+ this.id = attrs["id"];
79
+ this.additional_text = attrs["additional_text"];
80
+ this.original_prefix = attrs["original_prefix"];
81
+ }
82
+ toWire() {
83
+ return {
84
+ ...(this.type !== undefined && this.type !== "" ? { type: this.type } : {}),
85
+ ...(this.id !== undefined && this.id !== "" ? { id: this.id } : {}),
86
+ ...(this.additional_text !== undefined && this.additional_text !== "" ? { additional_text: this.additional_text } : {}),
87
+ ...(this.original_prefix !== undefined && this.original_prefix !== "" ? { original_prefix: this.original_prefix } : {}),
88
+ };
89
+ }
90
+ render() {
91
+ if (this.type === "r" && this.original_prefix !== undefined && this.original_prefix !== "") {
92
+ let result = `${this.original_prefix}${this.id ?? ""}`;
93
+ if (this.additional_text !== undefined && this.additional_text !== "") {
94
+ result += /^[A-Za-z]$/.test(this.additional_text) ? this.additional_text.toUpperCase() : `.${this.additional_text}`;
95
+ }
96
+ return result;
97
+ }
98
+ if (this.type === "e" && this.original_prefix === "-" && this.id !== undefined && /^\d{4}$/.test(this.id)) {
99
+ return `-${this.id}`;
100
+ }
101
+ let result = `${this.type ?? ""}${this.id ?? ""}`;
102
+ if (this.additional_text !== undefined && this.additional_text !== "") {
103
+ if (this.type === "-" && /^[A-Z][a-z]+\d{4}$/.test(this.additional_text)) {
104
+ result = `-${this.additional_text}`;
105
+ }
106
+ else if (/^[A-Za-z]$/.test(this.additional_text)) {
107
+ result += this.additional_text.toUpperCase();
108
+ }
109
+ else {
110
+ result += `.${this.additional_text}`;
111
+ }
112
+ }
113
+ return result;
114
+ }
115
+ }
116
+ export class NistUpdate {
117
+ number;
118
+ year;
119
+ month;
120
+ prefix;
121
+ constructor(attrs) {
122
+ this.number = attrs["number"];
123
+ this.year = attrs["year"];
124
+ this.month = attrs["month"];
125
+ this.prefix = attrs["prefix"];
126
+ }
127
+ toWire() {
128
+ return {
129
+ ...(this.number !== undefined ? { number: this.number } : {}),
130
+ ...(this.year !== undefined ? { year: this.year } : {}),
131
+ ...(this.month !== undefined ? { month: this.month } : {}),
132
+ ...(this.prefix !== undefined ? { prefix: this.prefix } : {}),
133
+ };
134
+ }
135
+ render(format = "short") {
136
+ if (this.prefix === "dash") {
137
+ return this.year !== undefined ? `-upd${this.number ?? ""}-${this.yearMonth()}` : `-upd${this.number ?? ""}`;
138
+ }
139
+ if (format === "mr") {
140
+ if (this.number === undefined && this.year === undefined)
141
+ return "-upd";
142
+ return this.year !== undefined ? `-upd${this.number ?? ""}-${this.yearMonth()}` : `-upd${this.number ?? ""}`;
143
+ }
144
+ return this.year !== undefined ? `/Upd${this.number ?? ""}-${this.yearMonth()}` : `/Upd${this.number ?? ""}`;
145
+ }
146
+ yearMonth() {
147
+ if (this.year === undefined)
148
+ return "";
149
+ return this.month !== undefined ? `${this.year}${this.month.padStart(2, "0")}` : this.year;
150
+ }
151
+ }
152
+ export class NistTranslation {
153
+ code;
154
+ constructor(attrs) {
155
+ this.code = String(attrs["code"] ?? "");
156
+ }
157
+ toWire() {
158
+ return { code: this.code };
159
+ }
160
+ render(format = "short") {
161
+ return format === "mr" ? `.${this.code}` : ` ${this.code}`;
162
+ }
163
+ }
164
+ export class NistStage {
165
+ id;
166
+ type;
167
+ constructor(attrs) {
168
+ this.id = String(attrs["id"] ?? "");
169
+ this.type = String(attrs["type"] ?? "");
170
+ }
171
+ toWire() {
172
+ return { id: this.id, type: this.type };
173
+ }
174
+ render() {
175
+ if (this.id === "" || this.type === "")
176
+ return "";
177
+ return `${this.id}${this.type}`;
178
+ }
179
+ }
180
+ export class NistVersion {
181
+ value;
182
+ constructor(attrs) {
183
+ this.value = String(attrs["value"] ?? "");
184
+ }
185
+ toWire() {
186
+ return { value: this.value };
187
+ }
188
+ render() {
189
+ return `ver${this.value}`;
190
+ }
191
+ }
192
+ export class NistSupplement {
193
+ number;
194
+ year;
195
+ month;
196
+ month_end;
197
+ year_end;
198
+ has_revision;
199
+ suffix;
200
+ constructor(attrs) {
201
+ this.number = attrs["number"];
202
+ this.year = attrs["year"];
203
+ this.month = attrs["month"];
204
+ this.month_end = attrs["month_end"];
205
+ this.year_end = attrs["year_end"];
206
+ this.has_revision = attrs["has_revision"] === true;
207
+ this.suffix = attrs["suffix"];
208
+ }
209
+ toWire() {
210
+ const empty = this.number === undefined && this.year === undefined && this.month === undefined &&
211
+ this.month_end === undefined && this.year_end === undefined && !this.has_revision &&
212
+ this.suffix === undefined;
213
+ if (empty)
214
+ return undefined;
215
+ return {
216
+ ...(this.number !== undefined ? { number: this.number } : {}),
217
+ ...(this.year !== undefined ? { year: this.year } : {}),
218
+ ...(this.month !== undefined ? { month: this.month } : {}),
219
+ ...(this.month_end !== undefined ? { month_end: this.month_end } : {}),
220
+ ...(this.year_end !== undefined ? { year_end: this.year_end } : {}),
221
+ ...(this.has_revision ? { has_revision: true } : {}),
222
+ ...(this.suffix !== undefined ? { suffix: this.suffix } : {}),
223
+ };
224
+ }
225
+ static fromRaw(value, hasRevision = false) {
226
+ const supp = {};
227
+ if (hasRevision) {
228
+ supp["has_revision"] = true;
229
+ }
230
+ else if (value === undefined || value === "") {
231
+ // empty
232
+ }
233
+ else {
234
+ const m = /^([A-Za-z]{3,9})(\d{4})$/.exec(value);
235
+ if (m !== null) {
236
+ supp["month"] = m[1];
237
+ supp["year"] = m[2];
238
+ }
239
+ else if (/^(18|19|20)\d{2}$/.test(value)) {
240
+ supp["year"] = value;
241
+ }
242
+ else if (/^\d+$/.test(value)) {
243
+ supp["number"] = value;
244
+ }
245
+ else {
246
+ supp["suffix"] = value;
247
+ }
248
+ }
249
+ return new NistSupplement(supp);
250
+ }
251
+ isRange() {
252
+ return this.year !== undefined && this.year_end !== undefined;
253
+ }
254
+ valueString() {
255
+ if (this.has_revision || this.isRange())
256
+ return "";
257
+ if (this.suffix !== undefined)
258
+ return this.suffix;
259
+ if (this.month !== undefined && this.year !== undefined)
260
+ return `${this.month}${this.year}`;
261
+ if (this.number !== undefined && this.year !== undefined)
262
+ return `${this.number}/${this.year}`;
263
+ if (this.year !== undefined)
264
+ return this.year;
265
+ if (this.number !== undefined)
266
+ return this.number;
267
+ return "";
268
+ }
269
+ render() {
270
+ if (this.number === undefined && this.year === undefined && this.month === undefined &&
271
+ !this.has_revision && this.suffix === undefined && this.month_end === undefined && this.year_end === undefined) {
272
+ return "";
273
+ }
274
+ if (this.has_revision)
275
+ return "suprev";
276
+ if (this.suffix !== undefined)
277
+ return `sup${this.suffix}`;
278
+ if (this.isRange())
279
+ return `sup${this.month ?? ""}${this.year}-${this.month_end ?? ""}${this.year_end}`;
280
+ if (this.month !== undefined && this.year !== undefined)
281
+ return `sup${this.month}${this.year}`;
282
+ if (this.number !== undefined && this.year !== undefined)
283
+ return `sup${this.number}/${this.year}`;
284
+ if (this.year !== undefined)
285
+ return `sup${this.year}`;
286
+ if (this.number !== undefined)
287
+ return `sup${this.number}`;
288
+ return "";
289
+ }
290
+ }
291
+ const LETTER_PRESERVING = {
292
+ preserveLetterSuffix: true,
293
+ modernEditionDate: false,
294
+ partNumAsComponent: false,
295
+ };
296
+ const BASE_POLICY = {
297
+ preserveLetterSuffix: false,
298
+ modernEditionDate: false,
299
+ partNumAsComponent: false,
300
+ };
301
+ const IR_POLICY = { ...LETTER_PRESERVING, partNumAsComponent: true };
302
+ const FIPS_POLICY = { ...LETTER_PRESERVING, modernEditionDate: true };
303
+ const SERIES_REGISTRY = [
304
+ ["LCIRC", LETTER_PRESERVING],
305
+ ["FIPS", FIPS_POLICY],
306
+ ["CRPL", LETTER_PRESERVING],
307
+ ["NCSTAR", BASE_POLICY],
308
+ ["MONO", LETTER_PRESERVING],
309
+ ["IR", IR_POLICY],
310
+ ["MP", LETTER_PRESERVING],
311
+ ["RPT", LETTER_PRESERVING],
312
+ ["LC", LETTER_PRESERVING],
313
+ ];
314
+ export function seriesPolicy(series) {
315
+ if (series === undefined)
316
+ return BASE_POLICY;
317
+ const up = series.toUpperCase();
318
+ for (const [code, policy] of SERIES_REGISTRY) {
319
+ if (up.includes(code))
320
+ return policy;
321
+ }
322
+ return BASE_POLICY;
323
+ }
324
+ // --- Identifier base ------------------------------------------------------------
325
+ const componentWire = (componentName) => [
326
+ {
327
+ wire: componentName,
328
+ to: componentName,
329
+ toWire: (m) => {
330
+ const value = m[componentName];
331
+ return value === undefined ? undefined : value.toWire();
332
+ },
333
+ fromWire: () => undefined,
334
+ },
335
+ ];
336
+ const scalarCode = (name, ctor) => ({
337
+ wire: name,
338
+ to: name,
339
+ toWire: (m) => m[name]?.value,
340
+ fromWire: (h) => {
341
+ const v = h[name];
342
+ return v === undefined || v === null ? undefined : new ctor({ value: v });
343
+ },
344
+ });
345
+ export class NistIdentifier extends BaseIdentifier {
346
+ static attributes = extendAttributes(BaseIdentifier, {
347
+ publisher: { type: "string" },
348
+ series: { type: NistCode },
349
+ subseries: { type: NistCode },
350
+ number: { type: "string" },
351
+ subpart: { type: "string" },
352
+ edition: { type: NistEdition },
353
+ volume: { type: NistVolume },
354
+ part: { type: NistPart },
355
+ stage: { type: NistStage },
356
+ version_component: { type: NistVersion },
357
+ update_component: { type: NistUpdate },
358
+ translation_component: { type: NistTranslation },
359
+ issue_number: { type: NistIssueNumber },
360
+ parsed_format: { type: "string" },
361
+ publisher_was_parsed: { type: "boolean", default: true },
362
+ parts: { type: "string", collection: true },
363
+ revision_year: { type: "string" },
364
+ revision_month: { type: "string" },
365
+ edition_year: { type: "string" },
366
+ version: { type: "string" },
367
+ update: { type: NistUpdate },
368
+ year: { type: "integer" },
369
+ month: { type: "integer" },
370
+ first_number: { type: "string" },
371
+ second_number: { type: "string" },
372
+ update_number: { type: "string" },
373
+ update_year: { type: "string" },
374
+ addendum: { type: "string" },
375
+ addendum_number: { type: "string" },
376
+ supplement: { type: NistSupplement },
377
+ errata: { type: "string" },
378
+ index: { type: "string" },
379
+ insert: { type: "string" },
380
+ section: { type: "string" },
381
+ appendix: { type: "string" },
382
+ translation: { type: "string" },
383
+ draft: { type: "string" },
384
+ draft_number: { type: "string" },
385
+ date_year: { type: "string" },
386
+ date_month: { type: "string" },
387
+ date_day: { type: "string" },
388
+ dated_seq: { type: "string" },
389
+ public_draft: { type: "string" },
390
+ });
391
+ static mappings = keyValue(scalarCode("series", NistCode), scalarCode("subseries", NistCode), { wire: "publisher", to: "publisher" }, {
392
+ wire: "number",
393
+ to: "number",
394
+ toWire: (m) => {
395
+ const v = m["number"];
396
+ if (typeof v === "string" &&
397
+ (/^\d+E-\d+$/.test(v) || /^[+-]?\d+(\.\d+)?[eE][+-]?\d+$/.test(v))) {
398
+ return Number(v);
399
+ }
400
+ return v;
401
+ },
402
+ fromWire: (h) => {
403
+ const v = h["number"];
404
+ if (v === undefined || v === null)
405
+ return undefined;
406
+ // A numeric value came from the exporter's YAML float coercion —
407
+ // keep it so the round trip stays idempotent.
408
+ return typeof v === "number" ? v : String(v);
409
+ },
410
+ }, { wire: "parsed_format", to: "parsed_format" }, { wire: "publisher_was_parsed", to: "publisher_was_parsed" }, ...componentWire("edition"), ...componentWire("part"), ...componentWire("supplement"), ...componentWire("stage"), ...componentWire("version_component"), ...componentWire("update_component"), ...componentWire("update"), ...componentWire("translation_component"), ...componentWire("issue_number"), {
411
+ wire: "volume",
412
+ to: "volume",
413
+ toWire: (m) => m["volume"]?.value,
414
+ fromWire: (h) => (h["volume"] === undefined || h["volume"] === null ? undefined : new NistVolume({ value: String(h["volume"]) })),
415
+ }, { wire: "section", to: "section" }, { wire: "index", to: "index" }, { wire: "insert", to: "insert" }, { wire: "appendix", to: "appendix" }, { wire: "errata", to: "errata" }, { wire: "addendum", to: "addendum" }, { wire: "translation", to: "translation" }, { wire: "edition_year", to: "edition_year" }, { wire: "dated_seq", to: "dated_seq" }, { wire: "date_year", to: "date_year" }, { wire: "date_month", to: "date_month" }, { wire: "date_day", to: "date_day" }, { wire: "revised_date", to: "revised_date" }, { wire: "range_notation", to: "range_notation" }, { wire: "prefix", to: "prefix" });
416
+ seriesCode() {
417
+ return undefined;
418
+ }
419
+ defaultPublisher() {
420
+ return "NIST";
421
+ }
422
+ revision() {
423
+ return this.edition !== undefined && this.edition.type !== undefined && this.edition.id !== undefined
424
+ ? `${this.edition.type}${this.edition.id}`
425
+ : undefined;
426
+ }
427
+ supplementShort() {
428
+ if (this.supplement === undefined)
429
+ return "";
430
+ const prefix = this.supplement.isRange() && this.number === undefined ? " " : "";
431
+ const rendered = this.supplement.render();
432
+ return prefix + (rendered === "" ? "sup" : rendered);
433
+ }
434
+ appendShortComponents(skipPart = false) {
435
+ let result = "";
436
+ const effectivePart = skipPart ? undefined : this.part;
437
+ if (this.volume !== undefined && effectivePart instanceof NistPart) {
438
+ result += ` ${this.volume.render()}${effectivePart.render()}`;
439
+ }
440
+ else if (effectivePart instanceof NistPart) {
441
+ result += effectivePart.render();
442
+ }
443
+ else if (this.volume !== undefined && this.issue_number === undefined && effectivePart === undefined) {
444
+ result += this.volume.render();
445
+ }
446
+ else if (this.volume !== undefined && this.issue_number !== undefined) {
447
+ result += `${this.volume.render()}n${this.issue_number.number}`;
448
+ }
449
+ if (this.edition !== undefined) {
450
+ if (this.edition.original_prefix !== undefined && this.edition.original_prefix !== "") {
451
+ result += this.edition.render();
452
+ }
453
+ else if (this.number !== undefined) {
454
+ result += this.edition.render();
455
+ }
456
+ else {
457
+ result += ` ${this.edition.render()}`;
458
+ }
459
+ }
460
+ if (this.version_component !== undefined) {
461
+ result += this.version_component.render();
462
+ }
463
+ else if (this.version !== undefined) {
464
+ result += `ver${this.version}`;
465
+ }
466
+ result += this.supplementShort();
467
+ if (this.errata !== undefined)
468
+ result += this.errata;
469
+ if (this.index !== undefined)
470
+ result += "index";
471
+ if (this.insert !== undefined)
472
+ result += "insert";
473
+ if (this.section !== undefined)
474
+ result += `sec${this.section}`;
475
+ if (this.appendix !== undefined)
476
+ result += "app";
477
+ if (this.addendum !== undefined || this.addendum_number !== undefined)
478
+ result += " Add.";
479
+ if (this.update_component !== undefined) {
480
+ result += this.update_component.render("short");
481
+ }
482
+ else if (this.update !== undefined) {
483
+ result += `-upd${this.update.number ?? ""}`;
484
+ }
485
+ if (this.draft_number !== undefined) {
486
+ result += ` ${this.draft_number}pd`;
487
+ }
488
+ else if (this.draft !== undefined && this.draft.includes("draft") && !this.draft.includes("Draft)")) {
489
+ result += "-draft";
490
+ }
491
+ if (this.stage !== undefined) {
492
+ const rendered = this.stage.render();
493
+ if (rendered !== "")
494
+ result += ` ${rendered}`;
495
+ }
496
+ if (this.translation_component !== undefined) {
497
+ result += this.translation_component.render("short");
498
+ }
499
+ else if (this.translation !== undefined) {
500
+ result += ` ${this.translation}`;
501
+ }
502
+ return result;
503
+ }
504
+ appendMrComponents(skipPart = false) {
505
+ let result = "";
506
+ const effectivePart = skipPart ? undefined : this.part;
507
+ if (this.volume !== undefined && effectivePart instanceof NistPart) {
508
+ result += `${this.volume.render()}${effectivePart.render()}`;
509
+ }
510
+ else if (effectivePart instanceof NistPart) {
511
+ result += effectivePart.render();
512
+ }
513
+ else if (this.volume !== undefined && this.issue_number === undefined && effectivePart === undefined) {
514
+ result += this.volume.render();
515
+ }
516
+ else if (this.volume !== undefined && this.issue_number !== undefined) {
517
+ result += `${this.volume.render()}n${this.issue_number.number}`;
518
+ }
519
+ if (this.edition !== undefined)
520
+ result += this.edition.render();
521
+ if (this.version_component !== undefined)
522
+ result += this.version_component.render();
523
+ result += this.supplementShort();
524
+ if (this.update_component !== undefined)
525
+ result += this.update_component.render("mr");
526
+ if (this.stage !== undefined) {
527
+ const rendered = this.stage.render();
528
+ if (rendered !== "")
529
+ result += `.${rendered}`;
530
+ }
531
+ if (this.addendum !== undefined || this.addendum_number !== undefined)
532
+ result += ".Add.";
533
+ if (this.translation_component !== undefined)
534
+ result += this.translation_component.render("mr");
535
+ return result;
536
+ }
537
+ effectiveSeries() {
538
+ return this.seriesCode() ?? this.series?.value;
539
+ }
540
+ shortRenderPublisher() {
541
+ return this.publisher !== undefined && this.publisher_was_parsed !== false ? this.publisher : undefined;
542
+ }
543
+ renderShort() {
544
+ let result = "";
545
+ const effectivePublisher = this.shortRenderPublisher();
546
+ const effectiveSeries = this.effectiveSeries();
547
+ if (effectiveSeries?.startsWith("NBS ") === true) {
548
+ result += effectiveSeries;
549
+ }
550
+ else if (effectivePublisher !== undefined && effectiveSeries !== undefined) {
551
+ result += `${effectivePublisher} ${effectiveSeries}`;
552
+ }
553
+ else if (effectiveSeries !== undefined && this.publisher_was_parsed === true) {
554
+ result += `NIST ${effectiveSeries}`;
555
+ }
556
+ else if (effectiveSeries !== undefined) {
557
+ result += effectiveSeries;
558
+ }
559
+ if (this.number !== undefined)
560
+ result += ` ${this.number}`;
561
+ if (this.parts !== undefined && this.parts.length > 0) {
562
+ result += this.parts.map((p) => `-${p}`).join("");
563
+ }
564
+ if (this.year !== undefined && this.number === undefined)
565
+ result += ` (${this.year})`;
566
+ result += this.appendShortComponents();
567
+ return result;
568
+ }
569
+ renderMr() {
570
+ let result = (this.publisher ?? "NIST").toString();
571
+ const effectiveSeries = this.effectiveSeries();
572
+ if (effectiveSeries !== undefined)
573
+ result += `.${effectiveSeries}`;
574
+ if (this.number !== undefined)
575
+ result += `.${this.number}`;
576
+ if (this.parts !== undefined && this.parts.length > 0) {
577
+ result += this.parts.map((p) => `-${p}`).join("");
578
+ }
579
+ result += this.appendMrComponents();
580
+ return result;
581
+ }
582
+ render() {
583
+ if (this.parsed_format === "mr")
584
+ return this.renderMr();
585
+ return this.renderShort();
586
+ }
587
+ }
588
+ class NistUrnGenerator extends BaseUrnGenerator {
589
+ generate() {
590
+ const id = this.identifier;
591
+ const parts = ["urn", "nist"];
592
+ const urnSeries = id.series?.value ?? id.seriesCode() ?? "sp";
593
+ parts.push(urnSeries.toLowerCase());
594
+ const identifierParts = [];
595
+ if (id.number !== undefined)
596
+ identifierParts.push(id.number);
597
+ if (id.parts !== undefined && id.parts.length > 0) {
598
+ identifierParts.push(...id.parts.map((p) => `-${p}`));
599
+ }
600
+ if (id.edition !== undefined)
601
+ identifierParts.push(id.edition.render());
602
+ if (id.volume !== undefined)
603
+ identifierParts.push(id.volume.render());
604
+ if (id.part instanceof NistPart)
605
+ identifierParts.push(id.part.render());
606
+ if (id.volume !== undefined && id.issue_number !== undefined) {
607
+ identifierParts.push(`${id.volume.render()}n${id.issue_number.number}`);
608
+ }
609
+ if (id.version_component !== undefined) {
610
+ identifierParts.push(id.version_component.render());
611
+ }
612
+ else if (id.version !== undefined) {
613
+ identifierParts.push(`ver.${id.version}`);
614
+ }
615
+ if (id.update_component !== undefined) {
616
+ identifierParts.push(id.update_component.render("short"));
617
+ }
618
+ else if (id.update !== undefined) {
619
+ identifierParts.push(`-upd${id.update.number ?? ""}`);
620
+ }
621
+ if (id.stage !== undefined) {
622
+ const rendered = id.stage.render();
623
+ if (rendered !== "")
624
+ identifierParts.push(rendered);
625
+ }
626
+ // The nil supplement still emits "supp" (quirk retained from Ruby).
627
+ const supp = id.supplement;
628
+ if (supp?.isRange() === true) {
629
+ identifierParts.push(`supp${supp.month ?? ""}${supp.year}-${supp.month_end ?? ""}${supp.year_end}`);
630
+ }
631
+ else if (supp?.has_revision === true) {
632
+ identifierParts.push("supprev");
633
+ }
634
+ else if (supp !== undefined && supp.valueString() !== "") {
635
+ const value = supp.valueString();
636
+ identifierParts.push(/^[A-Z]/.test(value) ? `supp${value}` : `supp-${value}`);
637
+ }
638
+ else if (supp === undefined) {
639
+ identifierParts.push("supp");
640
+ }
641
+ if (id.errata !== undefined)
642
+ identifierParts.push(id.errata);
643
+ if (id.addendum !== undefined || id.addendum_number !== undefined)
644
+ identifierParts.push("add.");
645
+ if (id.draft_number !== undefined) {
646
+ identifierParts.push(`${id.draft_number}pd`);
647
+ }
648
+ else if (id.draft !== undefined && id.draft.includes("draft")) {
649
+ identifierParts.push("-draft");
650
+ }
651
+ if (id.index !== undefined)
652
+ identifierParts.push("index");
653
+ if (id.insert !== undefined)
654
+ identifierParts.push("insert");
655
+ if (id.section !== undefined)
656
+ identifierParts.push(`sec${id.section}`);
657
+ if (id.appendix !== undefined)
658
+ identifierParts.push("app");
659
+ if (identifierParts.length > 0)
660
+ parts.push(identifierParts.join("."));
661
+ if (id.translation_component !== undefined) {
662
+ parts.push(id.translation_component.code.toLowerCase());
663
+ }
664
+ else if (id.translation !== undefined) {
665
+ parts.push(id.translation.toLowerCase());
666
+ }
667
+ return parts.join(":");
668
+ }
669
+ }
670
+ function nistClass(spec) {
671
+ class NistConcrete extends (spec.supplementSeam === true ? NistSupplementIdentifier : NistIdentifier) {
672
+ static polymorphicName = `pubid:nist:${spec.kind}`;
673
+ static urnGenerator = NistUrnGenerator;
674
+ seriesCode() {
675
+ return spec.seriesCode;
676
+ }
677
+ defaultPublisher() {
678
+ return spec.defaultPublisher ?? "NIST";
679
+ }
680
+ renderMr() {
681
+ if (spec.style === "fips") {
682
+ let result = this.seriesCode() ?? "";
683
+ if (this.number !== undefined)
684
+ result += `.${this.number}`;
685
+ if (this.part instanceof NistPart)
686
+ result += `-${this.part.value}`;
687
+ if (this.parts !== undefined && this.parts.length > 0) {
688
+ result += this.parts.map((p) => `-${p}`).join("");
689
+ }
690
+ result += this.appendMrComponents(true);
691
+ return result;
692
+ }
693
+ return super.renderMr();
694
+ }
695
+ renderShort() {
696
+ if (spec.kind === "dated-document") {
697
+ return `${this.publisher ?? "NIST"} ${this.date_year ?? ""}-${this.date_month ?? ""}-${this.date_day ?? ""} ${this.dated_seq ?? ""}`;
698
+ }
699
+ if (spec.style === "fips") {
700
+ let result = this.publisher !== undefined ? `${this.publisher} ` : "";
701
+ result += this.seriesCode() ?? "";
702
+ let numberPart = this.number ?? "";
703
+ const fy = /^(\d{1,3})-(\d{4})$/.exec(numberPart);
704
+ if (fy !== null) {
705
+ numberPart = `${fy[1]}e${fy[2]}`;
706
+ }
707
+ if (numberPart !== "")
708
+ result += ` ${numberPart}`;
709
+ if (this.part instanceof NistPart)
710
+ result += `-${this.part.value}`;
711
+ result += this.appendShortComponents(true);
712
+ return result;
713
+ }
714
+ let result = super.renderShort();
715
+ if (spec.style === "crpl") {
716
+ const seriesValue = this.series?.value ?? "";
717
+ const band = seriesValue.includes("CRPL-F-")
718
+ ? seriesValue.replace("NBS ", "")
719
+ : this.seriesCode();
720
+ result = `${this.defaultPublisher()} ${band}`;
721
+ let numValue = this.number ?? "";
722
+ if (/^c\d/.test(numValue))
723
+ numValue = numValue.slice(1);
724
+ numValue = numValue.replace(/-m-/, "-M-").replace(/^m-/, "M-");
725
+ if (this.number !== undefined) {
726
+ if (this.prefix !== undefined) {
727
+ result += ` ${this.prefix}`;
728
+ }
729
+ result += ` ${numValue}`;
730
+ }
731
+ result += this.appendShortComponents();
732
+ }
733
+ return result;
734
+ }
735
+ shortRenderPublisher() {
736
+ if (spec.shortUsesDefaultPublisher === true)
737
+ return this.defaultPublisher();
738
+ return super.shortRenderPublisher();
739
+ }
740
+ render() {
741
+ if (spec.supplementSeam === true) {
742
+ return NistSupplementIdentifier.prototype.render.call(this);
743
+ }
744
+ // Ruby classes whose to_s defaults to :short render that way even
745
+ // for mr-parsed input.
746
+ let rendered = this.parsed_format === "mr" && !spec.forceShort ? this.renderMr() : this.renderShort();
747
+ // Handbook rewrites "e2.1955" to "e2-1955".
748
+ if (spec.seriesCode === "HB" &&
749
+ this.edition !== undefined &&
750
+ this.edition.additional_text !== undefined &&
751
+ this.edition.additional_text !== "" &&
752
+ this.edition.type !== undefined &&
753
+ this.edition.id !== undefined) {
754
+ const from = `${this.edition.type}${this.edition.id}.${this.edition.additional_text}`;
755
+ const to = `${this.edition.type}${this.edition.id}-${this.edition.additional_text}`;
756
+ rendered = rendered.split(from).join(to);
757
+ }
758
+ return rendered;
759
+ }
760
+ }
761
+ registerType(NistConcrete);
762
+ return NistConcrete;
763
+ }
764
+ export class NistSupplementIdentifier extends NistIdentifier {
765
+ static attributes = extendAttributes(NistIdentifier, {
766
+ base: { type: NistIdentifier },
767
+ supplement_date_range_start: { type: "string" },
768
+ supplement_date_range_end: { type: "string" },
769
+ implicit_supplement: { type: "boolean" },
770
+ });
771
+ render() {
772
+ if (this.supplement_date_range_start !== undefined && this.supplement_date_range_end !== undefined) {
773
+ return `NBS CIRC sup${this.supplement_date_range_start}-${this.supplement_date_range_end}`;
774
+ }
775
+ const base = this.base;
776
+ if (base === undefined)
777
+ return super.render();
778
+ let result = base.toHuman();
779
+ if (this.update !== undefined) {
780
+ const isImplicit = this.implicit_supplement === true;
781
+ if (!isImplicit)
782
+ result += "sup";
783
+ result += this.update.render("short");
784
+ return result;
785
+ }
786
+ result += "sup";
787
+ if (this.edition?.id !== undefined) {
788
+ result += /^[A-Z]/.test(this.edition.id) ? this.edition.id : `-${this.edition.id}`;
789
+ }
790
+ return result;
791
+ }
792
+ }
793
+ const TYPE_SPECS = [
794
+ { kind: "special-publication", seriesCode: "SP" },
795
+ { kind: "federal-information-processing-standards", seriesCode: "FIPS", defaultPublisher: "", style: "fips" },
796
+ { kind: "interagency-report", seriesCode: "IR", forceShort: true },
797
+ { kind: "handbook", seriesCode: "HB" },
798
+ { kind: "technical-note", seriesCode: "TN" },
799
+ { kind: "circular", seriesCode: "CIRC", defaultPublisher: "NBS" },
800
+ { kind: "circular-supplement", seriesCode: "CIRC", defaultPublisher: "NBS", supplementSeam: true },
801
+ { kind: "crpl-report", seriesCode: "CRPL", defaultPublisher: "NBS", style: "crpl", forceShort: true },
802
+ { kind: "report", seriesCode: "RPT", defaultPublisher: "NBS", forceShort: true, shortUsesDefaultPublisher: true },
803
+ { kind: "monograph", seriesCode: "MONO", forceShort: true },
804
+ {
805
+ kind: "miscellaneous-publication", seriesCode: "MP", defaultPublisher: "NBS",
806
+ forceShort: true, shortUsesDefaultPublisher: true,
807
+ },
808
+ { kind: "grant-contractor-report", seriesCode: "GCR" },
809
+ { kind: "ncstar", seriesCode: "NCSTAR" },
810
+ { kind: "owmwp", seriesCode: "OWMWP" },
811
+ { kind: "nsrds", seriesCode: "NSRDS", defaultPublisher: "NBS" },
812
+ { kind: "letter-circular", seriesCode: "LC", defaultPublisher: "NBS" },
813
+ { kind: "commercial-standard", seriesCode: "CS", defaultPublisher: "NBS" },
814
+ { kind: "commercial-standard-emergency", seriesCode: "CS-E" },
815
+ { kind: "commercial-standards-monthly", seriesCode: "CSM", defaultPublisher: "NBS", forceShort: true },
816
+ { kind: "dated-document" },
817
+ { kind: "identifier" },
818
+ ];
819
+ export const NIST_CLASSES = new Map(TYPE_SPECS.map((spec) => [spec.kind, nistClass(spec)]));
820
+ export const SP_SUBSERIES = [
821
+ "250", "260", "300", "400", "480", "500", "700", "800", "823", "960",
822
+ "1190GB", "1200", "1500", "1800", "1900", "2000", "2100",
823
+ ];