@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,71 @@
1
+ import { parseGrammar } from "../../grammar/engine.js";
2
+ import { apiGrammar, preprocessApi } from "./grammar.js";
3
+ import { TypelessStandardClass, TYPE_CLASS_MAP } from "./model.js";
4
+ /**
5
+ * Port of lib/pubid/api/builder.rb — type dispatch plus the shared
6
+ * base-builder assignment loop (chapter routes into `number`; :type is
7
+ * dispatch-only and dropped).
8
+ */
9
+ const isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
10
+ const strv = (v) => {
11
+ if (v === undefined || v === null)
12
+ return undefined;
13
+ if (Array.isArray(v)) {
14
+ if (v.length === 0)
15
+ return undefined;
16
+ const joined = v.flat(10).map(String).join("");
17
+ return joined.length > 0 ? joined : undefined;
18
+ }
19
+ const s = String(v).trim();
20
+ return s.length > 0 ? s : undefined;
21
+ };
22
+ function flatten(data) {
23
+ return Array.isArray(data) ? Object.assign({}, ...data) : data;
24
+ }
25
+ function castValue(key, value) {
26
+ if (key === "reaffirmation") {
27
+ return isObj(value) ? strv(value["year"]) : strv(value);
28
+ }
29
+ return strv(value);
30
+ }
31
+ function assignAttributes(identifier, data) {
32
+ const self = identifier;
33
+ const known = new Set([
34
+ "publisher", "number", "part", "subpart", "year", "reaffirmation",
35
+ "section", "subsection",
36
+ ]);
37
+ for (const [key, value] of Object.entries(data)) {
38
+ if (key === "type")
39
+ continue;
40
+ if (key === "chapter") {
41
+ const chapter = strv(value);
42
+ if (chapter !== undefined)
43
+ self["number"] = chapter;
44
+ continue;
45
+ }
46
+ // :part_number is a parse-tree key the gem's base builder silently
47
+ // drops (not an attribute) — matched 1:1.
48
+ if (!known.has(key))
49
+ continue;
50
+ const realized = castValue(key, value);
51
+ if (realized !== undefined)
52
+ self[key] = realized;
53
+ }
54
+ }
55
+ export function buildApiIdentifier(tree) {
56
+ const data = flatten(tree);
57
+ const typeStr = strv(data["type"]);
58
+ const klass = (typeStr !== undefined ? TYPE_CLASS_MAP[typeStr] : undefined)
59
+ ?? TypelessStandardClass;
60
+ const identifier = new klass();
61
+ assignAttributes(identifier, data);
62
+ return identifier;
63
+ }
64
+ export function apiGrammarImplementation() {
65
+ return {
66
+ parse(input) {
67
+ const tree = parseGrammar(apiGrammar, preprocessApi(input));
68
+ return buildApiIdentifier(tree);
69
+ },
70
+ };
71
+ }
@@ -0,0 +1,27 @@
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
+ export declare abstract class ApiIdentifier extends BaseIdentifier {
5
+ static attributes: AttributeTable;
6
+ static mappings: FieldMapping[];
7
+ readonly publisher: string | undefined;
8
+ readonly number: string | undefined;
9
+ readonly part: string | undefined;
10
+ readonly subpart: string | undefined;
11
+ readonly year: string | undefined;
12
+ readonly reaffirmation: string | undefined;
13
+ constructor(attrs?: Record<string, unknown>);
14
+ /** The printed type token (plain method on the Ruby leaf, never a wire attribute). */
15
+ typeString(): string | undefined;
16
+ render(): string;
17
+ }
18
+ export declare const BulletinClass: IdentifierStatic;
19
+ export declare const RecommendedPracticeClass: IdentifierStatic;
20
+ export declare const SpecificationClass: IdentifierStatic;
21
+ export declare const StandardClass: IdentifierStatic;
22
+ export declare const TechnicalReportClass: IdentifierStatic;
23
+ export declare const ContinuousOperationsStandardClass: IdentifierStatic;
24
+ export declare const PublicationClass: IdentifierStatic;
25
+ export declare const TypelessStandardClass: IdentifierStatic;
26
+ export declare const MpmsClass: IdentifierStatic;
27
+ export declare const TYPE_CLASS_MAP: Record<string, IdentifierStatic>;
@@ -0,0 +1,114 @@
1
+ import { BaseIdentifier, registerType } from "../../model/identifier.js";
2
+ import { keyValue, extendAttributes } from "../../model/attribute.js";
3
+ import { BaseUrnGenerator } from "../../model/urn-generator.js";
4
+ /**
5
+ * Port of lib/pubid/api: the shared base, the eight typed leaf
6
+ * classes plus TypelessStandard, the renderer and the URN generator.
7
+ */
8
+ const BASE_ATTRS = {
9
+ publisher: { type: "string", default: "API" },
10
+ number: { type: "string" },
11
+ part: { type: "string" },
12
+ subpart: { type: "string" },
13
+ year: { type: "string" },
14
+ reaffirmation: { type: "string" },
15
+ };
16
+ const BASE_MAPPINGS = keyValue({ wire: "publisher", to: "publisher" }, { wire: "number", to: "number" }, { wire: "part", to: "part" }, { wire: "subpart", to: "subpart" }, { wire: "year", to: "year" }, { wire: "reaffirmation", to: "reaffirmation" });
17
+ export class ApiIdentifier extends BaseIdentifier {
18
+ static attributes = extendAttributes(BaseIdentifier, BASE_ATTRS);
19
+ static mappings = BASE_MAPPINGS;
20
+ constructor(attrs = {}) {
21
+ super(attrs);
22
+ const self = this;
23
+ if (self["publisher"] === undefined)
24
+ self["publisher"] = "API";
25
+ }
26
+ /** The printed type token (plain method on the Ruby leaf, never a wire attribute). */
27
+ typeString() {
28
+ return undefined;
29
+ }
30
+ render() {
31
+ const parts = ["API"];
32
+ if (this.typeString() !== undefined)
33
+ parts.push(this.typeString());
34
+ const code = codePortion(this);
35
+ if (code !== undefined)
36
+ parts.push(code);
37
+ let result = parts.join(" ");
38
+ if (this.year !== undefined)
39
+ result += `-${this.year}`;
40
+ if (this.reaffirmation !== undefined)
41
+ result += ` (R${this.reaffirmation})`;
42
+ return result;
43
+ }
44
+ }
45
+ function codePortion(id) {
46
+ if (id.number === undefined)
47
+ return undefined;
48
+ return id.part !== undefined ? `${id.number}-${id.part}` : id.number;
49
+ }
50
+ class ApiUrnGenerator extends BaseUrnGenerator {
51
+ generate() {
52
+ const id = this.identifier;
53
+ const parts = ["urn", "api", "std"];
54
+ if (id.number !== undefined)
55
+ parts.push(id.number);
56
+ if (id.part !== undefined)
57
+ parts.push(`-${id.part}`);
58
+ if (id.year !== undefined)
59
+ parts.push(id.year);
60
+ parts[1] = id.publisher !== undefined ? id.publisher.toLowerCase() : "api";
61
+ return parts.join(":");
62
+ }
63
+ }
64
+ function apiClass(spec, extraAttrs = {}, render) {
65
+ class ApiConcrete extends ApiIdentifier {
66
+ static polymorphicName = `pubid:api:${spec.kind}`;
67
+ static urnGenerator = ApiUrnGenerator;
68
+ static attributes = extendAttributes(ApiIdentifier, extraAttrs);
69
+ static mappings = [
70
+ ...BASE_MAPPINGS,
71
+ ...Object.keys(extraAttrs).map((k) => ({ wire: k, to: k })),
72
+ ];
73
+ typeString() {
74
+ return spec.typeString;
75
+ }
76
+ render() {
77
+ return render !== undefined ? render(this) : super.render();
78
+ }
79
+ }
80
+ registerType(ApiConcrete);
81
+ return ApiConcrete;
82
+ }
83
+ export const BulletinClass = apiClass({ kind: "bulletin", typeString: "BULL" });
84
+ export const RecommendedPracticeClass = apiClass({ kind: "recommended-practice", typeString: "RP" });
85
+ export const SpecificationClass = apiClass({ kind: "specification", typeString: "SPEC" });
86
+ export const StandardClass = apiClass({ kind: "standard", typeString: "STD" });
87
+ export const TechnicalReportClass = apiClass({ kind: "technical-report", typeString: "TR" });
88
+ export const ContinuousOperationsStandardClass = apiClass({ kind: "continuous-operations-standard", typeString: "COS" });
89
+ export const PublicationClass = apiClass({ kind: "publication", typeString: "PUBL" });
90
+ export const TypelessStandardClass = apiClass({ kind: "typeless-standard" });
91
+ export const MpmsClass = apiClass({ kind: "mpms", typeString: "MPMS" }, { section: { type: "string" }, subsection: { type: "string" } }, (id) => {
92
+ const self = id;
93
+ const parts = ["API", "MPMS"];
94
+ if (id.number !== undefined)
95
+ parts.push(`CH ${id.number}`);
96
+ if (self.section !== undefined) {
97
+ parts.push(`.${self.section}`);
98
+ if (self.subsection !== undefined)
99
+ parts.push(`.${self.subsection}`);
100
+ }
101
+ if (id.year !== undefined)
102
+ parts.push(`-${id.year}`);
103
+ return parts.join(" ").replaceAll(" .", ".");
104
+ });
105
+ export const TYPE_CLASS_MAP = {
106
+ BULL: BulletinClass,
107
+ MPMS: MpmsClass,
108
+ RP: RecommendedPracticeClass,
109
+ SPEC: SpecificationClass,
110
+ STD: StandardClass,
111
+ TR: TechnicalReportClass,
112
+ COS: ContinuousOperationsStandardClass,
113
+ PUBL: PublicationClass,
114
+ };
@@ -0,0 +1,2 @@
1
+ import { Grammar } from "../../grammar/engine.js";
2
+ export declare const ashraeGrammar: Grammar;