@pubid/pubid 0.1.3 → 0.1.5

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 (185) 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 +31 -0
  80. package/dist/flavors/gb/index.js +159 -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 +697 -0
  107. package/dist/flavors/ieee/index.d.ts +3 -0
  108. package/dist/flavors/ieee/index.js +1258 -0
  109. package/dist/flavors/ieee/model.d.ts +144 -0
  110. package/dist/flavors/ieee/model.js +1237 -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 +197 -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 +206 -0
  155. package/dist/flavors/oiml/implementation.d.ts +9 -0
  156. package/dist/flavors/oiml/implementation.js +45 -0
  157. package/dist/flavors/oiml/model.d.ts +23 -0
  158. package/dist/flavors/oiml/model.js +592 -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/index.d.ts +1 -0
  174. package/dist/index.js +3 -0
  175. package/dist/model/attribute.d.ts +54 -0
  176. package/dist/model/attribute.js +53 -0
  177. package/dist/model/builder.d.ts +39 -0
  178. package/dist/model/builder.js +124 -0
  179. package/dist/model/component.d.ts +70 -0
  180. package/dist/model/component.js +170 -0
  181. package/dist/model/identifier.d.ts +84 -0
  182. package/dist/model/identifier.js +270 -0
  183. package/dist/model/urn-generator.d.ts +27 -0
  184. package/dist/model/urn-generator.js +91 -0
  185. package/package.json +1 -1
@@ -0,0 +1,71 @@
1
+ import { match, ref, str } from "../../grammar/engine.js";
2
+ /**
3
+ * Port of lib/pubid/idf/parser.rb — 1:1. Root: supplement_identifier |
4
+ * identifier_publisher.
5
+ */
6
+ const IS_ABBRS = [
7
+ "PWI", "NP", "NWIP", "AWI", "WD", "CD", "FCD", "DIS", "FPD", "FDIS",
8
+ "PRF", "Fpr", "WDR", "WDA", "WDAR",
9
+ ];
10
+ const RM_ABBRS = [
11
+ "PWI RM", "NP RM", "AWI RM", "WD RM", "CD RM", "PDRM", "DRM", "FDRM",
12
+ "PRF RM", "RM",
13
+ ];
14
+ const SUPPLEMENT_ABBRS = ["AMD", "COR"];
15
+ function abbrAlternation(tokens) {
16
+ const sorted = [...new Set(tokens)].sort((a, b) => b.length - a.length);
17
+ return sorted.map((t) => str(t)).reduce((a, b) => a.or(b));
18
+ }
19
+ function buildRules() {
20
+ const rules = {};
21
+ const rule = (name, build) => {
22
+ rules[name] = build();
23
+ };
24
+ const space = str(" ");
25
+ const dash = str("-").or(str("‑")).or(str("‐"));
26
+ const word = match("\\w");
27
+ const digit = match("\\d");
28
+ const digits = digit.repeat(1, Infinity);
29
+ rule("prefix_sole_publisher", () => str("IDF").as("publisher"));
30
+ rule("number", () => word.repeat(1, 5));
31
+ rule("date", () => digits
32
+ .then(dash.then(digit.repeat(2, 2)).maybe())
33
+ .then(dash.then(digit.repeat(2, 2)).maybe())
34
+ .as("date"));
35
+ rule("part_and_subpart", () => dash.then(space.maybe())
36
+ .then(word.repeat(0, Infinity))
37
+ .then(dash.then(word.repeat(0, Infinity)).repeat(0, Infinity).maybe()));
38
+ rule("number_with_part", () => ref(rules, "number").then(ref(rules, "part_and_subpart").maybe()).as("number_with_part"));
39
+ rule("all_parts", () => str("(all parts)").as("all_parts"));
40
+ rule("type_with_stage", () => abbrAlternation([...IS_ABBRS, ...RM_ABBRS]).as("type_with_stage")
41
+ .then(digit.as("stage_iteration").then(space).maybe()));
42
+ rule("language", () => str("(")
43
+ .then((match("[a-z]").repeat(1, Infinity).then(str(",").maybe())).or(match("[EFARDS]").then(str("/").maybe())).repeat(0, Infinity).as("languages"))
44
+ .then(str(")")));
45
+ rule("stage_iteration", () => str(".").then(digit.as("stage_iteration")));
46
+ rule("second_part", () => ref(rules, "number_with_part")
47
+ .then(ref(rules, "stage_iteration").maybe())
48
+ .then(space.maybe())
49
+ .then(str(":").then(ref(rules, "date")).maybe()));
50
+ rule("third_part", () => space.maybe().then(ref(rules, "language").maybe()).then(ref(rules, "all_parts").maybe()));
51
+ rule("identifier_publisher_no_third", () => ref(rules, "prefix_sole_publisher")
52
+ .then(space.maybe())
53
+ .then(str("/").maybe())
54
+ .then(ref(rules, "type_with_stage").maybe())
55
+ .then(space.maybe())
56
+ .then(ref(rules, "second_part")));
57
+ rule("identifier_publisher", () => ref(rules, "identifier_publisher_no_third").then(ref(rules, "third_part")));
58
+ rule("supplement_type_with_stage", () => abbrAlternation(SUPPLEMENT_ABBRS).as("type_with_stage"));
59
+ rule("supplement_identifier_no_third", () => ref(rules, "identifier_publisher_no_third").as("base")
60
+ .then(space.maybe().then(str("/")).then(space.maybe()))
61
+ .then(ref(rules, "supplement_type_with_stage"))
62
+ .then(space.maybe())
63
+ .then(ref(rules, "second_part")));
64
+ rule("supplement_identifier", () => ref(rules, "supplement_identifier_no_third").then(ref(rules, "third_part")));
65
+ rule("identifier", () => ref(rules, "supplement_identifier").or(ref(rules, "identifier_publisher")));
66
+ return rules;
67
+ }
68
+ export const idfGrammar = {
69
+ rules: buildRules(),
70
+ root: "identifier",
71
+ };
@@ -0,0 +1,2 @@
1
+ import type { FlavorImplementation } from "../../conformance/implementation.js";
2
+ export declare function idfGrammarImplementation(): FlavorImplementation;
@@ -0,0 +1,100 @@
1
+ import { parseGrammar } from "../../grammar/engine.js";
2
+ import { idfGrammar } from "./grammar.js";
3
+ import { AmendmentClass, CorrigendumClass, IDF_TYPE_CLASSES, IdfTypedStageComponent, InternationalStandardClass, locateStage, } from "./model.js";
4
+ import { Language, PubidDate } from "../../model/component.js";
5
+ /**
6
+ * Port of lib/pubid/idf/builder.rb — stage lookup, number/part split,
7
+ * language mapping, supplement wrapping.
8
+ */
9
+ const isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
10
+ const str = (v) => {
11
+ if (v === undefined || v === null)
12
+ return undefined;
13
+ const s = String(v);
14
+ return s.length > 0 ? s : undefined;
15
+ };
16
+ const LANG_CHAR_MAP = {
17
+ R: "ru", F: "fr", E: "en", A: "ar", S: "es", D: "de",
18
+ };
19
+ function buildIdentifier(tree) {
20
+ const d = Array.isArray(tree) ? Object.assign({}, ...tree) : tree;
21
+ return buildFrom(d);
22
+ }
23
+ function buildFrom(d) {
24
+ if (d["base"] !== undefined) {
25
+ const base = buildFrom(d["base"]);
26
+ const attrs = assignAttributes(d);
27
+ const typedStage = locateStage(str(d["type_with_stage"]) ?? "AMD");
28
+ const isCor = typedStage?.type_code === "cor";
29
+ const klass = (isCor ? CorrigendumClass : AmendmentClass);
30
+ // The supplement's wire "year" is its DATE flattened by the shared
31
+ // scalar flattener; nothing else changes.
32
+ return new klass({ ...attrs, base, typedStage: typedStage === undefined ? undefined : new IdfTypedStageComponent(typedStage) });
33
+ }
34
+ const rawStage = str(d["type_with_stage"]);
35
+ const stageIteration = str(d["stage_iteration"]);
36
+ // The stage abbr may carry a trailing iteration digit in the capture.
37
+ let stageAbbr = rawStage;
38
+ let iteration = stageIteration;
39
+ if (rawStage !== undefined && iteration === undefined && /\d$/.test(rawStage) && !/\b(RM|FDIS|DIS|COR|AMD)\b/.test(rawStage)) {
40
+ const m = /(\d+)$/.exec(rawStage);
41
+ if (m !== null) {
42
+ stageAbbr = rawStage.slice(0, -(m[1] ?? "").length);
43
+ iteration = m[1];
44
+ }
45
+ }
46
+ const typedStage = locateStage(stageAbbr ?? "");
47
+ const typeCode = typedStage?.type_code ?? "is";
48
+ const klass = (IDF_TYPE_CLASSES[typeCode] ?? InternationalStandardClass);
49
+ const attrs = assignAttributes(d);
50
+ return new klass({
51
+ ...attrs,
52
+ ...(iteration !== undefined ? { stageIteration: iteration } : {}),
53
+ ...(typedStage !== undefined ? { typedStage: new IdfTypedStageComponent(typedStage) } : {}),
54
+ });
55
+ }
56
+ function assignAttributes(d) {
57
+ const attrs = {};
58
+ if (d["number_with_part"] !== undefined) {
59
+ const value = String(Array.isArray(d["number_with_part"])
60
+ ? d["number_with_part"].join("")
61
+ : d["number_with_part"]);
62
+ const parts = value.split("-");
63
+ attrs["number"] = parts.shift();
64
+ const part = parts.shift();
65
+ if (part !== undefined && part !== "")
66
+ attrs["part"] = part;
67
+ if (parts.length > 0)
68
+ attrs["subpart"] = parts.join("-");
69
+ }
70
+ if (d["date"] !== undefined) {
71
+ const value = String(Array.isArray(d["date"]) ? d["date"].join("") : d["date"]);
72
+ if (/^\d{4}(-\d{2})?$/.test(value)) {
73
+ const [year, month] = value.split("-");
74
+ attrs["date"] = new PubidDate(month !== undefined ? { year, month } : { year });
75
+ }
76
+ }
77
+ if (d["languages"] !== undefined) {
78
+ const raw = String(d["languages"]).replaceAll("/", ",");
79
+ attrs["languages"] = raw
80
+ .split(",")
81
+ .map((lang) => lang.trim())
82
+ .filter((lang) => lang !== "")
83
+ .map((lang) => new Language({ code: LANG_CHAR_MAP[lang] ?? lang }));
84
+ }
85
+ if (d["all_parts"] !== undefined) {
86
+ attrs["all_parts"] = true;
87
+ }
88
+ if (isObj(d["base"])) {
89
+ // Supplement attrs handled by caller; number/date already read above.
90
+ }
91
+ return attrs;
92
+ }
93
+ export function idfGrammarImplementation() {
94
+ return {
95
+ parse(input) {
96
+ const tree = parseGrammar(idfGrammar, input);
97
+ return buildIdentifier(tree);
98
+ },
99
+ };
100
+ }
@@ -0,0 +1,54 @@
1
+ import { BaseIdentifier } from "../../model/identifier.js";
2
+ import type { IdentifierStatic } from "../../model/identifier.js";
3
+ import { type AttributeTable, type FieldMapping } from "../../model/attribute.js";
4
+ import { Language, PubidDate } from "../../model/component.js";
5
+ /**
6
+ * Port of lib/pubid/idf: the typed-stage registry (is/rm/amd/cor), the
7
+ * nested Type/Stage/TypedStage wire objects, supplements carrying a base,
8
+ * the renderer and the URN generator.
9
+ */
10
+ export interface IdfTypedStage {
11
+ name: string;
12
+ code: string;
13
+ type_code: string;
14
+ stage_code?: string;
15
+ abbr: string[];
16
+ harmonized_stages?: string[];
17
+ short_abbr?: string;
18
+ long_abbr?: string;
19
+ }
20
+ export declare const IS_STAGES: IdfTypedStage[];
21
+ export declare const RM_STAGES: IdfTypedStage[];
22
+ export declare const AMD_STAGE: IdfTypedStage;
23
+ export declare const COR_STAGE: IdfTypedStage;
24
+ export declare function locateStage(abbr: string): IdfTypedStage | undefined;
25
+ export declare function locateStageByTypeCode(typeCode: string): IdfTypedStage | undefined;
26
+ export declare class IdfTypedStageComponent {
27
+ readonly record: IdfTypedStage;
28
+ constructor(record: IdfTypedStage);
29
+ get abbrFirst(): string;
30
+ /** abbreviation: short/long override else abbr[0]. */
31
+ abbreviation(formatLong?: boolean): string;
32
+ typeWire(): Record<string, unknown>;
33
+ stageWire(): Record<string, unknown>;
34
+ toWire(): Record<string, unknown>;
35
+ static fromWire(hash: Record<string, unknown>): IdfTypedStageComponent | undefined;
36
+ }
37
+ export declare abstract class IdfIdentifier extends BaseIdentifier {
38
+ static attributes: AttributeTable;
39
+ static mappings: FieldMapping[];
40
+ readonly publisherBody: string;
41
+ readonly number: string | undefined;
42
+ readonly part: string | undefined;
43
+ readonly subpart: string | undefined;
44
+ readonly date: PubidDate | undefined;
45
+ readonly languages: Language[] | undefined;
46
+ readonly all_parts: boolean | undefined;
47
+ root(): IdfIdentifier;
48
+ }
49
+ export declare const InternationalStandardClass: IdentifierStatic;
50
+ export declare const ReviewedMethodClass: IdentifierStatic;
51
+ export declare const AmendmentClass: IdentifierStatic;
52
+ export declare const CorrigendumClass: IdentifierStatic;
53
+ export declare const IDF_TYPE_CLASSES: Record<string, IdentifierStatic>;
54
+ export declare const IDF_ATTRIBUTES: AttributeTable;
@@ -0,0 +1,359 @@
1
+ import { BaseIdentifier, registerType } from "../../model/identifier.js";
2
+ import { extendAttributes, keyValue } from "../../model/attribute.js";
3
+ import { Language, PubidDate } from "../../model/component.js";
4
+ import { BaseUrnGenerator } from "../../model/urn-generator.js";
5
+ export const IS_STAGES = [
6
+ { name: "Proposed Work Item for International Standard", code: "pwiis", type_code: "is", stage_code: "pwi", abbr: ["PWI"], harmonized_stages: ["00.00", "00.20", "00.60", "00.92", "00.93", "00.98", "00.99"] },
7
+ { name: "New Work Item Proposal for International Standard", code: "isnp", type_code: "is", stage_code: "np", abbr: ["NP", "NWIP"], harmonized_stages: ["10.00", "10.20", "10.60", "10.92", "10.93", "10.98"] },
8
+ { name: "Approved Work Item for International Standard", code: "awiis", type_code: "is", stage_code: "awi", abbr: ["AWI"], harmonized_stages: ["10.99", "20.00"] },
9
+ { name: "Working Draft for International Standard", code: "wdis", type_code: "is", stage_code: "wd", abbr: ["WD"], harmonized_stages: ["20.20", "20.60", "20.92", "20.93", "20.98", "20.99"] },
10
+ { name: "Committee Draft for International Standard", code: "cdis", type_code: "is", stage_code: "cd", abbr: ["CD"], harmonized_stages: ["30.00", "30.20", "30.60", "30.92", "30.93", "30.98", "30.99"] },
11
+ { name: "Final Committee Draft for International Standard", code: "fcdis", type_code: "is", stage_code: "fcd", abbr: ["FCD"], harmonized_stages: ["30.00", "30.20", "30.60", "30.92", "30.93", "30.98", "30.99"] },
12
+ { name: "Draft International Standard", code: "dis", type_code: "is", stage_code: "dis", abbr: ["DIS", "FPD"], harmonized_stages: ["40.00", "40.20", "40.60", "40.92", "40.93", "40.98", "40.99"] },
13
+ { name: "Final Draft International Standard", code: "fdis", type_code: "is", stage_code: "fdis", abbr: ["FDIS"], harmonized_stages: ["50.00", "50.20", "50.60", "50.92", "50.98", "50.99"] },
14
+ { name: "Proof International Standard", code: "prfis", type_code: "is", stage_code: "prf", abbr: ["PRF", "Fpr"], harmonized_stages: ["60.00"] },
15
+ { name: "International Standard", code: "is", type_code: "is", stage_code: "published", abbr: [""], harmonized_stages: ["60.00", "60.60"] },
16
+ { name: "Proposed for Withdrawal", code: "wdr", type_code: "is", stage_code: "wdr", abbr: ["WDR"], harmonized_stages: ["90.92"] },
17
+ { name: "Withdrawal Approved", code: "wda", type_code: "is", stage_code: "wda", abbr: ["WDA"], harmonized_stages: ["90.93"] },
18
+ { name: "Withdrawal Archived", code: "wdar", type_code: "is", stage_code: "wdar", abbr: ["WDAR"], harmonized_stages: ["95.99"] },
19
+ ];
20
+ export const RM_STAGES = [
21
+ { name: "Proposed Work Item for Reviewed Method", code: "pwirm", type_code: "rm", stage_code: "pwi", abbr: ["PWI RM"], harmonized_stages: ["00.00", "00.20", "00.60", "00.92", "00.93", "00.98", "00.99"] },
22
+ { name: "New Work Item Proposal for Reviewed Method", code: "nprm", type_code: "rm", stage_code: "np", abbr: ["NP RM"], harmonized_stages: ["10.00", "10.20", "10.60", "10.92", "10.93", "10.98"] },
23
+ { name: "Approved Work Item for Reviewed Method", code: "awirm", type_code: "rm", stage_code: "awi", abbr: ["AWI RM"], harmonized_stages: ["10.99", "20.00"] },
24
+ { name: "Working Draft Reviewed Method", code: "wdrm", type_code: "rm", stage_code: "wd", abbr: ["WD RM"], harmonized_stages: ["20.20", "20.60", "20.92", "20.93", "20.98", "20.99"] },
25
+ { name: "Committee Draft Reviewed Method", code: "cdrm", type_code: "rm", stage_code: "cd", abbr: ["CD RM"], harmonized_stages: ["30.00", "30.20", "30.60", "30.92", "30.93", "30.98", "30.99"] },
26
+ { name: "Proposed Draft Reviewed Method", code: "pdrm", type_code: "rm", stage_code: "cd", abbr: ["PDRM"], harmonized_stages: ["30.00", "30.20", "30.60", "30.92", "30.93", "30.98", "30.99"] },
27
+ { name: "Draft Reviewed Method", code: "drm", type_code: "rm", abbr: ["DRM"], harmonized_stages: ["40.00", "40.20", "40.60", "40.92", "40.93", "40.98", "40.99"] },
28
+ { name: "Final Draft Reviewed Method", code: "fdrm", type_code: "rm", abbr: ["FDRM"], harmonized_stages: ["50.00", "50.20", "50.60", "50.92", "50.98", "50.99"] },
29
+ { name: "Proof Reviewed Method", code: "prfrm", type_code: "rm", stage_code: "prf", abbr: ["PRF RM"], harmonized_stages: ["50.00", "50.20", "50.60", "50.92", "50.98", "50.99"] },
30
+ { name: "Published Reviewed Method", code: "pubrm", type_code: "rm", stage_code: "published", abbr: ["RM"], harmonized_stages: ["60.00", "60.60"] },
31
+ ];
32
+ export const AMD_STAGE = {
33
+ name: "Amendment", code: "published", type_code: "amd", stage_code: "published",
34
+ abbr: ["AMD"], short_abbr: "AMD", long_abbr: "AMD",
35
+ };
36
+ export const COR_STAGE = {
37
+ name: "Corrigendum", code: "published", type_code: "cor", stage_code: "published",
38
+ abbr: ["COR"], short_abbr: "COR", long_abbr: "COR",
39
+ };
40
+ const ALL_STAGES = [...IS_STAGES, ...RM_STAGES, AMD_STAGE, COR_STAGE];
41
+ export function locateStage(abbr) {
42
+ const needle = abbr.trim();
43
+ if (needle === "")
44
+ return IS_STAGES.find((s) => s.code === "is");
45
+ return ALL_STAGES.find((s) => s.abbr.some((a) => a === needle));
46
+ }
47
+ export function locateStageByTypeCode(typeCode) {
48
+ return ALL_STAGES.find((s) => s.type_code === typeCode && s.stage_code === "published")
49
+ ?? ALL_STAGES.find((s) => s.type_code === typeCode);
50
+ }
51
+ // --- Wire shapes -------------------------------------------------------------------
52
+ export class IdfTypedStageComponent {
53
+ record;
54
+ constructor(record) {
55
+ this.record = record;
56
+ }
57
+ get abbrFirst() {
58
+ return this.record.abbr[0] ?? "";
59
+ }
60
+ /** abbreviation: short/long override else abbr[0]. */
61
+ abbreviation(formatLong = true) {
62
+ if (formatLong && this.record.long_abbr !== undefined)
63
+ return this.record.long_abbr;
64
+ if (!formatLong && this.record.short_abbr !== undefined)
65
+ return this.record.short_abbr;
66
+ return this.abbrFirst;
67
+ }
68
+ typeWire() {
69
+ const out = { name: this.record.name, type_code: this.record.type_code };
70
+ if (this.abbrFirst !== "")
71
+ out["abbr"] = this.abbrFirst;
72
+ return out;
73
+ }
74
+ stageWire() {
75
+ const out = { name: this.record.name };
76
+ if (this.record.stage_code !== undefined)
77
+ out["stage_code"] = this.record.stage_code;
78
+ if (this.abbrFirst !== "")
79
+ out["abbr"] = this.abbrFirst;
80
+ if (this.record.harmonized_stages !== undefined)
81
+ out["harmonized_stages"] = this.record.harmonized_stages;
82
+ return out;
83
+ }
84
+ toWire() {
85
+ const out = {
86
+ name: this.record.name,
87
+ code: this.record.code,
88
+ type_code: this.record.type_code,
89
+ ...(this.record.stage_code !== undefined ? { stage_code: this.record.stage_code } : {}),
90
+ abbr: this.record.abbr,
91
+ };
92
+ if (this.record.harmonized_stages !== undefined)
93
+ out["harmonized_stages"] = this.record.harmonized_stages;
94
+ if (this.record.short_abbr !== undefined)
95
+ out["short_abbr"] = this.record.short_abbr;
96
+ if (this.record.long_abbr !== undefined)
97
+ out["long_abbr"] = this.record.long_abbr;
98
+ return out;
99
+ }
100
+ static fromWire(hash) {
101
+ const abbr = Array.isArray(hash["abbr"]) ? hash["abbr"].map(String) : [];
102
+ const match = ALL_STAGES.find((s) => s.abbr.length === abbr.length && s.abbr.every((a, i) => a === abbr[i]) && s.code === hash["code"]);
103
+ return match === undefined ? undefined : new IdfTypedStageComponent(match);
104
+ }
105
+ }
106
+ const publisherWire = {
107
+ wire: "publisher",
108
+ to: "publisherBody",
109
+ toWire: (model) => {
110
+ const body = model["publisherBody"];
111
+ return body === undefined ? undefined : { body };
112
+ },
113
+ fromWire: (hash) => {
114
+ const value = hash["publisher"];
115
+ if (value === undefined || typeof value !== "object")
116
+ return undefined;
117
+ return String(value["body"] ?? "");
118
+ },
119
+ };
120
+ const typedStageObjWire = {
121
+ wire: "typed_stage",
122
+ to: "typedStage",
123
+ toWire: (model) => {
124
+ const stage = model["typedStage"];
125
+ return stage instanceof IdfTypedStageComponent ? stage.toWire() : undefined;
126
+ },
127
+ fromWire: (hash) => {
128
+ const value = hash["typed_stage"];
129
+ if (value === undefined || typeof value !== "object" || Array.isArray(value))
130
+ return undefined;
131
+ return IdfTypedStageComponent.fromWire(value);
132
+ },
133
+ };
134
+ // --- The identifier base --------------------------------------------------------
135
+ export class IdfIdentifier extends BaseIdentifier {
136
+ static attributes = extendAttributes(BaseIdentifier, {
137
+ publisherBody: { type: "string" },
138
+ number: { type: "string" },
139
+ part: { type: "string" },
140
+ subpart: { type: "string" },
141
+ date: { type: PubidDate },
142
+ languages: { type: Language, collection: true },
143
+ all_parts: { type: "boolean", default: false },
144
+ });
145
+ static mappings = keyValue(publisherWire, { wire: "number", to: "number" }, { wire: "part", to: "part" }, { wire: "subpart", to: "subpart" }, {
146
+ wire: "date",
147
+ to: "date",
148
+ toWire: (model) => {
149
+ const date = model["date"];
150
+ if (date === undefined)
151
+ return undefined;
152
+ if (date.month === undefined)
153
+ return { year: date.year };
154
+ return { year: date.year, month: date.month };
155
+ },
156
+ fromWire: (hash) => {
157
+ const nested = hash["date"];
158
+ if (nested !== undefined && typeof nested === "object" && nested !== null) {
159
+ const rec = nested;
160
+ return new PubidDate({ year: rec["year"], month: rec["month"] });
161
+ }
162
+ const year = hash["year"];
163
+ if (typeof year === "string" && year !== "")
164
+ return new PubidDate({ year });
165
+ return undefined;
166
+ },
167
+ }, { wire: "languages", to: "languages" }, { wire: "all_parts", to: "all_parts" });
168
+ root() {
169
+ return this;
170
+ }
171
+ }
172
+ function languagePortion(id) {
173
+ if (id.languages === undefined || id.languages.length === 0)
174
+ return "";
175
+ return `(${id.languages.map((l) => l.code).join(",")})`;
176
+ }
177
+ function numberPortion(id) {
178
+ const self = id;
179
+ const iter = self["stageIteration"];
180
+ return [
181
+ id.number !== undefined ? ` ${id.number}` : "",
182
+ id.part !== undefined ? `-${id.part}` : "",
183
+ id.subpart !== undefined ? `-${id.subpart}` : "",
184
+ iter !== undefined ? `.${iter}` : "",
185
+ id.date?.present() ? `:${id.date.render()}` : "",
186
+ languagePortion(id),
187
+ ].join("");
188
+ }
189
+ function renderSingle(id) {
190
+ const stage = id["typedStage"];
191
+ const abbr = stage === undefined ? "" : stage.abbreviation();
192
+ return ["IDF", abbr === "" ? "" : `/${abbr}`].join("") + numberPortion(id);
193
+ }
194
+ // --- URN generator ---------------------------------------------------------------
195
+ class IdfUrnGenerator extends BaseUrnGenerator {
196
+ generate() {
197
+ const id = this.identifier;
198
+ const self = id;
199
+ const stage = self["typedStage"];
200
+ const typeAbbr = stage === undefined ? "" : stage.abbrFirst;
201
+ const parts = ["urn", "idf"];
202
+ if (id.number !== undefined)
203
+ parts.push(id.number);
204
+ // The URN keeps each part's leading dash (UrnGenerator::Base urn_part).
205
+ if (id.part !== undefined)
206
+ parts.push(`-${id.part}`);
207
+ if (id.subpart !== undefined)
208
+ parts.push(`-${id.subpart}`);
209
+ if (id.date?.year !== undefined)
210
+ parts.push(id.date.year);
211
+ // urn_type: the type abbreviation lowercased, "" when absent (the
212
+ // published IS keeps an empty trailing segment).
213
+ parts.push(typeAbbr.toLowerCase());
214
+ if (id.languages !== undefined && id.languages.length > 0) {
215
+ parts.push(id.languages.map((l) => l.code).join(","));
216
+ }
217
+ if (self["base"] !== undefined) {
218
+ if (stage !== undefined)
219
+ parts.push(stage.record.type_code);
220
+ if (id.number !== undefined)
221
+ parts.push(id.number);
222
+ }
223
+ return parts.join(":");
224
+ }
225
+ }
226
+ function documentClass(spec) {
227
+ class IdfConcrete extends IdfIdentifier {
228
+ static polymorphicName = `pubid:idf:${spec.kind}`;
229
+ static urnGenerator = IdfUrnGenerator;
230
+ static get attributes() {
231
+ return extendAttributes(IdfIdentifier, {
232
+ typedStage: { type: "string" },
233
+ });
234
+ }
235
+ static get mappings() {
236
+ const stage = locateStageByTypeCode(spec.typeCode);
237
+ return [
238
+ ...IdfIdentifier.mappings,
239
+ {
240
+ wire: "type",
241
+ to: "typedStage",
242
+ toWire: (model) => {
243
+ const s = model["typedStage"];
244
+ return s instanceof IdfTypedStageComponent ? s.typeWire() : undefined;
245
+ },
246
+ fromWire: () => undefined,
247
+ },
248
+ {
249
+ wire: "stage",
250
+ to: "typedStage",
251
+ toWire: (model) => {
252
+ const s = model["typedStage"];
253
+ return s instanceof IdfTypedStageComponent ? s.stageWire() : undefined;
254
+ },
255
+ fromWire: () => undefined,
256
+ },
257
+ typedStageObjWire,
258
+ ];
259
+ }
260
+ constructor(attrs = {}) {
261
+ super(attrs);
262
+ const self = this;
263
+ // The publisher body defaults to IDF on the instance (NOT via a
264
+ // spec default — a default-equal scalar would drop off the wire,
265
+ // but the nested publisher object always serializes).
266
+ if (self["publisherBody"] === undefined)
267
+ self["publisherBody"] = "IDF";
268
+ if (self["typedStage"] === undefined) {
269
+ self["typedStage"] = new IdfTypedStageComponent(locateStageByTypeCode(spec.typeCode));
270
+ }
271
+ }
272
+ render() {
273
+ return renderSingle(this);
274
+ }
275
+ toUrn() {
276
+ return new IdfUrnGenerator(this).generate();
277
+ }
278
+ }
279
+ void spec;
280
+ registerType(IdfConcrete);
281
+ return IdfConcrete;
282
+ }
283
+ export const InternationalStandardClass = documentClass({ kind: "international-standard", typeCode: "is" });
284
+ export const ReviewedMethodClass = documentClass({ kind: "reviewed-method", typeCode: "rm" });
285
+ function supplementClass(spec, stage) {
286
+ class IdfSupplement extends IdfIdentifier {
287
+ static polymorphicName = `pubid:idf:${spec.kind}`;
288
+ static urnGenerator = IdfUrnGenerator;
289
+ static get attributes() {
290
+ return extendAttributes(IdfIdentifier, {
291
+ base: { type: IdfIdentifier },
292
+ typedStage: { type: "string" },
293
+ });
294
+ }
295
+ static get mappings() {
296
+ // Supplements carry no publisher of their own (Ruby Supplement
297
+ // Identifier delegates to base; the wire drops it).
298
+ return [
299
+ ...IdfIdentifier.mappings.filter((m) => m.wire !== "publisher"),
300
+ { wire: "base", to: "base" },
301
+ {
302
+ wire: "type",
303
+ to: "typedStage",
304
+ toWire: (model) => {
305
+ const s = model["typedStage"];
306
+ return s instanceof IdfTypedStageComponent ? s.typeWire() : undefined;
307
+ },
308
+ fromWire: () => undefined,
309
+ },
310
+ {
311
+ wire: "stage",
312
+ to: "typedStage",
313
+ toWire: (model) => {
314
+ const s = model["typedStage"];
315
+ return s instanceof IdfTypedStageComponent ? s.stageWire() : undefined;
316
+ },
317
+ fromWire: () => undefined,
318
+ },
319
+ typedStageObjWire,
320
+ ];
321
+ }
322
+ constructor(attrs = {}) {
323
+ super(attrs);
324
+ const self = this;
325
+ if (self["publisherBody"] === undefined)
326
+ self["publisherBody"] = "IDF";
327
+ if (self["typedStage"] === undefined) {
328
+ self["typedStage"] = new IdfTypedStageComponent(stage);
329
+ }
330
+ }
331
+ render() {
332
+ return [
333
+ this.base?.toHuman() ?? "",
334
+ "/",
335
+ this.typedStage.abbreviation(),
336
+ " ",
337
+ this.number ?? "",
338
+ this.date?.present() ? `:${this.date.render()}` : "",
339
+ ].join("");
340
+ }
341
+ toUrn() {
342
+ return new IdfUrnGenerator(this).generate();
343
+ }
344
+ root() {
345
+ return this.base?.root() ?? this;
346
+ }
347
+ }
348
+ registerType(IdfSupplement);
349
+ return IdfSupplement;
350
+ }
351
+ export const AmendmentClass = supplementClass({ kind: "amendment", typeCode: "amd" }, AMD_STAGE);
352
+ export const CorrigendumClass = supplementClass({ kind: "corrigendum", typeCode: "cor" }, COR_STAGE);
353
+ export const IDF_TYPE_CLASSES = {
354
+ is: InternationalStandardClass,
355
+ rm: ReviewedMethodClass,
356
+ amd: AmendmentClass,
357
+ cor: CorrigendumClass,
358
+ };
359
+ export const IDF_ATTRIBUTES = IdfIdentifier.attributes;
@@ -0,0 +1,3 @@
1
+ import { Grammar } from "../../grammar/engine.js";
2
+ export declare function preprocessIec(input: string): string;
3
+ export declare const iecGrammar: Grammar;