@pubid/pubid 0.1.58 → 0.1.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/flavors/ansi/index.d.ts +1 -22
- package/dist/flavors/ansi/index.js +106 -132
- package/dist/flavors/ansi/model.d.ts +60 -0
- package/dist/flavors/ansi/model.js +107 -0
- package/dist/flavors/index.js +3 -0
- package/dist/flavors/register-types.d.ts +2 -1
- package/dist/flavors/register-types.js +2 -1
- package/dist/flavors/wmo/index.d.ts +3 -0
- package/dist/flavors/wmo/index.js +47 -0
- package/dist/flavors/wmo/model.d.ts +82 -0
- package/dist/flavors/wmo/model.js +135 -0
- package/dist/pubid-urn/schemas/ansi.js +3 -0
- package/dist/pubid-urn/schemas/index.js +2 -0
- package/dist/pubid-urn/schemas/wmo.d.ts +8 -0
- package/dist/pubid-urn/schemas/wmo.js +16 -0
- package/dist/urn/parsers.js +76 -0
- package/package.json +1 -1
- package/vendor/parg/ansi.json +1 -1
- package/vendor/parg/itu.json +1 -1
- package/vendor/parg/wmo.json +1 -0
|
@@ -1,24 +1,3 @@
|
|
|
1
|
-
import { Grammar } from "../../grammar/engine.js";
|
|
2
1
|
import type { FlavorImplementation } from "../../conformance/implementation.js";
|
|
3
|
-
|
|
4
|
-
import { BaseUrnGenerator } from "../../model/urn-generator.js";
|
|
5
|
-
import { Publisher, Language } from "../../model/component.js";
|
|
6
|
-
export declare const ansiGrammar: Grammar;
|
|
7
|
-
declare class AnsiUrnGenerator extends BaseUrnGenerator<AnsiIdentifier> {
|
|
8
|
-
generate(): string;
|
|
9
|
-
}
|
|
10
|
-
export declare class AnsiIdentifier extends BaseIdentifier {
|
|
11
|
-
static polymorphicName: string;
|
|
12
|
-
static attributes: import("../../model/attribute.js").AttributeTable;
|
|
13
|
-
static mappings: import("../../model/attribute.js").FieldMapping[];
|
|
14
|
-
static urnGenerator: typeof AnsiUrnGenerator;
|
|
15
|
-
readonly number: string;
|
|
16
|
-
readonly part: string | undefined;
|
|
17
|
-
readonly year: string | undefined;
|
|
18
|
-
readonly publisher: Publisher;
|
|
19
|
-
readonly copublishers: Publisher[];
|
|
20
|
-
readonly languages: Language[];
|
|
21
|
-
render(): string;
|
|
22
|
-
}
|
|
2
|
+
export * from "./model.js";
|
|
23
3
|
export declare function ansiGrammarImplementation(): FlavorImplementation;
|
|
24
|
-
export {};
|
|
@@ -1,147 +1,121 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import { BaseBuilder } from "../../model/builder.js";
|
|
7
|
-
import { Publisher, Language } from "../../model/component.js";
|
|
1
|
+
import { ParseFailed } from "../../grammar/engine.js";
|
|
2
|
+
import { PubidRuntime } from "../../parg/runtime.js";
|
|
3
|
+
import { Publisher, PubidDate, Language } from "../../model/component.js";
|
|
4
|
+
import { AnsiStandard } from "./model.js";
|
|
5
|
+
export * from "./model.js";
|
|
8
6
|
/**
|
|
9
|
-
*
|
|
10
|
-
* (
|
|
11
|
-
*
|
|
12
|
-
*
|
|
7
|
+
* The ansi parse entry — the same baked artifact the Ruby flavor runs
|
|
8
|
+
* (pubid data/parg/ansi.json, sealed at parsanol 1.5.1.0; the gem's
|
|
9
|
+
* artifact runs AHEAD of the pubid-grammar checkout, the known
|
|
10
|
+
* artifact-ahead-of-source drift), loaded through the artifact runtime.
|
|
11
|
+
* The builder mirrors Pubid::Ansi::Builder: the grammar checks the
|
|
12
|
+
* shape, this side splits the number group on dashes and reclassifies a
|
|
13
|
+
* trailing dash-year.
|
|
13
14
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
.repeat(2, Infinity)
|
|
39
|
-
.then(str(",").maybe())
|
|
40
|
-
.repeat(0, Infinity)
|
|
41
|
-
.as("languages"), str(")")));
|
|
42
|
-
rule("identifier_with_copublishers", () => str("ANSI")
|
|
43
|
-
.as("publisher")
|
|
44
|
-
.then(rules["copublishers"], space, rules["std_keyword"])
|
|
45
|
-
.then(rules["number_with_part"])
|
|
46
|
-
.then(rules["date"].maybe())
|
|
47
|
-
.then(rules["language"].maybe()));
|
|
48
|
-
rule("identifier_sole", () => str("ANSI")
|
|
49
|
-
.as("publisher")
|
|
50
|
-
.then(space, rules["std_keyword"], rules["number_with_part"])
|
|
51
|
-
.then(rules["date"].maybe())
|
|
52
|
-
.then(rules["language"].maybe()));
|
|
53
|
-
rule("identifier", () => rules["identifier_with_copublishers"].or(rules["identifier_sole"]));
|
|
54
|
-
rule("root", () => rules["identifier"]);
|
|
55
|
-
return rules;
|
|
56
|
-
}
|
|
57
|
-
export const ansiGrammar = { rules: buildRules(), root: "root" };
|
|
58
|
-
class AnsiUrnGenerator extends BaseUrnGenerator {
|
|
59
|
-
generate() {
|
|
60
|
-
const id = this.identifier;
|
|
61
|
-
const parts = ["urn", "ansi", id.number];
|
|
62
|
-
if (id.part !== undefined)
|
|
63
|
-
parts.push(`-${id.part}`);
|
|
64
|
-
if (id.year !== undefined)
|
|
65
|
-
parts.push(id.year);
|
|
66
|
-
if (id.copublishers.length > 0) {
|
|
67
|
-
parts[1] = ["ansi", ...id.copublishers.map((c) => c.body.toLowerCase())].join("-");
|
|
68
|
-
}
|
|
69
|
-
if (id.languages.length > 0) {
|
|
70
|
-
parts.push(id.languages.map((l) => l.code).join(","));
|
|
71
|
-
}
|
|
72
|
-
return parts.join(":");
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
export class AnsiIdentifier extends BaseIdentifier {
|
|
76
|
-
static polymorphicName = "pubid:ansi:standard";
|
|
77
|
-
static attributes = extendAttributes(BaseIdentifier, {
|
|
78
|
-
number: { type: "string" },
|
|
79
|
-
part: { type: "string" },
|
|
80
|
-
year: { type: "string" },
|
|
81
|
-
copublishers: { type: Publisher, collection: true, initializeEmpty: true },
|
|
82
|
-
languages: { type: Language, collection: true, initializeEmpty: true },
|
|
83
|
-
});
|
|
84
|
-
static mappings = keyValue({ wire: "number", to: "number" }, { wire: "part", to: "part" }, { wire: "year", to: "year" }, { wire: "publisher", to: "publisher" }, { wire: "copublishers", to: "copublishers" }, { wire: "languages", to: "languages" });
|
|
85
|
-
static urnGenerator = AnsiUrnGenerator;
|
|
86
|
-
render() {
|
|
87
|
-
const publisherPortion = this.copublishers.length > 0
|
|
88
|
-
? [this.publisher.body, ...this.copublishers.map((p) => p.body)].join("/")
|
|
89
|
-
: this.publisher.body;
|
|
90
|
-
let numberPortion = this.number;
|
|
91
|
-
if (this.part !== undefined)
|
|
92
|
-
numberPortion += `-${this.part}`;
|
|
93
|
-
if (this.year !== undefined)
|
|
94
|
-
numberPortion += `:${this.year}`;
|
|
95
|
-
let result = `${publisherPortion} ${numberPortion}`;
|
|
96
|
-
if (this.languages.length > 0)
|
|
97
|
-
result += `(${this.languages.map((l) => l.code).join(",")})`;
|
|
98
|
-
return result;
|
|
15
|
+
// --- Builder (lib/pubid/ansi/builder.rb) -------------------------------------
|
|
16
|
+
/**
|
|
17
|
+
* A trailing "-" + 4 digits (19xx/20xx) is the publication year, not a
|
|
18
|
+
* part: "ANSI X9.62-2005" (relaton#45). Only when no ":YYYY" follows,
|
|
19
|
+
* so the part of "ANSI X9.8-1:2007" stays a part.
|
|
20
|
+
*/
|
|
21
|
+
const DASH_YEAR = /^(?:19|20)\d{2}$/;
|
|
22
|
+
/**
|
|
23
|
+
* Ruby Builder split_number_with_part: a third dash group is always the
|
|
24
|
+
* year ("ANSI/ISA-61511-1-2018") — the grammar admits only a 19xx/20xx
|
|
25
|
+
* group there. At most one part group reaches the tree, so three
|
|
26
|
+
* segments is the maximum.
|
|
27
|
+
*/
|
|
28
|
+
function splitNumberWithPart(value) {
|
|
29
|
+
const segments = value.split("-");
|
|
30
|
+
const [number, part, dashYear] = segments;
|
|
31
|
+
const attrs = {};
|
|
32
|
+
if (number !== undefined)
|
|
33
|
+
attrs["number"] = number;
|
|
34
|
+
if (part !== undefined)
|
|
35
|
+
attrs["part"] = part;
|
|
36
|
+
if (dashYear !== undefined) {
|
|
37
|
+
attrs["date"] = new PubidDate({ year: dashYear });
|
|
38
|
+
attrs["date_separator"] = "-";
|
|
99
39
|
}
|
|
40
|
+
return attrs;
|
|
100
41
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
42
|
+
/**
|
|
43
|
+
* read_dash_year: a trailing "-" + 4 digits is the publication year,
|
|
44
|
+
* not a part — unless a date or a revision already claimed the slot (a
|
|
45
|
+
* revision follows the part, so "568-2009-D" keeps 2009 as a part:
|
|
46
|
+
* read as a year, it would render after the revision).
|
|
47
|
+
*/
|
|
48
|
+
function readDashYear(identifier) {
|
|
49
|
+
const record = identifier;
|
|
50
|
+
if (record["date"] !== undefined || record["revision"] !== undefined)
|
|
51
|
+
return;
|
|
52
|
+
const part = record["part"];
|
|
53
|
+
if (typeof part !== "string" || !DASH_YEAR.test(part))
|
|
54
|
+
return;
|
|
55
|
+
record["date"] = new PubidDate({ year: part });
|
|
56
|
+
record["date_separator"] = "-";
|
|
57
|
+
record["part"] = undefined;
|
|
110
58
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
59
|
+
function buildAnsi(data) {
|
|
60
|
+
const attrs = {};
|
|
61
|
+
for (const [key, value] of Object.entries(data)) {
|
|
62
|
+
if (value === undefined || value === null)
|
|
63
|
+
continue;
|
|
64
|
+
switch (key) {
|
|
65
|
+
case "publisher":
|
|
66
|
+
attrs["publisher"] = new Publisher({ body: String(value) });
|
|
67
|
+
break;
|
|
68
|
+
case "std_keyword":
|
|
69
|
+
// Consumed and dropped: no identifier attribute reads it.
|
|
70
|
+
break;
|
|
71
|
+
case "copublishers": {
|
|
72
|
+
const list = Array.isArray(value) ? value : [value];
|
|
73
|
+
if (list.length === 0)
|
|
74
|
+
break;
|
|
75
|
+
attrs["copublishers"] = list.map((entry) => {
|
|
76
|
+
const body = typeof entry === "object" && entry !== null && "copublisher" in entry
|
|
77
|
+
? String(entry["copublisher"])
|
|
78
|
+
: String(entry);
|
|
79
|
+
return new Publisher({ body });
|
|
80
|
+
});
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
case "number_with_part":
|
|
84
|
+
Object.assign(attrs, splitNumberWithPart(String(value)));
|
|
85
|
+
break;
|
|
86
|
+
case "number_separator":
|
|
87
|
+
case "revision":
|
|
88
|
+
attrs[key] = String(value);
|
|
89
|
+
break;
|
|
90
|
+
case "date":
|
|
91
|
+
attrs["date"] = new PubidDate({ year: String(value) });
|
|
92
|
+
break;
|
|
93
|
+
case "languages":
|
|
94
|
+
attrs["languages"] = String(value)
|
|
95
|
+
.split(",")
|
|
96
|
+
.map((lang) => new Language({ code: lang.trim() }));
|
|
97
|
+
break;
|
|
98
|
+
default:
|
|
99
|
+
// Unknown captures raise in the Ruby builder; the grammar binds
|
|
100
|
+
// exactly the keys above, so this is unreachable today.
|
|
101
|
+
throw new Error(`Unknown parameter type: ${key}`);
|
|
132
102
|
}
|
|
133
|
-
return value;
|
|
134
103
|
}
|
|
104
|
+
const identifier = new AnsiStandard(attrs);
|
|
105
|
+
readDashYear(identifier);
|
|
106
|
+
return identifier;
|
|
135
107
|
}
|
|
108
|
+
// --- Implementation ----------------------------------------------------------
|
|
109
|
+
let cachedRuntime;
|
|
136
110
|
export function ansiGrammarImplementation() {
|
|
137
|
-
const builder = new AnsiBuilder();
|
|
138
111
|
return {
|
|
139
112
|
parse(input) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
113
|
+
cachedRuntime ??= PubidRuntime.load("ansi");
|
|
114
|
+
const bound = cachedRuntime.parseAndBind(input);
|
|
115
|
+
if (bound === null || typeof bound !== "object" || Array.isArray(bound)) {
|
|
116
|
+
throw new ParseFailed("ansi: the artifact rejected the input", 0);
|
|
143
117
|
}
|
|
144
|
-
return
|
|
118
|
+
return buildAnsi(bound);
|
|
145
119
|
},
|
|
146
120
|
};
|
|
147
121
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { BaseIdentifier } from "../../model/identifier.js";
|
|
2
|
+
import { PubidDate } from "../../model/component.js";
|
|
3
|
+
import { BaseUrnGenerator } from "../../model/urn-generator.js";
|
|
4
|
+
/**
|
|
5
|
+
* The ansi identifier model — lib/pubid/ansi/identifier.rb plus its
|
|
6
|
+
* Identifiers::* leaves. Registration lives HERE (parg-free) so the
|
|
7
|
+
* worker manifest (src/flavors/register-types.ts) can import it without
|
|
8
|
+
* reaching the artifact runtime; the parse entry (./index.js) is the
|
|
9
|
+
* parg-backed half.
|
|
10
|
+
*
|
|
11
|
+
* The relaton#45 round: any uppercase developer acronym co-publishes,
|
|
12
|
+
* the publisher group may join the number with a dash
|
|
13
|
+
* (number_separator), the year may join the number with a dash
|
|
14
|
+
* (date_separator — the "ANSI X9.62-2005" spelling), and a trailing
|
|
15
|
+
* revision letter ("ANSI/TIA-568.2-D") is identity. Both separators are
|
|
16
|
+
* spelling-only facets: they serialize but `==` skips them
|
|
17
|
+
* (equality_ignored).
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* The URN generator (lib/pubid/ansi/urn_generator.rb): the namespace
|
|
21
|
+
* slot carries the publisher and copublishers joined with dashes
|
|
22
|
+
* ("ansi-tia"), the revision is identity so it reaches the URN too
|
|
23
|
+
* ("rev-D").
|
|
24
|
+
*/
|
|
25
|
+
declare class AnsiUrnGenerator extends BaseUrnGenerator<AnsiIdentifier> {
|
|
26
|
+
generate(): string;
|
|
27
|
+
}
|
|
28
|
+
/** The base ANSI identifier (Pubid::Ansi::Identifier): render, URN and
|
|
29
|
+
* hash behavior shared by every leaf. */
|
|
30
|
+
export declare class AnsiIdentifier extends BaseIdentifier {
|
|
31
|
+
static polymorphicName: string;
|
|
32
|
+
static attributes: import("../../model/attribute.js").AttributeTable;
|
|
33
|
+
static urnGenerator: typeof AnsiUrnGenerator;
|
|
34
|
+
readonly number: string | undefined;
|
|
35
|
+
readonly part: string | undefined;
|
|
36
|
+
readonly date: PubidDate | undefined;
|
|
37
|
+
readonly date_separator: string | undefined;
|
|
38
|
+
readonly number_separator: string | undefined;
|
|
39
|
+
readonly revision: string | undefined;
|
|
40
|
+
readonly publisher: {
|
|
41
|
+
body: string;
|
|
42
|
+
} | undefined;
|
|
43
|
+
readonly copublishers: {
|
|
44
|
+
body: string;
|
|
45
|
+
}[] | undefined;
|
|
46
|
+
readonly languages: {
|
|
47
|
+
code: string;
|
|
48
|
+
}[] | undefined;
|
|
49
|
+
render(): string;
|
|
50
|
+
private datePresent;
|
|
51
|
+
}
|
|
52
|
+
/** Identifiers::Standard — the default leaf every parse builds. */
|
|
53
|
+
export declare class AnsiStandard extends AnsiIdentifier {
|
|
54
|
+
static polymorphicName: string;
|
|
55
|
+
}
|
|
56
|
+
/** Identifiers::AmericanNationalStandard — the explicit ANS type. */
|
|
57
|
+
export declare class AnsiAmericanNationalStandard extends AnsiIdentifier {
|
|
58
|
+
static polymorphicName: string;
|
|
59
|
+
}
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { BaseIdentifier, registerType } from "../../model/identifier.js";
|
|
2
|
+
import { extendAttributes } from "../../model/attribute.js";
|
|
3
|
+
import { BaseUrnGenerator } from "../../model/urn-generator.js";
|
|
4
|
+
/**
|
|
5
|
+
* The ansi identifier model — lib/pubid/ansi/identifier.rb plus its
|
|
6
|
+
* Identifiers::* leaves. Registration lives HERE (parg-free) so the
|
|
7
|
+
* worker manifest (src/flavors/register-types.ts) can import it without
|
|
8
|
+
* reaching the artifact runtime; the parse entry (./index.js) is the
|
|
9
|
+
* parg-backed half.
|
|
10
|
+
*
|
|
11
|
+
* The relaton#45 round: any uppercase developer acronym co-publishes,
|
|
12
|
+
* the publisher group may join the number with a dash
|
|
13
|
+
* (number_separator), the year may join the number with a dash
|
|
14
|
+
* (date_separator — the "ANSI X9.62-2005" spelling), and a trailing
|
|
15
|
+
* revision letter ("ANSI/TIA-568.2-D") is identity. Both separators are
|
|
16
|
+
* spelling-only facets: they serialize but `==` skips them
|
|
17
|
+
* (equality_ignored).
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* The URN generator (lib/pubid/ansi/urn_generator.rb): the namespace
|
|
21
|
+
* slot carries the publisher and copublishers joined with dashes
|
|
22
|
+
* ("ansi-tia"), the revision is identity so it reaches the URN too
|
|
23
|
+
* ("rev-D").
|
|
24
|
+
*/
|
|
25
|
+
class AnsiUrnGenerator extends BaseUrnGenerator {
|
|
26
|
+
generate() {
|
|
27
|
+
const id = this.identifier;
|
|
28
|
+
const parts = ["urn", "ansi"];
|
|
29
|
+
const push = (v) => {
|
|
30
|
+
if (v !== undefined && v !== null && v !== "")
|
|
31
|
+
parts.push(v);
|
|
32
|
+
};
|
|
33
|
+
push(this.urnNumber());
|
|
34
|
+
push(this.urnPart());
|
|
35
|
+
push(this.urnSubpart());
|
|
36
|
+
push(this.urnYear());
|
|
37
|
+
// "568.2-C" and "568.2-D" are two documents: keep them apart.
|
|
38
|
+
push(id.revision !== undefined ? `rev-${id.revision}` : undefined);
|
|
39
|
+
push(this.urnEdition());
|
|
40
|
+
if (id.publisher !== undefined) {
|
|
41
|
+
parts[1] = id.publisher.body.toLowerCase();
|
|
42
|
+
}
|
|
43
|
+
if (id.copublishers !== undefined && id.copublishers.length > 0) {
|
|
44
|
+
const copubs = id.copublishers.map((cp) => cp.body.toLowerCase());
|
|
45
|
+
parts[1] = `${parts[1]}-${copubs.join("-")}`;
|
|
46
|
+
}
|
|
47
|
+
if (id.languages !== undefined && id.languages.length > 0) {
|
|
48
|
+
parts.push(id.languages.map((l) => l.code).join(","));
|
|
49
|
+
}
|
|
50
|
+
return parts.join(":");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** The base ANSI identifier (Pubid::Ansi::Identifier): render, URN and
|
|
54
|
+
* hash behavior shared by every leaf. */
|
|
55
|
+
export class AnsiIdentifier extends BaseIdentifier {
|
|
56
|
+
static polymorphicName = "pubid:ansi:identifier";
|
|
57
|
+
static attributes = extendAttributes(BaseIdentifier, {
|
|
58
|
+
date_separator: { type: "string", equalityIgnored: true },
|
|
59
|
+
number_separator: { type: "string", equalityIgnored: true },
|
|
60
|
+
revision: { type: "string" },
|
|
61
|
+
});
|
|
62
|
+
// The gem declares no key_value block: every attribute serializes
|
|
63
|
+
// under its own name (the date component's degenerate year flattens).
|
|
64
|
+
static urnGenerator = AnsiUrnGenerator;
|
|
65
|
+
render() {
|
|
66
|
+
// The renderer (lib/pubid/ansi/renderer.rb): "ANSI/ISA-5.1-2009"
|
|
67
|
+
// keeps its dash; the space is the default publisher join.
|
|
68
|
+
const publisherPortion = this.copublishers !== undefined && this.copublishers.length > 0
|
|
69
|
+
? [this.publisher, ...this.copublishers]
|
|
70
|
+
.map((p) => (p === undefined ? "" : p.body))
|
|
71
|
+
.join("/")
|
|
72
|
+
: this.publisher?.body ?? "";
|
|
73
|
+
const numberPortion = (this.number ?? "") +
|
|
74
|
+
(this.part !== undefined ? `-${this.part}` : "") +
|
|
75
|
+
(this.revision !== undefined ? `-${this.revision}` : "") +
|
|
76
|
+
// "ANSI X9.62-2005" keeps its dash; the colon is the default.
|
|
77
|
+
(this.datePresent() ? `${this.date_separator ?? ":"}${this.date?.year}` : "");
|
|
78
|
+
let result = this.number_separator !== undefined
|
|
79
|
+
? `${publisherPortion}${this.number_separator}${numberPortion}`
|
|
80
|
+
: `${publisherPortion} ${numberPortion}`;
|
|
81
|
+
if (this.languages !== undefined && this.languages.length > 0) {
|
|
82
|
+
result += `(${this.languages.map((l) => l.code).join(",")})`;
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
datePresent() {
|
|
87
|
+
const date = this.date;
|
|
88
|
+
if (date === undefined)
|
|
89
|
+
return false;
|
|
90
|
+
if (date.undated)
|
|
91
|
+
return true;
|
|
92
|
+
return date.year !== undefined && date.year !== "";
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/** Identifiers::Standard — the default leaf every parse builds. */
|
|
96
|
+
export class AnsiStandard extends AnsiIdentifier {
|
|
97
|
+
static polymorphicName = "pubid:ansi:standard";
|
|
98
|
+
}
|
|
99
|
+
/** Identifiers::AmericanNationalStandard — the explicit ANS type. */
|
|
100
|
+
export class AnsiAmericanNationalStandard extends AnsiIdentifier {
|
|
101
|
+
static polymorphicName = "pubid:ansi:american-national-standard";
|
|
102
|
+
}
|
|
103
|
+
// The ANSI_TYPE_MAP role: the base plus the two concrete leaves (the
|
|
104
|
+
// schema's pubid:ansi:{identifier,standard,american-national-standard}).
|
|
105
|
+
registerType(AnsiIdentifier);
|
|
106
|
+
registerType(AnsiStandard);
|
|
107
|
+
registerType(AnsiAmericanNationalStandard);
|
package/dist/flavors/index.js
CHANGED
|
@@ -47,6 +47,7 @@ import { ietfGrammarImplementation } from "./ietf/index.js";
|
|
|
47
47
|
import { ialaGrammarImplementation } from "./iala/index.js";
|
|
48
48
|
import { euGrammarImplementation } from "./eu/index.js";
|
|
49
49
|
import { arxivGrammarImplementation } from "./arxiv/index.js";
|
|
50
|
+
import { wmoGrammarImplementation } from "./wmo/index.js";
|
|
50
51
|
/**
|
|
51
52
|
* The grammar-wave registry: flavors whose Ruby grammar has been ported
|
|
52
53
|
* to a TypeScript implementation. A flavor listed here parses
|
|
@@ -178,6 +179,8 @@ function grammarImplementationSwitch(flavor) {
|
|
|
178
179
|
return euGrammarImplementation();
|
|
179
180
|
case "arxiv":
|
|
180
181
|
return arxivGrammarImplementation();
|
|
182
|
+
case "wmo":
|
|
183
|
+
return wmoGrammarImplementation();
|
|
181
184
|
default:
|
|
182
185
|
return undefined;
|
|
183
186
|
}
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
* codec with no node-only module in the graph.
|
|
35
35
|
*/
|
|
36
36
|
import "./amca/model.js";
|
|
37
|
+
import "./ansi/model.js";
|
|
37
38
|
import "./api/model.js";
|
|
38
39
|
import "./arxiv/model.js";
|
|
39
40
|
import "./ashrae/model.js";
|
|
@@ -53,7 +54,7 @@ import "./iso/model.js";
|
|
|
53
54
|
import "./itu/model.js";
|
|
54
55
|
import "./nist/model.js";
|
|
55
56
|
import "./oiml/model.js";
|
|
56
|
-
import "./
|
|
57
|
+
import "./wmo/model.js";
|
|
57
58
|
import "./bipm/index.js";
|
|
58
59
|
import "./calconnect/index.js";
|
|
59
60
|
import "./ccsds/model.js";
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
*/
|
|
36
36
|
// Model-registrant flavors: registration lives in <flavor>/model.js.
|
|
37
37
|
import "./amca/model.js";
|
|
38
|
+
import "./ansi/model.js";
|
|
38
39
|
import "./api/model.js";
|
|
39
40
|
import "./arxiv/model.js";
|
|
40
41
|
import "./ashrae/model.js";
|
|
@@ -54,8 +55,8 @@ import "./iso/model.js";
|
|
|
54
55
|
import "./itu/model.js";
|
|
55
56
|
import "./nist/model.js";
|
|
56
57
|
import "./oiml/model.js";
|
|
58
|
+
import "./wmo/model.js";
|
|
57
59
|
// Index-registrant flavors: registration lives in <flavor>/index.js.
|
|
58
|
-
import "./ansi/index.js";
|
|
59
60
|
import "./bipm/index.js";
|
|
60
61
|
import "./calconnect/index.js";
|
|
61
62
|
// ccsds (pubid-ts#178): the registration classes live on ccsds/model.js
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ParseFailed } from "../../grammar/engine.js";
|
|
2
|
+
import { PubidRuntime } from "../../parg/runtime.js";
|
|
3
|
+
import { WmoAnnex, WmoPublication, WmoStandard } from "./model.js";
|
|
4
|
+
export * from "./model.js";
|
|
5
|
+
/**
|
|
6
|
+
* The wmo parse entry — the same baked artifact the Ruby flavor runs
|
|
7
|
+
* (pubid-grammar grammars/wmo.parg -> artifacts/wmo.json, sealed at
|
|
8
|
+
* parsanol 1.5.1.0), loaded through the artifact runtime. The builder
|
|
9
|
+
* mirrors Pubid::Wmo::Builder: the grammar carries exactly one
|
|
10
|
+
* doc_number and edition_value per alternative path, so one flat bound
|
|
11
|
+
* map serves all three types and the dispatch keys off `annex_marker`
|
|
12
|
+
* and `wmomarker`.
|
|
13
|
+
*/
|
|
14
|
+
function buildWmo(data) {
|
|
15
|
+
const number = data["doc_number"] === undefined ? undefined : String(data["doc_number"]);
|
|
16
|
+
const edition = data["edition_value"] === undefined ? undefined : String(data["edition_value"]);
|
|
17
|
+
const annexMarker = data["annex_marker"] === undefined ? undefined : String(data["annex_marker"]);
|
|
18
|
+
const annexLetter = data["annex_letter"] === undefined ? undefined : String(data["annex_letter"]);
|
|
19
|
+
if (annexMarker !== undefined) {
|
|
20
|
+
const attrs = {
|
|
21
|
+
base: new WmoStandard({ number }),
|
|
22
|
+
annex_form: annexMarker,
|
|
23
|
+
};
|
|
24
|
+
if (annexLetter !== undefined)
|
|
25
|
+
attrs["letter"] = annexLetter;
|
|
26
|
+
if (edition !== undefined)
|
|
27
|
+
attrs["edition"] = edition;
|
|
28
|
+
return new WmoAnnex(attrs);
|
|
29
|
+
}
|
|
30
|
+
if (data["wmomarker"] !== undefined) {
|
|
31
|
+
return new WmoPublication(edition !== undefined ? { number, edition } : { number });
|
|
32
|
+
}
|
|
33
|
+
return new WmoStandard(edition !== undefined ? { number, edition } : { number });
|
|
34
|
+
}
|
|
35
|
+
let cachedRuntime;
|
|
36
|
+
export function wmoGrammarImplementation() {
|
|
37
|
+
return {
|
|
38
|
+
parse(input) {
|
|
39
|
+
cachedRuntime ??= PubidRuntime.load("wmo");
|
|
40
|
+
const bound = cachedRuntime.parseAndBind(input);
|
|
41
|
+
if (bound === null || typeof bound !== "object" || Array.isArray(bound)) {
|
|
42
|
+
throw new ParseFailed("wmo: the artifact rejected the input", 0);
|
|
43
|
+
}
|
|
44
|
+
return buildWmo(bound);
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { BaseIdentifier } from "../../model/identifier.js";
|
|
2
|
+
/**
|
|
3
|
+
* The wmo identifier model — lib/pubid/wmo/identifier.rb plus its
|
|
4
|
+
* Identifiers::* leaves. Registration lives HERE (parg-free) so the
|
|
5
|
+
* worker manifest (src/flavors/register-types.ts) can import it without
|
|
6
|
+
* reaching the artifact runtime; the parse entry (./index.js) is the
|
|
7
|
+
* parg-backed half.
|
|
8
|
+
*
|
|
9
|
+
* Two series share the flavor (pubid#763):
|
|
10
|
+
*
|
|
11
|
+
* WMO-No. <number>[, <year> edition] the WMO-No. publication
|
|
12
|
+
* series; editions are calendar
|
|
13
|
+
* years
|
|
14
|
+
* S-<number>[ <x.y.z>] the WMO-published S-100 product
|
|
15
|
+
* specifications; editions are
|
|
16
|
+
* dotted x.y.z (the IHO lexical
|
|
17
|
+
* form, WMO as the assigning
|
|
18
|
+
* authority - the S-201-of-IALA
|
|
19
|
+
* ruling)
|
|
20
|
+
* S-<number> [Annex|ANNEX] [<letter>] [<x.y.z>] annex wrapper
|
|
21
|
+
*
|
|
22
|
+
* The edition is ONE string attribute carrying a type-driven face:
|
|
23
|
+
* "2025" on a Publication, "1.2.1" on a Standard or Annex. The
|
|
24
|
+
* renderer and the MRN URN generator key the face off the type.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* The MRN URN generator (lib/pubid/wmo/urn_generator.rb) — the WMO
|
|
28
|
+
* assigning authority of the IANA-registered mrn namespace, following
|
|
29
|
+
* the IALA pattern (pubid#763 proposed form):
|
|
30
|
+
*
|
|
31
|
+
* urn:mrn:wmo:pub:wmo-<number>[:ed<year>] the WMO-No. series
|
|
32
|
+
* urn:mrn:wmo:pub:s-<number>[:ed<x.y.z>] the S-100 specs
|
|
33
|
+
* urn:mrn:wmo:pub:s-<number>:annex[-<letter>][:ed<x.y.z>]
|
|
34
|
+
*/
|
|
35
|
+
declare class WmoUrnGenerator {
|
|
36
|
+
private readonly identifier;
|
|
37
|
+
constructor(identifier: WmoIdentifier);
|
|
38
|
+
generate(): string;
|
|
39
|
+
}
|
|
40
|
+
/** The base WMO identifier (Pubid::Wmo::Identifier). */
|
|
41
|
+
export declare class WmoIdentifier extends BaseIdentifier {
|
|
42
|
+
static polymorphicName: string;
|
|
43
|
+
static attributes: import("../../model/attribute.js").AttributeTable;
|
|
44
|
+
static mappings: import("../../model/attribute.js").FieldMapping[];
|
|
45
|
+
static urnGenerator: typeof WmoUrnGenerator;
|
|
46
|
+
readonly number: string | undefined;
|
|
47
|
+
readonly edition: string | undefined;
|
|
48
|
+
readonly publisher: string | undefined;
|
|
49
|
+
/** The edition is a plain string (the string-edition flavors precede
|
|
50
|
+
* this); the base mr_edition reads edition.number of a
|
|
51
|
+
* Components::Edition, which would crash on the string. */
|
|
52
|
+
mrEdition(): string | undefined;
|
|
53
|
+
/** "WMO-No." and the S-number are designations, not publisher tokens:
|
|
54
|
+
* the canonical faces carry no publisher prefix. */
|
|
55
|
+
render(): string;
|
|
56
|
+
}
|
|
57
|
+
/** Identifiers::Publication — the WMO-No. series. */
|
|
58
|
+
export declare class WmoPublication extends WmoIdentifier {
|
|
59
|
+
static polymorphicName: string;
|
|
60
|
+
render(): string;
|
|
61
|
+
}
|
|
62
|
+
/** Identifiers::Standard — the WMO-published S-100 specifications. */
|
|
63
|
+
export declare class WmoStandard extends WmoIdentifier {
|
|
64
|
+
static polymorphicName: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Identifiers::Annex — an annex to a WMO-published S-100 product
|
|
68
|
+
* specification: "S-411 Annex A" (the DCEG docidentifier). The marker
|
|
69
|
+
* case is preserved (Annex vs ANNEX) for round-trip fidelity; the
|
|
70
|
+
* optional edition applies to the annex itself, not the base.
|
|
71
|
+
*/
|
|
72
|
+
export declare class WmoAnnex extends WmoIdentifier {
|
|
73
|
+
static polymorphicName: string;
|
|
74
|
+
static attributes: import("../../model/attribute.js").AttributeTable;
|
|
75
|
+
static mappings: import("../../model/attribute.js").FieldMapping[];
|
|
76
|
+
readonly base: WmoIdentifier | undefined;
|
|
77
|
+
readonly annex_form: string | undefined;
|
|
78
|
+
readonly letter: string | undefined;
|
|
79
|
+
readonly edition: string | undefined;
|
|
80
|
+
render(): string;
|
|
81
|
+
}
|
|
82
|
+
export {};
|